Skip to content

Commit

Permalink
fixing command instrumentation for strings that have test infras but …
Browse files Browse the repository at this point in the history
…arent a call to them; and a few minor tweaks
  • Loading branch information
emarteca committed Jun 27, 2023
1 parent 3cdf18b commit 7d2f03b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions configs/verbose.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"test": {
"test_command_repeats": 1,
"test_verbose_all_output": { "do_verbose_tracking": true }
}
}
2 changes: 1 addition & 1 deletion src/TestInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TestInfo:
"gulp lint": "gulp lint -- linter"
}

TRACKED_RUNNERS = [ "node", "babel-node", "grunt" ]
TRACKED_RUNNERS = [ "node", "babel-node", "grunt", "lerna" ]

def __init__(self, success, error_stream, output_stream, manager, VERBOSE_MODE):
self.success = success
Expand Down
16 changes: 12 additions & 4 deletions src/output_parsing/test_output_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ def parse_mocha_json_to_csv(output_file, new_output_file=None):
# convert an xml file to json
# used to convert the xunit reporter output from mocha into json
# code from https://www.geeksforgeeks.org/python-xml-to-json/
with open(output_file) as xml_file:
data_dict = xmltodict.parse(xml_file.read()).get("testsuite", {})
data_dict = {}
try:
with open(output_file) as xml_file:
data_dict = xmltodict.parse(xml_file.read()).get("testsuite", {})
except:
data_dict = {}
# the format: all the tests are in a top-level list called "testcase"
test_suites = []
test_names = []
Expand All @@ -34,8 +38,12 @@ def parse_mocha_json_to_csv(output_file, new_output_file=None):
def parse_jest_json_to_csv(output_file, new_output_file=None):
if new_output_file is None:
new_output_file = output_file.split(".")[0] + ".csv" # same name, csv file extension
with open(output_file) as json_file:
data_dict = json.loads(json_file.read())
data_dict = {}
try:
with open(output_file) as json_file:
data_dict = json.loads(json_file.read())
except:
data_dict = {}
# the format: all tests are in a top level list called "testResults"
# this is a list of objects that have "assertionResults" representing the test suites
# "assertionResults" is a list of objects that have the test data
Expand Down
10 changes: 9 additions & 1 deletion src/test_JS_repo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def run_tests( manager, pkg_json, crawler, repo_name, cur_dir="."):
+ "infra_" + str(verbosity_index) + "_" \
+ ("" if test_rep_id == "" else test_rep_id + "_") \
+ crawler.TEST_VERBOSE_OUTPUT_JSON
infra_verbosity_config = TestInfo.VERBOSE_TESTS_EXTRA_ARGS[test_infra]
infra_verbosity_config = TestInfo.VERBOSE_TESTS_EXTRA_ARGS.get(test_infra)
if not infra_verbosity_config: # checks if it's an empty object
print("TEST VERBOSE MODE: unsupported test infra " + test_infra)
test_verbosity_output[test_infra] = { "error": True }
Expand Down Expand Up @@ -205,6 +205,14 @@ def instrument_test_command_for_verbose(test_script, test_infra, infra_verbosity
infra_calls = test_script.split(test_infra)
instrumented_test_command = []
for i, infra_call in enumerate(infra_calls):
# if the last char in the string is not whitespace and not a command delimiter,
# and it's not the last string in the split
# then it's a string that is appended to the front of the name of the infra (e.g., "\"jest\"")
# and not a call
if i < len(infra_calls) - 1 and infra_call != "" and (not infra_call[-1].isspace()) and (not any([infra_call.endswith(s) for s in command_split_chars])):
instrumented_test_command += [ infra_call ]
continue

# if the current call is empty string
# then this is the call to the testing infra and the next is the arguments
# so, skip this one
Expand Down

0 comments on commit 7d2f03b

Please sign in to comment.