디자인 시스템 배럴(`src/presentation/design-system/index.ts`)의 값 export 가운데 화면 컴포넌트 37개에 story가 없다: SearchField·ConfirmationDialog· Drawer·Popover·Breadcrumbs·Pagination·LinkButton·Separator·IconButton 같은 primitive, DataTable 등 pattern 다섯, 페이지 템플릿 다섯, 폼 구성요소, 아이콘 아홉. 결과를 모르는 저장(확인·같은 요청 다시 보내기), 충돌, 오래된 데이터, 저장 중은 갤러리와 골든에 없다. 그래서 파생 서비스가 쓸 컴포넌트의 상태를 볼 곳이 없고, 그 배치 회귀를 골든이 잡지 못한다. 고른 방법: - `catalog.stories.tsx`에 묶음 story 열을 더한다(겹치는 화면, 탐색과 입력, 아이콘, 화면 패턴, 페이지 템플릿 다섯을 하나씩, 저장 결과). 템플릿 story는 각자 자기 h1을 그린다. - ScreenStates 갤러리에 저장 상태 절을 더한다: 결과를 모르는 저장(다시 보내기 가능), 충돌, 오래된 데이터, 저장 중, 입력과 무관한 저장 실패 (FormFailureStatus), 입력 오류 요약. `state-surfaces-light` 골든이 이 절을 담는다. - `tests/unit/design-system-story-coverage.test.ts`가 배럴의 값 export마다 story에서 `<Name`으로 그려지는지 대조한다. 그리지 않는 것(Portal·FocusRing· VisuallyHidden, 토큰 상수, hook)은 이유와 함께 목록에 둔다. - 새 story 열은 `tests/storybook/galleries.spec.ts`의 axe 검사(light·dark)에 더했고, 겹치는 화면 셋(확인 대화 상자, 서랍, 팝오버)은 연 상태로도 본다. 대조 시험이 catalog story마다 그 목록에 있는지 본다. - 갤러리에 넣으면서 드러난 둘을 고쳤다. 저장 상태 안내의 문장과 버튼이 붙어 있었다(`.async-surface__status`: 한 줄로 감싸고 간격, 지원 참조는 아랫줄). `FormFailureStatus`가 제목 단계를 받지 못해 카드 안에서 h2로 그려졌다 (`headingLevel`, 추가만, 다른 상태 표면과 같은 08-05 계약). - 버린 대안: 컴포넌트마다 variant 행렬 story를 한 번에 쓰기(이번 범위는 "모든 화면 컴포넌트에 story 하나 이상"이고, 행렬은 컴포넌트를 고칠 때 더한다). StatusPage를 갤러리에 넣기(자기 h1을 그려 갤러리의 h1과 겹친다. 자기 story로 뒀다). 위험·한계: 갤러리 골든이 바뀐다(이 커밋에서 다시 찍는다). theme·locale toolbar는 아직 없다. story axe가 20번 늘어 FE-GATE-008이 조금 길어진다. 검증: 대조 시험(고치기 전 story 파일에서 37개 누락으로 실패), story 빌드 (FE-GATE-011), story axe와 시각 골든(FE-GATE-008)은 desktop에서 돌려 PR 본문에 적는다. Refs: 1112/04-10
80 lines
3.3 KiB
TypeScript
80 lines
3.3 KiB
TypeScript
import { readFile, readdir } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
/**
|
|
* 1112/04-10. A product builds its screens from the design-system barrel.
|
|
* A component without a story has no place where its states can be opened
|
|
* and scanned (tests/storybook/galleries.spec.ts runs axe over the stories),
|
|
* and 43 of the barrel's components had none.
|
|
*/
|
|
const BARREL = "src/presentation/design-system/index.ts";
|
|
|
|
// Exports that draw nothing of their own, with the reason.
|
|
const WITHOUT_STORY = new Map([
|
|
["Portal", "moves its children to another node"],
|
|
["FocusRing", "wraps a child to draw the focus ring the stories already show"],
|
|
["VisuallyHidden", "draws nothing visible"],
|
|
["DESIGN_TOKEN_CONTRACT", "a constant"],
|
|
["REQUIRED_COMPONENT_TOKENS", "a constant"],
|
|
["REQUIRED_PRIMITIVE_TOKENS", "a constant"],
|
|
["REQUIRED_SEMANTIC_TOKENS", "a constant"],
|
|
["useAppForm", "a hook"],
|
|
["useDirtyNavigationGuard", "a hook"],
|
|
["useToast", "a hook"],
|
|
]);
|
|
|
|
async function barrelValueExports(): Promise<string[]> {
|
|
const source = await readFile(BARREL, "utf8");
|
|
return [...source.matchAll(/export\s*\{([^}]*)\}/g)]
|
|
.flatMap((match) => match[1].split(","))
|
|
.map((name) => name.trim())
|
|
.filter((name) => name !== "" && !name.startsWith("type "));
|
|
}
|
|
|
|
async function storySources(): Promise<string> {
|
|
const files = (await readdir("src", { recursive: true }))
|
|
.filter((file) => file.endsWith(".stories.tsx"))
|
|
.map((file) => path.join("src", file));
|
|
expect(files.length).toBeGreaterThan(0);
|
|
const sources = await Promise.all(files.map((file) => readFile(file, "utf8")));
|
|
// A name in a comment or a string is not a drawing of it.
|
|
return sources
|
|
.map((source) =>
|
|
source
|
|
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
.replace(/(^|[^:])\/\/.*$/gm, "$1")
|
|
.replace(/"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'/g, '""'),
|
|
)
|
|
.join("\n");
|
|
}
|
|
|
|
describe("design-system story coverage", () => {
|
|
it("draws every screen component of the barrel in a story", async () => {
|
|
const exports = await barrelValueExports();
|
|
const stories = await storySources();
|
|
expect(exports).toContain("Button");
|
|
|
|
const drawn = (name: string) => new RegExp(`<${name}[\\s/>]`, "u").test(stories);
|
|
expect(exports.filter((name) => !WITHOUT_STORY.has(name) && !drawn(name))).toEqual([]);
|
|
});
|
|
|
|
// tests/storybook/galleries.spec.ts scans each catalog story with axe; a
|
|
// story added to the catalog and not to that list is drawn and not scanned.
|
|
it("scans every catalog story with axe", async () => {
|
|
const catalog = await readFile("src/presentation/design-system/catalog.stories.tsx", "utf8");
|
|
const spec = await readFile("tests/storybook/galleries.spec.ts", "utf8");
|
|
const ids = [...catalog.matchAll(/^export const (\w+): Story/gmu)].map(
|
|
([, name = ""]) => `platform-catalog--${name.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").toLowerCase()}`,
|
|
);
|
|
expect(ids.length).toBeGreaterThan(0);
|
|
expect(ids.filter((id) => !spec.includes(`"${id}"`))).toEqual([]);
|
|
});
|
|
|
|
it("names a reason only for exports the barrel still has", async () => {
|
|
const exports = await barrelValueExports();
|
|
expect([...WITHOUT_STORY.keys()].filter((name) => !exports.includes(name))).toEqual([]);
|
|
});
|
|
});
|