Files
clean-architecture-frontend…/tests/unit/route-chunks.test.ts
T
DongHyeonka 86b4a328c0 fix(release): route 청크를 청크 이름이 아니라 페이지 소스 파일로 찾는다
문제: build manifest 작성과 release 검사 둘은 route 청크를 Vite manifest
`entry.name === moduleId`로 찾았다. 청크 이름이 선언 없이 계약이 되어,
vite.config.ts가 route 청크에 이름을 붙이면(tech-log 방식) 빌드가 이유 없는
`Missing built route chunk: <routeId>`로 멈췄다.

고친 것: `scripts/lib/build-manifest-outputs.ts`의 `findRouteChunk` 하나가 dynamic
entry 중 소스 파일(manifest 키 또는 `src`) 이름이 route runtime의
`moduleId`인 것을 찾는다. 셋(build manifest, verify-release, local release
evidence)이 그것을 쓴다. 새 파일을 두지 않은 것은 release 후보
archive의 검증기 소스 목록(`config/ci/gates.json` member 집합)을 바꾸지
않기 위해서다. 못 찾으면 규칙("moduleId는 그 라우트가 import하는
페이지 파일 이름")을, 둘이면 두 소스 경로를 적는다.

위험·한계: moduleId가 페이지 파일 이름이라는 규약은 그대로다(생성기와
`route-runtime.tsx`가 이미 그렇게 쓴다).

검증: desktop `node scripts/run-vitest.ts run tests/unit/route-chunks.test.ts`
통과(다른 청크 이름, 없음, 중복, 계약 없음, 세 사용처).

Refs: 0929/13-03
2026-11-13 23:29:12 +09:00

75 lines
3.1 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { findRouteChunk } from "../../scripts/lib/build-manifest-outputs.ts";
// 0929/13-03. The route chunk was found by the chunk's `name`, so naming route
// chunks in vite.config.ts (the way tech-log did) stopped the build with
// `Missing built route chunk: APP_HOME` and no reason. It is found by the
// page's source file now, which is what the route runtime's moduleId names.
describe("route chunk lookup (0929/13-03)", () => {
const manifest = {
"index.html": { file: "assets/index-a.js", isEntry: true },
"src/presentation/pages/home-page.tsx": {
file: "assets/route-home-page-b.js",
name: "route-home-page",
src: "src/presentation/pages/home-page.tsx",
isDynamicEntry: true,
},
"src/features/order-feature/presentation/order-feature-list-page.tsx": {
file: "assets/order-feature-list-page-c.js",
name: "order-feature-list-page",
isDynamicEntry: true,
},
"_home-page-shared.js": { file: "assets/home-page-d.js", name: "home-page" },
};
it("finds the chunk by the page's source file even when the chunk has another name", () => {
expect(findRouteChunk(manifest, "APP_HOME", "home-page")).toEqual({ file: "assets/route-home-page-b.js" });
expect(findRouteChunk(manifest, "ORDER_FEATURE_LIST", "order-feature-list-page")).toEqual({
file: "assets/order-feature-list-page-c.js",
});
});
it("names the reason and the rule when no lazily imported page has that file name", () => {
const lookup = findRouteChunk(manifest, "NOT_FOUND", "not-found-page");
expect(lookup).toEqual({
error:
"Missing built route chunk: NOT_FOUND: no lazily imported module in the Vite manifest has the source " +
"file not-found-page.tsx (or .ts). A route runtime's moduleId must be the file name of the page it imports.",
});
});
it("refuses two lazily imported pages with the same file name", () => {
const lookup = findRouteChunk(
{ ...manifest, "src/other/home-page.tsx": { file: "assets/home-page-e.js", isDynamicEntry: true } },
"APP_HOME",
"home-page",
);
expect(lookup).toEqual({
error:
"Ambiguous built route chunk: APP_HOME: the lazily imported modules " +
"src/presentation/pages/home-page.tsx, src/other/home-page.tsx are all named home-page.",
});
});
it("names a route without a runtime contract", () => {
expect(findRouteChunk(manifest, "GHOST", undefined)).toEqual({
error: "Missing built route chunk: GHOST has no route runtime contract (ROUTE_RUNTIME_CONTRACT)",
});
});
it("is the one lookup the manifest writer and both release checks use", async () => {
for (const file of [
"scripts/generate-build-manifest.ts",
"scripts/verify-release.ts",
"scripts/lib/local-release-evidence.ts",
]) {
const source = await readFile(file, "utf8");
expect(source, file).toContain("findRouteChunk(");
expect(source, file).not.toMatch(/\.name === runtime\?\.moduleId/u);
}
});
});