diff --git a/packages/jest-environment-puppeteer/src/browsers.ts b/packages/jest-environment-puppeteer/src/browsers.ts index c65e798f..f4743a75 100644 --- a/packages/jest-environment-puppeteer/src/browsers.ts +++ b/packages/jest-environment-puppeteer/src/browsers.ts @@ -80,14 +80,19 @@ export const startBrowsers = async ({ config: JestPuppeteerConfig; jestConfig: JestConfig; }): Promise => { + const workersCount = getWorkersCount(jestConfig); + saveWorkersCount(workersCount); + if (config.connect?.browserWSEndpoint) { + if (workersCount > 1) { + throw new Error( + "Cannot use `connect.browserWSEndpoint` with multiple workers. Set Jest `maxWorkers` to 1.", + ); + } saveWsEndpoints([config.connect.browserWSEndpoint]); return []; } - const workersCount = getWorkersCount(jestConfig); - saveWorkersCount(workersCount); - const browsers = await Promise.all( Array.from({ length: workersCount }).map(() => openBrowser(config)), );