diff --git a/tests/e2e/preload-use.spec.ts b/tests/e2e/preload-use.spec.ts index 7f614f83..d748b098 100644 --- a/tests/e2e/preload-use.spec.ts +++ b/tests/e2e/preload-use.spec.ts @@ -298,6 +298,25 @@ recordedTest.describe("the strict fixture's console check", () => { ); }); +// 1112/03-05. The fixture watched its own page only, so a console error in +// a second tab of the same context (the cross-tab capability specs) passed. +recordedTest.describe("the strict fixture's other tabs", () => { + recordedTest.use({ + fixtureReports: { lines: [/^console:error:\[preload-use\] second tab$/u] }, + }); + + recordedTest( + "records a console error in another tab of the context", + async ({ page }) => { + await openHome(page); + const second = await page.context().newPage(); + await openHome(second); + + await second.evaluate(() => console.error("[preload-use] second tab")); + }, + ); +}); + /** * 1105/11-01. The verdict every other spec gets: a recorded failure fails the * test. The record is proven above; this proves the verdict. diff --git a/tests/e2e/service-worker-recovery.spec.ts b/tests/e2e/service-worker-recovery.spec.ts index 400ec503..561330fc 100644 --- a/tests/e2e/service-worker-recovery.spec.ts +++ b/tests/e2e/service-worker-recovery.spec.ts @@ -1,6 +1,11 @@ import path from "node:path"; -import { expect, test, type Page } from "../support/browser/strict-browser-test.ts"; +import { + expect, + test, + watchBrowserFailures, + type Page, +} from "../support/browser/strict-browser-test.ts"; import { prepareServiceWorkerBuilds, removeServiceWorkerBuilds, @@ -91,7 +96,7 @@ test("a REMOVE_REGISTRATION release unregisters a worker that blocks boot", asyn const server = await startBuildServer(builds.dist); // The broken phase fails requests on purpose, so this test drives its own // context instead of the strict `page` fixture and checks the recovered - // load for browser errors itself. + // load for browser errors with the fixture's own watcher (1112/03-05). const context = await browser.newContext(); try { const page = await context.newPage(); @@ -133,22 +138,16 @@ test("a REMOVE_REGISTRATION release unregisters a worker that blocks boot", asyn ) .toBe(true); - const failures: string[] = []; - page.on("console", (message) => { - if (["error", "warning"].includes(message.type())) { - failures.push(`console:${message.type()}:${message.text()}`); - } - }); - page.on("pageerror", (error) => failures.push(`pageerror:${error.name}`)); - page.on("requestfailed", (request) => - failures.push(`requestfailed:${new URL(request.url()).pathname}`), - ); + // No preload check here: this context loaded the origin twice already, + // and WebKit answers the recovered load's scripts from its cache, past + // the tracker's route, so every preload reads as unused (16 in a run). + const recovered = await watchBrowserFailures(page); await page.goto(`${server.origin}/`); expect(await startOutcome(page)).toEqual({ kind: "DISABLED" }); expect( await page.evaluate(() => navigator.serviceWorker.controller === null), ).toBe(true); - expect(failures).toEqual([]); + expect(await recovered.stop()).toEqual([]); } finally { await context.close(); await server.close(); diff --git a/tests/support/browser/strict-browser-test.ts b/tests/support/browser/strict-browser-test.ts index 1c0b5a94..fdda5bc7 100644 --- a/tests/support/browser/strict-browser-test.ts +++ b/tests/support/browser/strict-browser-test.ts @@ -20,6 +20,48 @@ function ignoredConsole(message: ConsoleMessage) { ); } +/** + * 1112/03-05. Records a page's browser failures as `console:…`, `pageerror:…` + * and `requestfailed:…` lines, with the same rules the strict fixture judges + * by. The fixture watches its `page` and every other tab opened in the same + * context; a spec that drives a context of its own watches its pages with + * this. `preloads` also checks that every modulepreload ran (preload-use.ts) + * in the documents open when `stop` runs; attach it before the navigation + * that loads them. + */ +export async function watchBrowserFailures( + page: Page, + options: Readonly<{ preloads?: boolean }> = {}, +): Promise }>> { + const failures: string[] = []; + const onConsole = (message: ConsoleMessage) => { + if (["error", "warning"].includes(message.type()) && !ignoredConsole(message)) { + failures.push(`console:${message.type()}:${message.text()}`); + } + }; + const onPageError = (error: Error) => { + failures.push(`pageerror:${error.name}`); + }; + const onRequestFailed = (request: import("@playwright/test").Request) => { + failures.push( + `requestfailed:${request.method()}:${new URL(request.url()).pathname}:${request.failure()?.errorText ?? "unknown"}`, + ); + }; + page.on("console", onConsole); + page.on("pageerror", onPageError); + page.on("requestfailed", onRequestFailed); + const preloads = options.preloads ? await trackPreloadUse(page) : null; + return Object.freeze({ + async stop() { + if (preloads) failures.push(...(await preloads.check()).failures); + page.off("console", onConsole); + page.off("pageerror", onPageError); + page.off("requestfailed", onRequestFailed); + return [...failures]; + }, + }); +} + /** * 1105/11-01. What the strict `page` fixture does with every failure it * recorded, once the test has ended. @@ -62,32 +104,19 @@ export const test = base.extend<{ ); }, page: async ({ page, browserFailureVerdict }, use) => { - const preloads = await trackPreloadUse(page); - const failures: string[] = []; - const onConsole = (message: ConsoleMessage) => { - if ( - ["error", "warning"].includes(message.type()) && - !ignoredConsole(message) - ) { - failures.push(`console:${message.type()}:${message.text()}`); - } + const watched = [await watchBrowserFailures(page, { preloads: true })]; + // 1112/03-05. A second tab of the same context (the cross-tab specs) + // went unwatched. Its listeners are attached as the tab opens, before + // the spec can navigate it; preload use is checked on the first page only. + const pending: Promise[] = []; + const onPage = (opened: Page) => { + pending.push(watchBrowserFailures(opened).then((watcher) => void watched.push(watcher))); }; - const onPageError = (error: Error) => { - failures.push(`pageerror:${error.name}`); - }; - const onRequestFailed = (request: import("@playwright/test").Request) => { - failures.push( - `requestfailed:${request.method()}:${new URL(request.url()).pathname}:${request.failure()?.errorText ?? "unknown"}`, - ); - }; - page.on("console", onConsole); - page.on("pageerror", onPageError); - page.on("requestfailed", onRequestFailed); + page.context().on("page", onPage); await use(page); - failures.push(...(await preloads.check()).failures); - page.off("console", onConsole); - page.off("pageerror", onPageError); - page.off("requestfailed", onRequestFailed); + page.context().off("page", onPage); + await Promise.all(pending); + const failures = (await Promise.all(watched.map((watcher) => watcher.stop()))).flat(); browserFailureVerdict.judge(failures); }, }); diff --git a/tests/visual/scrollbar-gutter.visual.spec.ts b/tests/visual/scrollbar-gutter.visual.spec.ts index 6ad4e93a..0df6d62b 100644 --- a/tests/visual/scrollbar-gutter.visual.spec.ts +++ b/tests/visual/scrollbar-gutter.visual.spec.ts @@ -66,7 +66,9 @@ async function stripColours( new Blob([bytes], { type: "image/png" }), ); const canvas = new OffscreenCanvas(bitmap.width, bitmap.height); - const context = canvas.getContext("2d"); + // Read back once per strip: without the hint Chromium warns on the + // console of this tab, which the strict fixture watches (1112/03-05). + const context = canvas.getContext("2d", { willReadFrequently: true }); if (context === null) throw new Error("no 2d canvas context"); context.drawImage(bitmap, 0, 0); return offsets.map(({ x, width }) => {