diff --git a/app/tests/organization-notices-browser.ts b/app/tests/organization-notices-browser.ts index 8272ada152..a79d42d1c1 100644 --- a/app/tests/organization-notices-browser.ts +++ b/app/tests/organization-notices-browser.ts @@ -507,28 +507,65 @@ async function stylesheet(classes: string[]): Promise { const browsers = new Map(); let script: string; +/** Set while `stop` closes the browsers, so only a browser lost before then is said. */ +let stopping = false; + +/* + * A PAGE OR BROWSER LOST MID-TEST IS SAID IN THE LOG, AND HOW. Playwright fails whatever the test was + * waiting on with the same words whether the browser crashed the page or something closed it + * ("Target page, context or browser has been closed"), so a test that failed that way in CI said + * nothing of which it was. Lines start with [browser lost]; the failing test's name follows them in + * the output. Nothing here changes what a test does. + */ /** Build the app (`fixture`, beside this file) and start each browser asked for. */ export async function start( fixture = "organization-notices.fixture.tsx", ): Promise { script = await bundle(fixture); + stopping = false; const playwright = await import("playwright-core"); for (const engine of engines) { const type: BrowserType = playwright[engine]; - browsers.set( - engine, - // The CI job installs full Chromium without the headless shell. - await type.launch(engine === "chromium" ? { channel: "chromium" } : {}), + // The CI job installs full Chromium without the headless shell. + const browser = await type.launch( + engine === "chromium" ? { channel: "chromium" } : {}, ); + browser.on("disconnected", () => { + if (!stopping) + console.error( + `[browser lost] ${engine} disconnected: the browser crashed or was killed`, + ); + }); + browsers.set(engine, browser); } } export async function stop(): Promise { + stopping = true; for (const browser of browsers.values()) await browser.close(); browsers.clear(); } +/** Say when `page` crashes, or closes without the test closing it. */ +function sayIfLost(page: Page, what: string): void { + let closedByTest = false; + const close = page.close.bind(page); + page.close = (options) => { + closedByTest = true; + return close(options); + }; + page.on("crash", () => + console.error(`[browser lost] the page crashed: ${what}, at ${page.url()}`), + ); + page.on("close", () => { + if (!closedByTest && !stopping) + console.error( + `[browser lost] the page closed, not by the test: ${what}, at ${page.url()}`, + ); + }); +} + /** The app opened at `path`, signed in, in a window of `look`'s size and theme. */ export async function open( engine: string, @@ -543,6 +580,7 @@ export async function open( colorScheme: look.theme, reducedMotion: "reduce", }); + sayIfLost(page, `${engine}, ${look.width}, ${look.theme}, opened at ${path}`); page.on("pageerror", (error) => console.error(error)); const inter = join(packageDir("@fontsource-variable/inter"), "files"); await page.route(`${ORIGIN}/**`, (route) => {