Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Dinesh02cf8e831f45
diff --git a/tools/test-js-with-puppeteer b/tools/test-js-with-puppeteer
index 45ae405c463..5b38200755d 100755
--- a/tools/test-js-with-puppeteer
+++ b/tools/test-js-with-puppeteer
@@ -61,40 +61,46 @@ parser.add_argument(
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:
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)
- cmd = [
- "node",
- "--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
+ 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