diff --git a/src/TestInfo.py b/src/TestInfo.py index 0c91d2c..9e89972 100644 --- a/src/TestInfo.py +++ b/src/TestInfo.py @@ -40,9 +40,11 @@ class TestInfo: } # extra args, their position in the arg list, and any post-processing required # post-processing is a function that takes 2 arguments: input file and output file + # CAUTION: DO NOT PUT ANY MORE ARGS AFTER PLACEHOLDER_OUTPUT_FILE_NAME. THE CODE THAT + # PARSES THE OUTPUT RELIES ON THIS BEING THE *LAST* ARGUMENT VERBOSE_TESTS_EXTRA_ARGS = { "jest": { - "args": " --verbose --json --outputFile=$PLACEHOLDER_OUTPUT_FILE_NAME$", + "args": " --verbose --json -i --outputFile=$PLACEHOLDER_OUTPUT_FILE_NAME$", "position": -1, "post_processing": TestOutputProc.parse_jest_json_to_csv }, @@ -116,6 +118,8 @@ def __init__(self, success, error_stream, output_stream, manager, VERBOSE_MODE): self.timed_out = False self.VERBOSE_MODE = VERBOSE_MODE self.test_verbosity_output = None + self.startTime = 0 + self.endTime = 0 def set_test_command( self, test_command): self.test_command = test_command @@ -194,6 +198,8 @@ def get_json_rep( self): if self.test_verbosity_output: json_rep["test_verbosity_output"] = self.test_verbosity_output json_rep["timed_out"] = self.timed_out + json_rep["start_time"] = self.start_time + json_rep["end_time"] = self.end_time return( json_rep) def __str__(self): diff --git a/src/test_JS_repo_lib.py b/src/test_JS_repo_lib.py index 4623306..73ae479 100644 --- a/src/test_JS_repo_lib.py +++ b/src/test_JS_repo_lib.py @@ -2,6 +2,7 @@ import subprocess import json import os +import time from TestInfo import * def run_command( commands, timeout=None): @@ -117,6 +118,9 @@ def run_tests( manager, pkg_json, crawler, repo_name, cur_dir="."): test_command = pkg_json.get("scripts", {})[t] test_infras = TestInfo.get_test_infras_list(test_command, manager) test_verbosity_output = {} + # initialize these variables for timing; they'll be set before/after running test commands (resp) + start_time = 0 + end_time = 0 # if we're in verbose testing mode (i.e. getting all timing info for each test, etc) # then, we rerun the test commands with all the commands for adding verbose_mode to # each of the test infras involved (individually) @@ -145,7 +149,10 @@ def run_tests( manager, pkg_json, crawler, repo_name, cur_dir="."): with open("package.json", 'w') as f: json.dump( pkg_json, f) print("Running verbosity: " + manager + infra_verbosity_command) + # time how long the next line takes + start_time = time.time() error, output, retcode = run_command( manager + verbosity_script_name, crawler.TEST_TIMEOUT) + end_time = time.time() # if there's post-processing to be done if not infra_verbosity_post_proc is None: for out_file_obj in out_files: @@ -163,12 +170,16 @@ def run_tests( manager, pkg_json, crawler, repo_name, cur_dir="."): run_command( "mv TEMP_package.json_TEMP package.json") # not verbose test mode -- just run the normal test command else: + start_time = time.time() error, output, retcode = run_command( manager + t, crawler.TEST_TIMEOUT) + end_time = time.time() test_info = TestInfo( (retcode == 0), error, output, manager, crawler.VERBOSE_MODE) # the below info on the test infras etc is independent of verbose mode: just based on the command itself test_info.set_test_command( test_command) test_info.compute_test_infras() test_info.compute_nested_test_commands( test_scripts) + test_info.start_time = start_time + test_info.end_time = end_time # note: if we're running in verbose mode, then the stats will be that of the last executed verbose mode # instrumented version of the test command test_info.compute_test_stats()