From 277f05513eb7ea6829ed67d4c2f4579eec2436fb Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:52:16 -0700 Subject: [PATCH] test: pick Chrome debugging port by Jest worker ID --- test/integration/selenium-helpers.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js index c3ae7ab52..73177252a 100644 --- a/test/integration/selenium-helpers.js +++ b/test/integration/selenium-helpers.js @@ -57,6 +57,12 @@ class SeleniumHelper { } getDriver () { + // JEST_WORKER_ID will always be '1' with --runInBand + // in that case, we want to use the default port so tools like VSCode can attach to the debugger + const defaultPort = 9222; + const workerIndex = parseInt(process.env.JEST_WORKER_ID || '1', 10) - 1; // one-based ID => zero-based index + const portNumber = defaultPort + workerIndex; + const chromeOptions = new chrome.Options(); if (headless) { chromeOptions.addArguments('--headless'); @@ -64,7 +70,7 @@ class SeleniumHelper { chromeOptions.addArguments('window-size=1024,1680'); chromeOptions.addArguments('--no-sandbox'); chromeOptions.addArguments('--disable-dev-shm-using'); - chromeOptions.addArguments('--remote-debugging-port=9222'); + chromeOptions.addArguments(`--remote-debugging-port=${portNumber}`); chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER); let driver = new webdriver.Builder() .forBrowser('chrome')