diff --git a/tests/features/tech-log/route-chunk-names.test.ts b/tests/features/tech-log/route-chunk-names.test.ts new file mode 100644 index 0000000..9a71550 --- /dev/null +++ b/tests/features/tech-log/route-chunk-names.test.ts @@ -0,0 +1,30 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "vitest"; + +import { TECH_LOG_ROUTE_RUNTIME_CONTRACT } from "../../../src/features/tech-log/contracts/tech-log-route-contract.ts"; + +/** + * 라우트마다 자기 chunk 이름이 있어야 한다. + * + *

vite 설정이 화면 파일 → chunk 이름 표를 손으로 들고 있다. 새 화면을 더하고 이 표를 + * 빠뜨리면 번들은 만들어지는데 빌드 매니페스트 단계에서 「Missing built route chunk」로 + * 멈춘다 — 다섯 개의 검사를 다 통과한 뒤 배포 직전에야 드러난다는 뜻이다. + * + *

여기서 미리 대조한다. 손으로 나열한 목록에 새 것을 빠뜨리는 일이 이 저장소에서 반복됐고, + * 이 표도 그중 하나다. + */ +const VITE_CONFIG = readFileSync("vite.config.ts", "utf8"); + +test("모든 라우트 모듈에 chunk 이름이 붙어 있다", () => { + const named = new Set( + [...VITE_CONFIG.matchAll(/"[^"]+":\s*"(route-[a-z0-9-]+)"/gu)].map((match) => match[1]!), + ); + assert.ok(named.size > 0, "vite 설정에서 chunk 이름을 하나도 읽지 못했다 — 표의 모양이 바뀌었다"); + + const missing = Object.values(TECH_LOG_ROUTE_RUNTIME_CONTRACT) + .map((runtime) => runtime.moduleId) + .filter((moduleId) => !named.has(moduleId)); + + assert.deepEqual(missing, [], `chunk 이름이 없는 라우트: ${missing.join(", ")}`); +}); diff --git a/vite.config.ts b/vite.config.ts index e202e45..d5e61da 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -34,6 +34,9 @@ const techLogRouteChunks = Object.freeze({ "/studio/pages/assets-page.tsx": "route-tech-log-studio-assets", "/studio/pages/taxonomy-page.tsx": "route-tech-log-studio-taxonomy", "/studio/pages/project-edit-page.tsx": "route-tech-log-studio-project-edit", + // 이 표를 빠뜨리면 빌드 매니페스트 단계에서 「Missing built route chunk」로 멈춘다. + // `route-chunk-names.test.ts` 가 다섯 검사 안에서 미리 대조한다. + "/studio/pages/topic-edit-page.tsx": "route-tech-log-studio-topic-edit", "/studio/pages/releases-page.tsx": "route-tech-log-studio-releases", "/studio/pages/release-edit-page.tsx": "route-tech-log-studio-release-edit", "/studio/pages/studio-not-found-page.tsx": "route-tech-log-studio-not-found",