import { expect, test, type Page, } from "../support/browser/strict-browser-test.ts"; import { VISUAL_TEST_FONT_INSTALL_ARGUMENTS } from "../../scripts/lib/visual-test-fonts.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.", // 1103/11-02. The CI browser step installs the same list. `Debian/Ubuntu: sudo ${VISUAL_TEST_FONT_INSTALL_ARGUMENTS}`, "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); });