From 1b5a8c6f54f1dcc2a1cc965e339f0e716ed5bad5 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 19:52:20 +0900 Subject: [PATCH] =?UTF-8?q?test(browser):=20strict=20=EA=B2=80=EC=82=AC?= =?UTF-8?q?=EB=A5=BC=20=EA=B3=B5=EC=9A=A9=20watcher=EB=A1=9C=20=EB=B9=BC?= =?UTF-8?q?=20=EA=B0=99=EC=9D=80=20context=EC=9D=98=20=EB=8B=A4=EB=A5=B8?= =?UTF-8?q?=20=ED=83=AD=EB=8F=84=20=EB=B3=B8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: strict fixture는 fixture의 `page` 하나에만 콘솔·pageerror· requestfailed listener를 붙였다. 다른 탭을 여는 capability 시험 7곳 (cross-context invalidation, OPFS, IndexedDB)의 두 번째 탭은 아무도 보지 않았다. SW recovery 시험은 자기 context를 쓰며 fixture와 다른 손 사본 (WebKit 문구 무시 없음)으로 검사했다. 고친 것: 검사 본문을 `watchBrowserFailures(page, { preloads })`로 뺀다. fixture는 자기 page(preload 검사 포함)와, 같은 context에서 열리는 모든 탭에 같은 함수를 붙인다(탭이 열릴 때 동기로 붙여 spec이 이동하기 전이다). SW recovery는 회복된 load 전에 같은 함수를 붙인다. 손 사본은 지운다. fixture의 기록을 읽는 `preload-use.spec.ts`에 둘째 탭의 console.error가 기록되는지 보는 시험을 더한다. 위험·한계: 둘째 탭의 preload 사용은 보지 않는다(첫 page만). SW recovery도 preload를 보지 않는다. 그 context는 같은 origin을 두 번 열어, WebKit이 회복된 load의 script를 캐시에서 주며 추적기의 route를 지나쳐 모든 preload가 미사용으로 읽혔다(16건). 검증: desktop — 옛 fixture에서 둘째 탭 시험이 세 엔진 모두 실패(RED), 고친 fixture에서 preload-use·SW recovery 통과, capability 세 spec은 FE-GATE-008에서 본다. Refs: 1112/03-05 --- tests/e2e/preload-use.spec.ts | 19 +++++ tests/e2e/service-worker-recovery.spec.ts | 25 +++---- tests/support/browser/strict-browser-test.ts | 77 ++++++++++++++------ tests/visual/scrollbar-gutter.visual.spec.ts | 4 +- 4 files changed, 87 insertions(+), 38 deletions(-) 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 }) => {