refactor: Extract code of running a single puppeteer test into a function.

This commit is contained in:
Dinesh 2022-03-02 10:33:44 +05:30 committed by Steve Howell
parent a529dc8c76
commit 02cf8e831f
1 changed files with 32 additions and 26 deletions

View File

@ -61,16 +61,7 @@ parser.add_argument(
options = parser.parse_args()
def run_tests(files: Iterable[str], external_host: str) -> None:
test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests")
test_files = find_js_test_files(test_dir, files)
total_tests = len(test_files)
def run_tests(test_number: int = 0) -> Tuple[int, int]:
ret = 1
current_test_num = test_number
for test_file in test_files[test_number:]:
test_name = os.path.basename(test_file)
def run_single_test(test_file: str, test_number: int, total_tests: int) -> int:
cmd = [
"node",
"--unhandled-rejections=strict",
@ -79,22 +70,37 @@ def run_tests(files: Iterable[str], external_host: str) -> None:
"--transpile-only",
test_file,
]
test_name = os.path.basename(test_file)
cmd_str = " ".join(map(shlex.quote, cmd))
print(
"\n\n===================== ({}/{}) {}\nRunning {}\n\n".format(
current_test_num + 1, total_tests, test_name, " ".join(map(shlex.quote, cmd))
),
f"\n\n===================== ({test_number}/{total_tests}) {test_name} =====================\nRunning {cmd_str}\n\n",
flush=True,
)
ret = subprocess.call(cmd)
# Resetting test environment.
reset_zulip_test_database()
# We are calling to /flush_caches to remove all the server-side caches.
response = requests.post("http://zulip.zulipdev.com:9981/flush_caches")
assert response.status_code == 200
if ret != 0:
return ret, current_test_num
return ret
def run_tests(files: Iterable[str], external_host: str) -> None:
test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests")
test_files = find_js_test_files(test_dir, files)
total_tests = len(test_files)
def run_tests(test_number: int = 0) -> Tuple[int, int]:
current_test_num = test_number
for test_file in test_files[test_number:]:
return_code = run_single_test(test_file, current_test_num + 1, total_tests)
if return_code != 0:
return return_code, current_test_num
current_test_num += 1
return 0, -1