diff --git a/docs/testing/frontend-platform-testing-strategy.md b/docs/testing/frontend-platform-testing-strategy.md index f9cd37f4..cf00ec96 100644 --- a/docs/testing/frontend-platform-testing-strategy.md +++ b/docs/testing/frontend-platform-testing-strategy.md @@ -941,7 +941,10 @@ Playwright `toHaveScreenshot()`을 사용한다. - clock/random/network fixture 고정 - 개인정보와 동적 ID mask - update snapshot은 전용 명령과 reviewer 승인을 요구 -- threshold를 높여 실제 차이를 숨기지 않는다. +- threshold를 높여 실제 차이를 숨기지 않는다. 허용치는 이미지 비율이 아니라 + 절대 픽셀 수(`maxDiffPixels: 50`)다. 비율은 긴 화면일수록 커져서 0.2%가 + 넓은 셸에서 2,592 px를 허용했고, 1,146 px짜리 UI-04 회귀를 통과시켰다 + (11-03). 글꼴을 고정한 같은 호스트에서는 다시 빌드해도 0 px 차이였다. Chromatic 같은 cloud visual service는 선택이다. 저장소 내부 Playwright baseline은 외부 서비스 없이도 실행 가능해야 한다. diff --git a/playwright.visual.config.ts b/playwright.visual.config.ts index 4fe52334..103bf402 100644 --- a/playwright.visual.config.ts +++ b/playwright.visual.config.ts @@ -19,7 +19,11 @@ export default defineConfig({ toHaveScreenshot: { animations: "disabled", caret: "hide", - maxDiffPixelRatio: 0.002, + // 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", }, }, diff --git a/tests/unit/visual-regression-tolerance.test.ts b/tests/unit/visual-regression-tolerance.test.ts new file mode 100644 index 00000000..ddd5ef8b --- /dev/null +++ b/tests/unit/visual-regression-tolerance.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vitest"; + +import visualConfig from "../../playwright.visual.config.ts"; + +// 11-03. Measured on this template's goldens: undoing the UI-04 fix changed +// 1,146 px of the wide shell, and the compact golden drifted 175 px from the +// code without failing. A 0.2% share of the image allowed 2,592 px on the +// wide shell, 985 px on the compact shell and 7,781 px on the platform +// overview, so the allowance grew with the page instead of covering only +// rasterization noise (VD-08 item 8). +const SMALLEST_MEASURED_REGRESSION_PX = 175; + +describe("visual regression tolerance", () => { + const screenshot = visualConfig.expect?.toHaveScreenshot; + + it("does not scale with the image size", () => { + expect(screenshot?.maxDiffPixelRatio).toBeUndefined(); + }); + + it("stays below the smallest real change measured", () => { + expect(screenshot?.maxDiffPixels).toBeGreaterThanOrEqual(0); + expect(screenshot?.maxDiffPixels).toBeLessThan( + SMALLEST_MEASURED_REGRESSION_PX, + ); + }); +});