Files
clean-architecture-frontend…/playwright.visual.config.ts
T
DongHyeonka c7e80f2f8a test(visual): 갤러리를 Storybook story로 옮기고 골든 대상을 바꾼다
예제 화면 /examples/ui·/examples/states가 visual 골든 2장과 갤러리
브라우저 시험의 대상이다. 2026-11-07 소유자 결정으로 예제 화면을
지우므로 그 역할을 먼저 옮긴다(design-docs repo-structure/
04-frontend-layout.md 9.2절 2단계 (1)).

두 갤러리 화면을 그대로 src/presentation/design-system/
galleries.stories.tsx로 옮겼다. 화면 단위 story(parameters.page)는
preview가 여백을 더하지 않아 앱 안과 같은 폭으로 그려진다. visual
설정은 Storybook 정적 빌드를 두 번째 web server로 띄우고
(TEST_VISUAL_WORKSHOP_PORT, 빌드 명령은 workshop 설정과 같은
scripts/lib/storybook-static.ts), 골든 2장은 그 story를 찍는다. 어두운
골든은 테마 선택기가 없어 시스템 dark(colorScheme)로 그린다. e2e의
갤러리 상호작용(텍스트 필드, 모달 포커스, 메뉴·탭·토스트, 열린 대화
상자 axe, 320px 리플로)은 tests/storybook/galleries.spec.ts로 옮겼다.

위험: 골든의 픽셀 색 허용치(threshold 0.2)는 그대로다. 미세한 토큰
변화는 옛 골든처럼 새 골든도 잡지 못한다.

검증(desktop): test:storybook 6 passed, test:visual 7 passed,
playwright-run-isolation 단위 시험 통과. 변이 확인: --color-action을
파랑→빨강으로 바꾸면 새 골든이 어두운 쪽 42,313px, 밝은 쪽 22,359px
차이로 실패했다. 옛 골든(main f33e4778)도 40,238px, 22,511px로 실패했다.
미세 변이(어두운 --color-danger red-500→600, 밝은 --color-danger-surface
색상각 25→145)는 옛·새 골든 모두 통과했다. 변이는 되돌렸다.
2026-11-08 13:51:54 +09:00

96 lines
3.5 KiB
TypeScript

import { fileURLToPath } from "node:url";
import { defineConfig, devices } from "@playwright/test";
import { LOCAL_BUILD_IDENTITY } from "./scripts/lib/build-environment.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";
// 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,
snapshotDir: "./tests/visual/__snapshots__",
outputDir: testRunPath("artifacts/tests/visual/results"),
reporter: [
["list"],
[
"html",
{ outputFolder: testRunPath("artifacts/tests/visual/report"), open: "never" },
],
["junit", { outputFile: testRunPath("artifacts/tests/visual/results.xml") }],
],
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() },
command:
`corepack pnpm build && corepack pnpm preview --host 127.0.0.1 --port ${port} --strictPort --outDir ${dist}`,
url: origin,
reuseExistingServer: false,
},
{
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"] },
],
});