참조 기능 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 통과.
90 lines
3.5 KiB
TypeScript
90 lines
3.5 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
|
import {
|
|
editOnce,
|
|
prepareFixtureBuilds,
|
|
removeFixtureBuilds,
|
|
type FixtureBuilds,
|
|
} from "./support/fixture-builds.ts";
|
|
import { addGeneratedFeature } from "./support/generated-feature.ts";
|
|
import { startBuildServer } from "./support/service-worker-builds.ts";
|
|
|
|
/**
|
|
* 09-03 (F-2). A production build whose application graph throws while its
|
|
* modules evaluate: the installed features are composed twice, so
|
|
* `installed-feature-messages.ts` meets every message key a second time and
|
|
* throws at module top level. The static "loading" shell used to stay up
|
|
* forever; the boot error shell has to replace it. The template installs no
|
|
* feature, so the copy gets the one `create:feature` writes first: with none
|
|
* there is no key to meet twice.
|
|
*/
|
|
|
|
let builds: FixtureBuilds<"broken"> | undefined;
|
|
|
|
test.beforeAll(async () => {
|
|
test.setTimeout(300_000);
|
|
builds = await prepareFixtureBuilds("boot-module-failure", [
|
|
{
|
|
name: "broken",
|
|
edit: async (root) => {
|
|
await addGeneratedFeature(root);
|
|
await editOnce(
|
|
path.join(root, "src/features/installed-feature-messages.ts"),
|
|
"composeInstalledMessageCatalogs(\n INSTALLED_PRODUCT_FEATURE_MODULES,\n)",
|
|
"composeInstalledMessageCatalogs([\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n])",
|
|
);
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
test.afterAll(async () => {
|
|
await removeFixtureBuilds(builds);
|
|
});
|
|
|
|
// 1103/11-09. Vite preloads the boot chunk with everything it imports. A
|
|
// module of that graph throws, so the graph stops evaluating and its
|
|
// remaining chunks stay preloaded and unrun: the provoked failure's own
|
|
// effect. Only the boot graph's chunks are allowed.
|
|
test.use({
|
|
allowedBrowserFailure: async ({ browserName: _engine }, provide) => {
|
|
if (!builds) throw new Error("Fixture build was not prepared.");
|
|
const manifest = JSON.parse(
|
|
await readFile(path.join(builds.dist.broken, ".vite/manifest.json"), "utf8"),
|
|
) as Record<string, { file: string; imports?: string[] }>;
|
|
const files = new Set<string>();
|
|
const pending = ["src/bootstrap/boot.tsx"];
|
|
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
const entry = manifest[key];
|
|
if (!entry || files.has(entry.file)) continue;
|
|
files.add(entry.file);
|
|
pending.push(...(entry.imports ?? []));
|
|
}
|
|
if (files.size === 0) throw new Error("The broken build has no boot chunk.");
|
|
const alternatives = [...files].map((file) => file.replaceAll(".", String.raw`\.`));
|
|
await provide(new RegExp(String.raw`^preloadunused:/(?:${alternatives.join("|")})$`, "u"));
|
|
},
|
|
});
|
|
|
|
test("shows the boot error shell when a module throws while it evaluates", async ({
|
|
page,
|
|
}) => {
|
|
if (!builds) throw new Error("Fixture build was not prepared.");
|
|
const broken = builds.dist.broken;
|
|
const server = await startBuildServer({ a: broken, b: broken });
|
|
try {
|
|
await page.goto(`${server.origin}/`);
|
|
|
|
const shell = page.getByRole("alert");
|
|
await expect(shell).toContainText("애플리케이션을 시작할 수 없습니다.");
|
|
await expect(shell).toContainText("BOOT_UNEXPECTED_FAILURE");
|
|
await expect(shell).toContainText("TypeError");
|
|
await expect(shell).toContainText("boot-module-failure-broken");
|
|
await expect(page.locator("[data-boot-shell]")).toHaveCount(0);
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|