Files
tech-log-frontend/tests/support/browser/strict-browser-test.ts
T
DongHyeonka 40075c9afd test(browser): WebKit의 「preload를 몇 초 안에 안 썼다」 추측 경고를 받아들인다
WebKit은 load 이벤트 3초 뒤, 아직 쓰이지 않은 link preload마다 경고를
한 번 낸다. 공용 fixture는 경고를 실패로 센다. 그런데 desktop 호스트의
WebKit은 화면 하나를 여는 데 4초 안팎이 걸려, 곧 쓰일 청크에도 이 경고가
나온다. app-shell 시험이 3회 반복 중 한 번 이것으로 떨어졌다
(document-kind-labels-*.js).

템플릿(1103/11-09)과 같은 문장 정규식으로 이 경고만 무시한다.

한계: 템플릿은 이 추측 대신 「preload한 스크립트가 실제로 실행됐는지」를
모든 엔진에서 직접 검사한다(preload-use.ts, 시험 서버가 빌드 스크립트에
표시를 넣는다). 그 장치는 CSP·SW 시험의 응답 가로채기까지 같이 고쳐야
해서 옮기지 않았다. 그래서 쓰이지 않는 preload는 지금 어느 엔진에서도
잡히지 않는다. 다음 템플릿 동기화 때 옮길 일이다.

검증: app-shell을 포함한 다섯 시험을 세 엔진에서 3회 반복해 81건 통과.
2026-11-12 18:38:30 +09:00

101 lines
3.9 KiB
TypeScript

import {
expect,
test as base,
type ConsoleMessage,
type Page,
} from "@playwright/test";
/**
* Firefox's font sanitizer (OTS) reports that the `name` table of the bundled
* `pretendard` 1.3.9 variable font lists its records out of order. It sorts
* them itself and the font still loads (`document.fonts.check` is true in
* Firefox); Chromium and WebKit say nothing. The file is the npm package's, not
* ours. Only this exact warning for this font is ignored: a font the sanitizer
* rejects logs a different line and still fails.
*/
const FIREFOX_PRETENDARD_NAME_ORDER =
/^\[JavaScript Warning: "downloadable font: name: name records are not sorted\. \(font-family: "Pretendard Variable" style:normal weight:45\.\.920 stretch:100 src index:0\) source: http:\/\/127\.0\.0\.1:\d+\/[\w./@-]*PretendardVariable(?:-[\w-]+)?\.woff2"\]$/u;
/**
* Template 1103/11-09. WebKit's guess, three seconds after the load event,
* that a preload went unused. It fires for chunks the page runs a moment
* later, which on the desktop host is often (WebKit takes about 4 s to open a
* page there). The template replaces it with a check of its own that every
* preloaded script ran (preload-use.ts); that check is not ported yet.
*/
const WEBKIT_UNUSED_PRELOAD_GUESS =
/^The resource \S+ was preloaded using link preload but not used within a few seconds from the window's load event\. Please make sure it wasn't preloaded for nothing\.$/u;
function ignoredConsole(message: ConsoleMessage) {
return (
message.type() === "warning" &&
(message.text().includes("NO_COLOR") ||
FIREFOX_PRETENDARD_NAME_ORDER.test(message.text()) ||
WEBKIT_UNUSED_PRELOAD_GUESS.test(message.text()))
);
}
export const test = base.extend<{
/**
* Browser failures a test provokes on purpose, matched against the recorded
* `console:…`, `pageerror:…` or `requestfailed:…` line (for example the
* browser's log line for a mocked 4xx). Everything else still fails. One
* pattern, not an array: `test.use` reads an array as a `[value, options]`
* fixture tuple.
*/
allowedBrowserFailure: RegExp | undefined;
}>({
allowedBrowserFailure: [undefined, { option: true }],
page: async ({ page, allowedBrowserFailure }, use) => {
const failures: string[] = [];
let mainDocumentStatus: number | null = null;
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"}`,
);
};
const onResponse = (response: import("@playwright/test").Response) => {
if (
response.request().resourceType() === "document" &&
response.frame() === page.mainFrame()
) {
mainDocumentStatus = response.status();
}
};
page.on("console", onConsole);
page.on("pageerror", onPageError);
page.on("requestfailed", onRequestFailed);
page.on("response", onResponse);
await use(page);
page.off("console", onConsole);
page.off("pageerror", onPageError);
page.off("requestfailed", onRequestFailed);
page.off("response", onResponse);
const expectedDocumentNotFoundConsole =
"console:error:Failed to load resource: the server responded with a status of 404 (Not Found)";
expect(
failures.filter(
(failure) =>
(failure !== expectedDocumentNotFoundConsole ||
mainDocumentStatus !== 404) &&
!allowedBrowserFailure?.test(failure),
),
"unexpected browser console/page errors",
).toEqual([]);
},
});
export { expect };
export type { Page };