From dd6966b9af56631606858b93bb9a5388bbdd808d Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 17 Apr 2020 12:49:39 +0530 Subject: [PATCH] test-js-with-puppeteer: Extract code to prepare for puppeteer run. --- tools/lib/test_script.py | 10 ++++++++++ tools/test-js-with-puppeteer | 16 +++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/lib/test_script.py b/tools/lib/test_script.py index 62da587bc0..18bafd23ec 100644 --- a/tools/lib/test_script.py +++ b/tools/lib/test_script.py @@ -1,12 +1,15 @@ from typing import Optional, Tuple, Iterable, List import os +import subprocess 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 +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + def get_major_version(v: str) -> int: return int(v.split('.')[0]) @@ -95,3 +98,10 @@ def find_js_test_files(test_dir: str, files: Iterable[str]) -> List[str]: test_files = sorted(glob.glob(os.path.join(test_dir, '*.js'))) return test_files + +def prepare_puppeteer_run() -> None: + os.chdir(ZULIP_PATH) + subprocess.check_call(['node', 'node_modules/puppeteer/install.js']) + os.makedirs('var/puppeteer', exist_ok=True) + for f in glob.glob('var/puppeteer/puppeteer-failure*.png'): + os.remove(f) diff --git a/tools/test-js-with-puppeteer b/tools/test-js-with-puppeteer index 3c61856dac..db2a68669c 100755 --- a/tools/test-js-with-puppeteer +++ b/tools/test-js-with-puppeteer @@ -3,7 +3,6 @@ import argparse import subprocess import sys import os -import glob import shlex ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -38,22 +37,11 @@ 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, find_js_test_files +from tools.lib.test_script import assert_provisioning_status_ok, find_js_test_files, prepare_puppeteer_run from tools.lib.test_server import test_server_running from typing import Iterable -assert_provisioning_status_ok(options.force) - -os.chdir(ZULIP_PATH) - -subprocess.check_call(['node', 'node_modules/puppeteer/install.js']) - -os.makedirs('var/puppeteer', exist_ok=True) - -for f in glob.glob('var/puppeteer/puppeteer-failure*.png'): - os.remove(f) - 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) @@ -87,5 +75,7 @@ def run_tests(files: Iterable[str], external_host: str) -> None: sys.exit(ret) external_host = "zulipdev.com:9981" +assert_provisioning_status_ok(options.force) +prepare_puppeteer_run() run_tests(options.tests, external_host) sys.exit(0)