Files
clean-architecture-frontend…/tests/e2e/support/generated-feature.ts
T
DongHyeonka 794a51a37d test(e2e): 참조 기능 대신 생성 기능을 넣은 빌드로 기능 경로를 확인한다
참조 기능 e2e 3개가 "기능 하나가 실제 브라우저에서 라우트·폼·
저장까지 된다"를 맡는다. 청크 복구, 부트 실패, preload 시험도 설치된
기능에 기댄다.

S4 9.1절 (가)대로 한다. scripts/lib/generated-feature.ts가 저장소
사본에 create:feature order-feature --with-create --keyed를 만들고,
spec은 그 사본의 빌드를 띄워 돈다. 참조 e2e의 검사(로그인, 목록, 폼
검증·이탈 확인·320px, en-US, 저장과 멱등 키, 429 뒤 다시 시도, 결과
불명과 같은 키 재전송, 키보드 포커스, 상태별 axe)를 생성 기능에
옮겼다. 오래된 탭의 청크 복구는 생성 기능 목록 라우트를, 부트 실패는
생성 기능을 넣은 사본을, preload 시험은 생성 기능 실행부 청크를 쓴다.

위험: 생성 기능의 동작만 본다. 제품 기능은 자기 spec이 필요하다.
사본 빌드가 spec과 브라우저마다 돈다(빌드 1초 안팎).

검증(desktop): 샘플을 지운 최종 트리에서 test:e2e 183 passed,
test:a11y 통과.
2026-11-08 14:07:53 +09:00

81 lines
3.5 KiB
TypeScript

import { spawnSync } from "node:child_process";
import path from "node:path";
import { pathToFileURL } from "node:url";
/**
* 2026-11-07. The template ships no feature. The browser checks that one
* feature works end to end (its route, form and save, a save whose result is
* lost) run on the feature `create:feature` writes: a fixture build
* (fixture-builds.ts) gets it with `addGeneratedFeature` as its edit, so a
* change of the generator's output fails here. The `--keyed` write slice is
* the widest one the command makes.
*/
export const GENERATED_FEATURE_ID = "order-feature";
export type GeneratedRoute = Readonly<{
routeId: string;
path: string;
chunkId: string;
/** The lazy page's module id (`routeRuntimeContracts`), the name of its chunk. */
moduleId: string;
}>;
export type GeneratedFeature = Readonly<{
list: GeneratedRoute;
detail: GeneratedRoute;
create: GeneratedRoute;
/** The feature's ko-KR and en-US catalogs. */
messages: Readonly<Record<"ko-KR" | "en-US", Readonly<Record<string, string>>>>;
/** The collection the operations call: API_BASE_URL of the build plus the path. */
api: string;
}>;
function node(root: string, args: readonly string[]): string {
const result = spawnSync(process.execPath, args, { cwd: root, encoding: "utf8" });
if (result.status !== 0) {
throw new Error(`node ${args.join(" ")} failed in ${root}:\n${result.stdout}\n${result.stderr}`);
}
return result.stdout;
}
/** The edit of a fixture build: `corepack pnpm create:feature order-feature --with-create --keyed`. */
export async function addGeneratedFeature(root: string): Promise<void> {
node(root, ["scripts/generate-product-feature-index.ts"]);
node(root, ["scripts/create-feature.ts", GENERATED_FEATURE_ID, "--with-create", "--keyed"]);
}
/**
* What the specs need to drive the feature, read from the copy the command
* wrote it into (node runs that TypeScript as it is): the three routes, the
* words and where its API is.
*/
export function generatedFeature(root: string): GeneratedFeature {
const feature = path.join(root, "src/features", GENERATED_FEATURE_ID);
const module = (file: string) => JSON.stringify(pathToFileURL(path.join(feature, file)).href);
const source = `
const { ORDER_FEATURE_CONTRACT } = await import(${module("contracts/order-feature-contract.ts")});
const { ORDER_MESSAGE_CATALOGS } = await import(${module("contracts/order-message-catalog.ts")});
const { ORDER_LIST_ITEMS_CONTRACT } = await import(${module("contracts/order-contract-contribution.ts")});
const { API_BASE_URL } = JSON.parse(await (await import("node:fs/promises")).readFile("config/runtime/local.json", "utf8"));
const route = (id) => ({
routeId: id,
path: ORDER_FEATURE_CONTRACT.routes[id].path,
chunkId: ORDER_FEATURE_CONTRACT.routes[id].chunkId,
moduleId: ORDER_FEATURE_CONTRACT.routeRuntimeContracts[id].moduleId,
});
process.stdout.write(JSON.stringify({
list: route("ORDER_LIST"),
detail: route("ORDER_DETAIL"),
create: route("ORDER_CREATE"),
messages: ORDER_MESSAGE_CATALOGS,
api: new URL(ORDER_LIST_ITEMS_CONTRACT.contract.pathTemplate.slice(1), API_BASE_URL).href,
}));
`;
return JSON.parse(node(root, ["--input-type=module", "-e", source])) as GeneratedFeature;
}
/** A route's path with its one parameter filled in. */
export function routePath(route: GeneratedRoute, id?: string): string {
return id === undefined ? route.path : route.path.replace(/:[A-Za-z][A-Za-z0-9_]*/u, id);
}