import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { test } from "vitest"; /** * 한 화면에 나란히 서는 구역 제목은 같은 급이어야 한다. * *
정본은 `.section-heading-row h2` 다. 그 안에 들어가지 않는 두 구역이 크기만 각자 적어 두어 * 굵기를 아무도 정하지 않았고, 400 으로 떨어져 「구조별로 알게 된 것」만 형제 구역보다 작고 * 가늘게 나왔다 — 규칙이 없는 게 아니라 절반만 있었고, 그래서 「디자인이 안 됐다」로 보였다. */ const RAW = readFileSync("src/features/tech-log/presentation/styles/globals.css", "utf8"); /** * 좁은 화면용 값은 뺀다. 화면 폭마다 급이 달라지는 것은 의도이고, 여기서 보려는 것은 같은 * 폭에서 나란히 설 때의 급이다. */ const CSS = RAW.replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/gu, ""); /** 나란히 서는 구역 제목들. 정본이 맨 앞이다. */ const SECTION_HEADINGS = [ ".section-heading-row h2", ".document-relations h2", ".topic-variants h2", ] as const; /** 마지막으로 선언된 값을 읽는다 — 뒤에 오는 규칙이 이긴다. */ function declared(selector: string, property: string): string | null { const escaped = selector.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); const blocks = [ ...CSS.matchAll(new RegExp(`(?:^|,|\\n)\\s*${escaped}\\s*(?:,[^{]*)?\\{([^}]*)\\}`, "gu")), ]; let value: string | null = null; for (const block of blocks) { const found = new RegExp(`${property}:\\s*([^;]+)`, "u").exec(block[1]!); if (found) value = found[1]!.trim(); } return value; } test("나란히 서는 구역 제목이 같은 크기와 굵기를 쓴다", () => { const canonical = SECTION_HEADINGS[0]; for (const property of ["font-size", "font-weight"]) { const want = declared(canonical, property); assert.ok(want, `${canonical} 에 ${property} 가 없다 — 정본이 값을 갖고 있어야 한다`); for (const selector of SECTION_HEADINGS.slice(1)) { assert.equal( declared(selector, property), want, `${selector} 의 ${property} 가 ${canonical} 과 다르다`, ); } } });