diff --git a/frontend_tests/run-casper b/frontend_tests/run-casper index 7544eb3ece..8229e7b984 100755 --- a/frontend_tests/run-casper +++ b/frontend_tests/run-casper @@ -66,7 +66,7 @@ sys.path.insert(0, ZULIP_PATH) from tools.lib import sanity_check sanity_check.check_venv(__file__) -from tools.lib.test_script import assert_provisioning_status_ok +from tools.lib.test_script import assert_provisioning_status_ok, find_js_test_files from tools.lib.test_server import test_server_running from typing import Iterable, List @@ -88,18 +88,7 @@ def reset_database() -> None: def run_tests(files: Iterable[str], external_host: str) -> None: test_dir = os.path.join(ZULIP_PATH, 'frontend_tests/casper_tests') - test_files = [] - for file in files: - for file_name in os.listdir(test_dir): - if file_name.startswith(file): - file = file_name - break - if not os.path.exists(file): - file = os.path.join(test_dir, file) - test_files.append(os.path.abspath(file)) - - if not test_files: - test_files = sorted(glob.glob(os.path.join(test_dir, '*.js'))) + test_files = find_js_test_files(test_dir, files) # 10-admin.js is too flaky! if options.skip_flaky: diff --git a/tools/lib/test_script.py b/tools/lib/test_script.py index 3f685a3674..62da587bc0 100644 --- a/tools/lib/test_script.py +++ b/tools/lib/test_script.py @@ -1,10 +1,11 @@ -from typing import Optional, Tuple +from typing import Optional, Tuple, Iterable, List import os import sys from distutils.version import LooseVersion from version import PROVISION_VERSION from scripts.lib.zulip_tools import get_dev_uuid_var_path +import glob def get_major_version(v: str) -> int: return int(v.split('.')[0]) @@ -77,3 +78,20 @@ def assert_provisioning_status_ok(force: bool) -> None: print(msg) print('If you really know what you are doing, use --force to run anyway.') sys.exit(1) + + +def find_js_test_files(test_dir: str, files: Iterable[str]) -> List[str]: + test_files = [] + for file in files: + for file_name in os.listdir(test_dir): + if file_name.startswith(file): + file = file_name + break + if not os.path.exists(file): + file = os.path.join(test_dir, file) + test_files.append(os.path.abspath(file)) + + if not test_files: + test_files = sorted(glob.glob(os.path.join(test_dir, '*.js'))) + + return test_files diff --git a/tools/test-js-with-puppeteer b/tools/test-js-with-puppeteer index 38c13c5290..3c61856dac 100755 --- a/tools/test-js-with-puppeteer +++ b/tools/test-js-with-puppeteer @@ -38,7 +38,7 @@ sys.path.insert(0, ZULIP_PATH) from tools.lib import sanity_check sanity_check.check_venv(__file__) -from tools.lib.test_script import assert_provisioning_status_ok +from tools.lib.test_script import assert_provisioning_status_ok, find_js_test_files from tools.lib.test_server import test_server_running from typing import Iterable @@ -56,18 +56,7 @@ for f in glob.glob('var/puppeteer/puppeteer-failure*.png'): def run_tests(files: Iterable[str], external_host: str) -> None: test_dir = os.path.join(ZULIP_PATH, 'frontend_tests/puppeteer_tests') - test_files = [] - for file in files: - for file_name in os.listdir(test_dir): - if file_name.startswith(file): - file = file_name - break - if not os.path.exists(file): - file = os.path.join(test_dir, file) - test_files.append(os.path.abspath(file)) - - if not test_files: - test_files = sorted(glob.glob(os.path.join(test_dir, '*.js'))) + test_files = find_js_test_files(test_dir, files) def run_tests() -> int: ret = 1