import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; /* TechLog 의 배색은 밝은 화면 하나만 상정하고 고른 값이다. 템플릿은 `[data-theme="dark"]` 로 같은 이름의 토큰을 뒤집는데, 그쪽이 더 구체적인 선택자라 TechLog 의 `:root` 를 이긴다. 글자색만 뒤집히고 배경은 원색 그대로 남아 흰 바탕에 흰 글씨가 나온 적이 있다. 그래서 템플릿이 어둡게 덮는 토큰은 TechLog 도 같은 조건에서 되돌려 놓아야 한다. 템플릿이 새 토큰을 어둡게 덮기 시작하면 이 검사가 그 이름을 짚는다 — 손으로 맞춘 목록은 반드시 낡는다. */ const TEMPLATE = "src/presentation/design-system/tokens/semantic.css"; const TECH_LOG = "src/features/tech-log/presentation/styles/tech-log-theme.css"; /** 선택자가 `match` 를 포함하는 블록들이 정의한 커스텀 속성 이름. */ function propertiesUnder(file: string, match: string): ReadonlySet { // 주석을 먼저 지운다. 남겨 두면 블록 앞 주석이 선택자에 붙어, 설명으로 적은 낱말만으로도 // 통과한다 — 이 검사를 처음 세웠을 때 실제로 그렇게 통과했다. const source = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//gu, " "); const names = new Set(); for (const block of source.matchAll(/([^{}]+)\{([^{}]*)\}/gu)) { const [, selector = "", body = ""] = block; if (!selector.includes(match)) continue; for (const declaration of body.matchAll(/(--[\w-]+)\s*:/gu)) names.add(declaration[1]!); } return names; } describe("TechLog 배색은 다크에서도 한 벌이다", () => { it("템플릿이 어둡게 덮는 토큰을 TechLog 가 같은 조건에서 되돌린다", () => { const darkened = propertiesUnder(TEMPLATE, '[data-theme="dark"]'); const restored = propertiesUnder(TECH_LOG, '[data-theme="dark"]'); expect(darkened.size).toBeGreaterThan(0); expect([...darkened].filter((name) => !restored.has(name))).toEqual([]); }); });