Skip to content

Commit dd4423f

Browse files
authored
Fix EMTEST_BROWSER command line to not accumulate parameters every time a browser is opened. (#25248)
Fix EMTEST_BROWSER command line to not accumulate parameters every time a browser is opened. This prevents the `-profile ...` directive and other command line args from stacking up on every browser terminate + restart.
1 parent ed10409 commit dd4423f

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

test/common.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,35 @@ def init_worker(counter, lock):
24702470
counter.value += 1
24712471

24722472

2473+
def configure_test_browser():
2474+
global EMTEST_BROWSER
2475+
2476+
if not has_browser():
2477+
return
2478+
2479+
if WINDOWS and '"' not in EMTEST_BROWSER and "'" not in EMTEST_BROWSER:
2480+
# On Windows env. vars canonically use backslashes as directory delimiters, e.g.
2481+
# set EMTEST_BROWSER=C:\Program Files\Mozilla Firefox\firefox.exe
2482+
# and spaces are not escaped. But make sure to also support args, e.g.
2483+
# set EMTEST_BROWSER="C:\Users\clb\AppData\Local\Google\Chrome SxS\Application\chrome.exe" --enable-unsafe-webgpu
2484+
EMTEST_BROWSER = '"' + EMTEST_BROWSER.replace("\\", "\\\\") + '"'
2485+
2486+
if not EMTEST_BROWSER:
2487+
logger.info('No EMTEST_BROWSER set. Defaulting to `google-chrome`')
2488+
EMTEST_BROWSER = 'google-chrome'
2489+
2490+
if EMTEST_BROWSER_AUTO_CONFIG:
2491+
config = None
2492+
if is_chrome():
2493+
config = ChromeConfig()
2494+
elif is_firefox():
2495+
config = FirefoxConfig()
2496+
if config:
2497+
EMTEST_BROWSER += ' ' + ' '.join(config.default_flags)
2498+
if EMTEST_HEADLESS == 1:
2499+
EMTEST_BROWSER += f" {config.headless_flags}"
2500+
2501+
24732502
class BrowserCore(RunnerCore):
24742503
# note how many tests hang / do not send an output. if many of these
24752504
# happen, likely something is broken and it is best to abort the test
@@ -2505,17 +2534,7 @@ def browser_restart(cls):
25052534

25062535
@classmethod
25072536
def browser_open(cls, url):
2508-
global EMTEST_BROWSER, worker_id
2509-
if WINDOWS and '"' not in EMTEST_BROWSER and "'" not in EMTEST_BROWSER:
2510-
# On Windows env. vars canonically use backslashes as directory delimiters, e.g.
2511-
# set EMTEST_BROWSER=C:\Program Files\Mozilla Firefox\firefox.exe
2512-
# and spaces are not escaped. But make sure to also support args, e.g.
2513-
# set EMTEST_BROWSER="C:\Users\clb\AppData\Local\Google\Chrome SxS\Application\chrome.exe" --enable-unsafe-webgpu
2514-
EMTEST_BROWSER = '"' + EMTEST_BROWSER.replace("\\", "\\\\") + '"'
2515-
2516-
if not EMTEST_BROWSER:
2517-
logger.info('No EMTEST_BROWSER set. Defaulting to `google-chrome`')
2518-
EMTEST_BROWSER = 'google-chrome'
2537+
browser_args = EMTEST_BROWSER
25192538

25202539
if EMTEST_BROWSER_AUTO_CONFIG:
25212540
logger.info('Using default CI configuration.')
@@ -2535,19 +2554,16 @@ def browser_open(cls, url):
25352554
if WINDOWS:
25362555
# Escape directory delimiter backslashes for shlex.split.
25372556
browser_data_dir = browser_data_dir.replace('\\', '\\\\')
2538-
EMTEST_BROWSER += f" {config.data_dir_flag}\"{browser_data_dir}\" {' '.join(config.default_flags)}"
2539-
if EMTEST_HEADLESS == 1:
2540-
EMTEST_BROWSER += f" {config.headless_flags}"
25412557
config.configure(browser_data_dir)
2558+
browser_args += f' {config.data_dir_flag}"{browser_data_dir}"'
25422559

2543-
browser_args = shlex.split(EMTEST_BROWSER)
2560+
browser_args = shlex.split(browser_args)
25442561
logger.info('Launching browser: %s', str(browser_args))
25452562
cls.browser_proc = subprocess.Popen(browser_args + [url])
25462563

25472564
@classmethod
25482565
def setUpClass(cls):
25492566
super().setUpClass()
2550-
global worker_id
25512567
cls.PORT = 8888 + (0 if worker_id is None else worker_id)
25522568
cls.SERVER_URL = f'http://localhost:{cls.PORT}'
25532569
cls.HARNESS_URL = f'{cls.SERVER_URL}/run_harness'

test/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ def configure():
512512
assert 'PARALLEL_SUITE_EMCC_CORES' not in os.environ, 'use EMTEST_CORES rather than PARALLEL_SUITE_EMCC_CORES'
513513
parallel_testsuite.NUM_CORES = os.environ.get('EMTEST_CORES') or os.environ.get('EMCC_CORES')
514514

515+
common.configure_test_browser()
516+
515517

516518
def main():
517519
options = parse_args()

0 commit comments

Comments
 (0)