mirror of https://github.com/zulip/zulip.git
refactor: Extract code of running a single puppeteer test into a function.
This commit is contained in:
parent
a529dc8c76
commit
02cf8e831f
|
@ -61,40 +61,46 @@ parser.add_argument(
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def run_single_test(test_file: str, test_number: int, total_tests: int) -> int:
|
||||||
|
cmd = [
|
||||||
|
"node",
|
||||||
|
"--unhandled-rejections=strict",
|
||||||
|
os.path.join(ZULIP_PATH, "node_modules/.bin/ts-node"),
|
||||||
|
"--script-mode",
|
||||||
|
"--transpile-only",
|
||||||
|
test_file,
|
||||||
|
]
|
||||||
|
|
||||||
|
test_name = os.path.basename(test_file)
|
||||||
|
cmd_str = " ".join(map(shlex.quote, cmd))
|
||||||
|
print(
|
||||||
|
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
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def run_tests(files: Iterable[str], external_host: str) -> None:
|
def run_tests(files: Iterable[str], external_host: str) -> None:
|
||||||
test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests")
|
test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests")
|
||||||
test_files = find_js_test_files(test_dir, files)
|
test_files = find_js_test_files(test_dir, files)
|
||||||
total_tests = len(test_files)
|
total_tests = len(test_files)
|
||||||
|
|
||||||
def run_tests(test_number: int = 0) -> Tuple[int, int]:
|
def run_tests(test_number: int = 0) -> Tuple[int, int]:
|
||||||
ret = 1
|
|
||||||
current_test_num = test_number
|
current_test_num = test_number
|
||||||
for test_file in test_files[test_number:]:
|
for test_file in test_files[test_number:]:
|
||||||
test_name = os.path.basename(test_file)
|
return_code = run_single_test(test_file, current_test_num + 1, total_tests)
|
||||||
cmd = [
|
if return_code != 0:
|
||||||
"node",
|
return return_code, current_test_num
|
||||||
"--unhandled-rejections=strict",
|
|
||||||
os.path.join(ZULIP_PATH, "node_modules/.bin/ts-node"),
|
|
||||||
"--script-mode",
|
|
||||||
"--transpile-only",
|
|
||||||
test_file,
|
|
||||||
]
|
|
||||||
print(
|
|
||||||
"\n\n===================== ({}/{}) {}\nRunning {}\n\n".format(
|
|
||||||
current_test_num + 1, total_tests, test_name, " ".join(map(shlex.quote, cmd))
|
|
||||||
),
|
|
||||||
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
|
|
||||||
current_test_num += 1
|
current_test_num += 1
|
||||||
return 0, -1
|
return 0, -1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue