diff --git a/docs/styling/design-system-platform.md b/docs/styling/design-system-platform.md index 0f25b452..3f091efa 100644 --- a/docs/styling/design-system-platform.md +++ b/docs/styling/design-system-platform.md @@ -635,7 +635,7 @@ Form과 overlay는 다음 story를 추가한다. 필수 안정화: -- 동일한 Linux image, browser version, font +- 동일한 browser version과 글꼴(`tests/visual/fonts.conf`, Linux 전용) - animation과 caret 비활성화 - 시간·랜덤·network 응답 고정 - 동적 ID와 민감 데이터 mask diff --git a/docs/testing/frontend-platform-testing-strategy.md b/docs/testing/frontend-platform-testing-strategy.md index 921906d1..0e53b1df 100644 --- a/docs/testing/frontend-platform-testing-strategy.md +++ b/docs/testing/frontend-platform-testing-strategy.md @@ -933,7 +933,10 @@ Playwright `toHaveScreenshot()`을 사용한다. 결정성 규칙: -- OS, browser, font, device scale을 CI image로 고정 +- browser 버전과 viewport·scale은 `playwright.visual.config.ts`로, 글꼴은 + `tests/visual/fonts.conf`로 고정(Linux 전용). 러너에는 + `fonts-noto-core fonts-noto-cjk fonts-noto-cjk-extra fonts-liberation` + 패키지가 필요하고, 없으면 `visual-fonts` 검사가 설치 명령을 보여 주며 실패한다 - animation/caret 비활성화 - clock/random/network fixture 고정 - 개인정보와 동적 ID mask diff --git a/playwright.visual.config.ts b/playwright.visual.config.ts index 36528303..4fe52334 100644 --- a/playwright.visual.config.ts +++ b/playwright.visual.config.ts @@ -1,3 +1,5 @@ +import { fileURLToPath } from "node:url"; + import { defineConfig, devices } from "@playwright/test"; export default defineConfig({ @@ -27,6 +29,17 @@ export default defineConfig({ 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: { command: @@ -34,5 +47,8 @@ export default defineConfig({ url: "http://127.0.0.1:4174", reuseExistingServer: false, }, - projects: [{ name: "chromium-visual" }], + projects: [ + { name: "visual-fonts", testMatch: /fonts\.setup\.ts$/ }, + { name: "chromium-visual", dependencies: ["visual-fonts"] }, + ], }); diff --git a/tests/visual/fonts.conf b/tests/visual/fonts.conf new file mode 100644 index 00000000..c2f1f11d --- /dev/null +++ b/tests/visual/fonts.conf @@ -0,0 +1,37 @@ + + + + + /usr/share/fonts/truetype/noto + /usr/share/fonts/opentype/noto + /usr/share/fonts/truetype/liberation + /var/cache/fontconfig + fontconfig + + + /etc/fonts/conf.d + + + + true + true + hintslight + false + rgb + lcddefault + + diff --git a/tests/visual/fonts.setup.ts b/tests/visual/fonts.setup.ts new file mode 100644 index 00000000..70775bff --- /dev/null +++ b/tests/visual/fonts.setup.ts @@ -0,0 +1,66 @@ +import { + expect, + test, + type Page, +} from "../support/browser/strict-browser-test.ts"; + +// 11-02. The goldens were captured with these four faces. `fonts.conf` shows +// Chromium only the directories that hold them; this check runs before the +// screenshots so a missing or substituted font fails here with an install +// hint instead of as a whole-page pixel diff. Probes sit in the real page so +// they get its CSS (`--font-sans`) and `lang`, which decide the fallbacks. +const expectedFaces = { + latin: "Noto Sans", + korean: "Noto Sans CJK KR", + "korean-800": "Noto Sans CJK KR Black", + code: "Liberation Mono", +}; + +const installHint = [ + "Visual tests must draw with the fonts the goldens were captured with.", + "Debian/Ubuntu: sudo apt-get install -y fonts-noto-core fonts-noto-cjk fonts-noto-cjk-extra fonts-liberation", + "tests/visual/fonts.conf reads them from the Debian/Ubuntu font directories; other OSes have no Linux goldens.", +].join("\n"); + +async function drawnFaces(page: Page) { + await page.goto("/"); + await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); + await page.evaluate(() => { + const probes = document.createElement("div"); + probes.innerHTML = ` +

Clean Architecture Frontend

+

플랫폼구성화면상태

+

플랫폼구성화면상태

+ const value = 42;`; + document.body.append(probes); + }); + + const cdp = await page.context().newCDPSession(page); + await cdp.send("DOM.enable"); + await cdp.send("CSS.enable"); + const { root } = await cdp.send("DOM.getDocument"); + const drawn: Record = {}; + for (const probe of Object.keys(expectedFaces)) { + const { nodeId } = await cdp.send("DOM.querySelector", { + nodeId: root.nodeId, + selector: `[data-font-probe="${probe}"]`, + }); + const { fonts } = await cdp.send("CSS.getPlatformFontsForNode", { nodeId }); + drawn[probe] = fonts.map((font) => font.familyName).join(" + "); + } + return drawn; +} + +test("visual fonts match the goldens", async ({ page }) => { + let drawn: Record; + try { + drawn = await drawnFaces(page); + } catch (error) { + // With no font at all the renderer crashes, so the page never draws. + throw new Error( + `${installHint}\nThe font probe page did not render: ${String(error)}`, + { cause: error }, + ); + } + expect(drawn, installHint).toEqual(expectedFaces); +});