From 6897b2225ad3567c322913864ae97267beae4922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Thu, 15 Feb 2024 11:07:52 +0100 Subject: [PATCH] fix: fix `WORKERS_COUNT` not found (#578) --- packages/jest-environment-puppeteer/src/browsers.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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)), );