Files
clean-architecture-frontend…/playwright.visual.config.ts
DongHyeonka ec95cde5df test(service-worker): 대기 숫자를 지우고 시험 timeout 하나에 맡긴다
Service Worker e2e 두 spec의 대기 넷(waitForFunction 60 s 둘, expect
30 s 둘)이 Playwright 기본 시험 timeout 30 s 이상이다. 설정과 spec
어디에도 시험 timeout이 없고, beforeAll의 test.setTimeout(180_000)은
그 hook의 기한만 바꾼다. 그래서 대기가 자기 기한에 닿기 전에 시험이
먼저 끊기고, 숫자의 근거도 없다.

대기 숫자를 지운다. waitForFunction과 expect.poll은 시험 timeout만
받는다. poll에는 `timeout: 0`을 준다. 그래야 기본 expect timeout(5 s)이
아니라 시험 기한까지 본다. toBeVisible은 기본 expect timeout을 받는다.
desktop에서 두 spec을 3회 돌려 잰 가장 긴 시험이 7.7 s(webkit, 기본
30 s 아래)라 describe.configure로 시험 timeout을 주지 않는다. 잰 가장
긴 대기는 waitForFunction 1.05 s, expect.poll 1.95 s(chromium 3회 모두
1.9 s대, webkit 3회 0.01 s), toBeVisible 0.09 s다.

버린 안: 대기를 25 s로 줄이기는 숫자만 바뀌고 근거가 없다. poll을 기본
5 s에 맡기기는 잰 최장의 2.6배뿐이라, 느린 날 끊기면 FE-GATE-008의
판정용 재시도가 flaky로 run을 떨어뜨린다(리뷰 지적).

위험·한계: toBeVisible 기한이 30 s에서 기본 5 s가 된다(잰 최장의 약
55배). poll은 예전처럼 시험 timeout에 끊긴다. 측정 때 desktop load는
15~23(12코어)이었다. beforeAll의 test.setTimeout(180_000)은 이 커밋이
다루지 않는다(잰 beforeAll 최장 7.3 s).

검증: 고치기 전 origin/main에서 `git grep -nE 'timeout: (30|60)_000' --
'tests/e2e/service-worker-*.spec.ts'` rc=0 4줄, 고친 뒤 rc=1 0줄.
poll의 `timeout: 0`은 Playwright 1.62 deadlineForMatcher
(lib/matchers/expect.js)가 시험 기한 250 ms 전을 기한으로 쓴다. desktop
CI env에서 두 spec을 3회 rc=0(17 passed·4 skipped씩, 재시도 0, poll을
기본 5 s에 둔 측정 트리 49b979c5), poll에 timeout 0을 준 트리 3a291c92(7752f90d 위,
다음 커밋까지 든 트리)에서 1회 rc=0(17 passed·4 skipped, load 22).

Refs: REV-FE-0012, REV-FE-0023
2026-11-23 12:45:31 +09:00

111 lines
4.2 KiB
TypeScript

import { fileURLToPath } from "node:url";
import { defineConfig, devices } from "@playwright/test";
import { LOCAL_BUILD_IDENTITY } from "./scripts/lib/build-environment.ts";
import { flakyJudgement, flakyJudgementReporter } from "./scripts/lib/playwright-flaky-judgement.ts";
import {
reservePort,
RUN_OUTPUT_ROOT_VARIABLE,
TEST_PORT_VARIABLES,
testRunPath,
testRunRoot,
} from "./scripts/lib/run-isolation.ts";
import { storybookStaticServer } from "./scripts/lib/storybook-static.ts";
import { childProcessTimeout } from "./tests/helpers/child-process-timeout.ts";
// 1105/12-04. Under TEST_RUN_ID the results, report and build are the run's
// own (.tmp/runs/<id>/); the goldens in snapshotDir are shared and only read.
// The preview listens on a free port (TEST_VISUAL_PORT pins one); it shared
// 4174 with the capability dev server.
const dist = testRunPath("dist");
const port = await reservePort(TEST_PORT_VARIABLES.visual);
const origin = `http://127.0.0.1:${port}`;
// The design-system and screen-state galleries are workshop stories
// (src/presentation/design-system/galleries.stories.tsx); their goldens open
// the static workshop, which the second server serves
// (TEST_VISUAL_WORKSHOP_PORT pins its port).
const workshopPort = await reservePort(TEST_PORT_VARIABLES.visualWorkshop);
export default defineConfig({
testDir: "./tests/visual",
forbidOnly: true,
...flakyJudgement(),
snapshotDir: "./tests/visual/__snapshots__",
outputDir: testRunPath("artifacts/tests/visual/results"),
reporter: [
["list"],
flakyJudgementReporter,
[
"html",
{ outputFolder: testRunPath("artifacts/tests/visual/report"), open: "never" },
],
[
"junit",
{ outputFile: testRunPath("artifacts/tests/visual/results.xml"), includeRetries: true },
],
],
expect: {
toHaveScreenshot: {
animations: "disabled",
caret: "hide",
// 11-03. An absolute count, not a share of the image: 0.2% allowed
// 2,592 px on the wide shell and let the 1,146 px UI-04 regression
// pass. With fonts and raster settings pinned (11-02), a clean build
// differs by 0 px, so this only covers stray anti-aliasing.
maxDiffPixels: 50,
scale: "css",
},
},
use: {
...devices["Desktop Chrome"],
baseURL: origin,
colorScheme: "light",
locale: "en-US",
trace: "retain-on-failure",
launchOptions: {
// 11-02. Chromium sees only the fonts the goldens were captured with,
// whatever the host or an outer FONTCONFIG_FILE says. The
// `visual-fonts` project checks them before any screenshot.
env: {
...process.env,
FONTCONFIG_FILE: fileURLToPath(
new URL("./tests/visual/fonts.conf", import.meta.url),
),
},
},
},
webServer: [
{
// The home page and the platform overview print the build and release
// identity. CI sets VITE_BUILD_ID, VITE_COMMIT_SHA and RELEASE_ID for
// the whole workflow, so its build drew other text than the goldens and
// every CI run failed here. The goldens are the template's shape,
// captured with the local identity.
// 1103/11-08: CI too, or the build is checked as a release build.
env: { ...LOCAL_BUILD_IDENTITY, [RUN_OUTPUT_ROOT_VARIABLE]: testRunRoot() },
// REV-FE-0015. The wait covers the build: longest start 3,887 ms on
// desktop (2026-11-23, 2 runs), sized like a child process of a test
// (tests/helpers/child-process-timeout.ts).
timeout: childProcessTimeout(3_887),
command:
`corepack pnpm build && corepack pnpm preview --host 127.0.0.1 --port ${port} --strictPort --outDir ${dist}`,
url: origin,
reuseExistingServer: false,
},
{
// REV-FE-0015. Playwright starts this server once the first one is up,
// so the two builds do not run together. Longest start with the build:
// 8,888 ms on desktop (2026-11-23, 2 runs), sized as above.
timeout: childProcessTimeout(8_888),
command: storybookStaticServer(workshopPort).command,
url: `http://127.0.0.1:${workshopPort}`,
reuseExistingServer: false,
},
],
projects: [
{ name: "visual-fonts", testMatch: /fonts\.setup\.ts$/ },
{ name: "chromium-visual", dependencies: ["visual-fonts"] },
],
});