Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ process.env.TEST_SERVER_PORT = port;
*/
const jestPuppeteerConfig = {
launch: {
browser: process.env.BROWSER || "chrome",
headless: "new",
args: ["--no-sandbox"],
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"lint": "prettier --check . && eslint .",
"test": "jest --runInBand",
"test:incognito": "cross-env INCOGNITO=true jest --runInBand",
"test:firefox": "cross-env BROWSER=firefox jest --runInBand",
"release": "npm run build && lerna publish --conventional-commits && npx conventional-github-releaser -p angular",
"release-canary": "npm run build && lerna publish --canary --dist-tag canary"
},
Expand Down
32 changes: 29 additions & 3 deletions packages/jest-environment-puppeteer/src/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,41 @@ export const startBrowsers = async ({
);
const wsEndpoints = browsers.map((browser) => browser.wsEndpoint());
saveWsEndpoints(wsEndpoints);
browsers.forEach((browser) => browser.disconnect());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why disconnecting directly?

return browsers;
};

export const closeBrowsers = async (
config: JestPuppeteerConfig,
browsers: Browser[],
) => {
await Promise.all(
browsers.map(async (browser) => closeBrowser(config, browser)),
);
if (config.connect) {
await Promise.all(
browsers.map(async (browser) => closeBrowser(config, browser)),
);
}

const closeRequests: Promise<void>[] = [];
const puppeteer = getPuppeteer();
const wsEndpoints = readWsEndpoints();
while (wsEndpoints.length) {
const wsEndpoint = wsEndpoints.pop()!;
closeRequests.push(
puppeteer
.connect({
Comment on lines +123 to +124
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we connecting into the closeBrowsers

...(config.launch?.browser === "firefox" && {
protocol: "webDriverBiDi",
}),
Comment on lines +125 to +127
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a hack here?

...config.connect,
...config.launch,
browserURL: undefined,
browserWSEndpoint: wsEndpoint,
})
.then((browser) => browser.close()),
);
}
Comment on lines +120 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just do a map instead of doing a loop like that?

await Promise.all(closeRequests);
saveWsEndpoints([]);
};

const getWorkerWsEndpoint = (): string => {
Expand All @@ -128,6 +153,7 @@ export const connectBrowserFromWorker = async (
const wsEndpoint = getWorkerWsEndpoint();
const puppeteer = getPuppeteer();
return puppeteer.connect({
...(config.launch?.browser === "firefox" && { protocol: "webDriverBiDi" }),
...config.connect,
...config.launch,
browserURL: undefined,
Expand Down
Loading