Files
clean-architecture-frontend…/tests/unit/playwright-run-isolation.test.ts
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

132 lines
5.3 KiB
TypeScript

import { readFileSync } from "node:fs";
import { afterEach, describe, expect, it } from "vitest";
import {
configRuns,
describeResultFolders,
describeServerPorts,
itExitsWhenItsPortIsTaken,
itKeepsTheViteCacheInTheRun,
hold,
releaseRuns,
webServer,
webServers,
} from "../helpers/playwright-run-isolation.ts";
/**
* 1105/12-04. Every Playwright config wrote its results, report and JUnit
* file, and the e2e and visual builds wrote `dist`, at fixed paths. A second
* run in one checkout deleted the first one's results (Playwright empties
* `outputDir` at start) and emptied the `dist` its preview was serving. Under
* TEST_RUN_ID each run gets its own paths; without it the paths stay where
* FE-GATE-008 and the CI upload read them.
*
* The servers listened on fixed ports (e2e 4173, visual and capabilities both
* 4174, storybook 6006, dev 5173), so the second run failed with "is already
* used", and the dev config reused whatever answered on 5173. Each now picks
* a free port, which the runner's environment hands to the workers.
*
* Each load evaluates the config again with the environment of one process.
*
* 1106/10-01. The capabilities config is checked in
* tests/unit/playwright-capabilities-run-isolation.test.ts: it goes with the
* browser file/storage runtime, and test:browser-file-storage-removal deletes
* the config and that file by name. This file has the four configs every
* project has.
*/
const runs = configRuns({
e2e: () => import("../../playwright.config.ts"),
visual: () => import("../../playwright.visual.config.ts"),
storybook: () => import("../../playwright.storybook.config.ts"),
dev: () => import("../../playwright.dev.config.ts"),
});
afterEach(releaseRuns);
describeResultFolders(runs, [
["e2e", "e2e"],
["visual", "visual"],
["storybook", "storybook"],
]);
describe("the build a run serves", () => {
it.each(["e2e", "visual"] as const)(
"is the checkout's dist without a run ID, and the run's own with one (%s)",
async (name) => {
const checkout = webServer(await runs.load(name));
expect(checkout.env?.["RUN_OUTPUT_ROOT"]).toBe(".");
expect(checkout.command).toMatch(/ --outDir dist(?: |$)/u);
const run = webServer(await runs.load(name, { TEST_RUN_ID: "a" }));
// The build writes under RUN_OUTPUT_ROOT and the preview serves it.
expect(run.env?.["RUN_OUTPUT_ROOT"]).toBe(".tmp/runs/a");
expect(run.command).toMatch(/^corepack pnpm build && corepack pnpm preview /u);
expect(run.command).toMatch(/ --outDir \.tmp\/runs\/a\/dist(?: |$)/u);
},
);
itKeepsTheViteCacheInTheRun(runs, ["dev"]);
it("builds the workshop into the run's folder the way build:storybook does", async () => {
const checkout = webServer(await runs.load("storybook")).command;
expect(checkout).toMatch(
/^corepack pnpm build:storybook && node scripts\/serve-static\.ts artifacts\/storybook\/static /u,
);
const run = webServer(await runs.load("storybook", { TEST_RUN_ID: "a" })).command;
const script = (
JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> }
).scripts["build:storybook"]!;
const sameStepsOtherFolder = script
.replace("&& storybook build", "&& corepack pnpm exec storybook build")
.replace("-o artifacts/storybook/static", "-o .tmp/runs/a/artifacts/storybook/static");
expect(sameStepsOtherFolder).not.toBe(script);
expect(run.startsWith(`${sameStepsOtherFolder} && `)).toBe(true);
expect(run).toMatch(/ node scripts\/serve-static\.ts \.tmp\/runs\/a\/artifacts\/storybook\/static /u);
});
});
describeServerPorts(runs, ["e2e", "visual", "storybook", "dev"]);
// The gallery goldens open workshop stories: the visual config starts the
// static workshop next to its preview, on a port of its own.
describe("the visual config's workshop server", () => {
const workshop = async (environment: Readonly<Record<string, string>> = {}) => {
const runner = await runs.loadProcess("visual", environment);
const servers = webServers(runner.config);
expect(servers).toHaveLength(2);
return { runner, server: servers[1]! };
};
it("is a free port of its own the runner hands to its workers", async () => {
const { runner, server } = await workshop();
const port = Number(runner.after["TEST_VISUAL_WORKSHOP_PORT"]);
expect(port).toBeGreaterThan(0);
expect(port).not.toBe(Number(runner.after["TEST_VISUAL_PORT"]));
expect(server.url).toBe(`http://127.0.0.1:${port}`);
expect(server.command).toMatch(new RegExp(` ${port}$`, "u"));
expect(server.reuseExistingServer).toBe(false);
});
it("moves for a second run while the first run's server holds its port", async () => {
const first = (await workshop()).server.url;
await hold(Number(new URL(String(first)).port));
expect((await workshop()).server.url).not.toBe(first);
});
it("serves the build the workshop config serves, in the run's folder", async () => {
const pinned = { TEST_VISUAL_WORKSHOP_PORT: "40124", TEST_STORYBOOK_PORT: "40124" };
for (const environment of [pinned, { ...pinned, TEST_RUN_ID: "a" }]) {
const { server } = await workshop(environment);
expect(server.command).toBe(webServer(await runs.load("storybook", environment)).command);
}
});
});
describe("vite servers", () => {
itExitsWhenItsPortIsTaken(runs, ["e2e", "visual", "dev"]);
});