scroll-restoration, production-csp, old-tab-chunk-recovery, boot-module-failure는 템플릿처럼 page.goto 뒤 첫 expect(5초) 안에 첫 화면이 그려지기를 기다린다. desktop 호스트의 WebKit은 화면 하나를 여는 데 혼자 돌 때도 3.8~4.6초가 걸린다(Case 화면, Chromium 0.93초). 그래서 다른 worker와 함께 돌면 5초를 넘겨 「불러오는 중」에서 떨어진다. 전체 test:e2e와 3회 반복에서 webkit만 이렇게 떨어졌다. 이 제품의 다른 브라우저 시험처럼 앱이 그려진 것(.site-frame, 부팅 실패면 alert)을 먼저 기다린다. scroll-restoration은 gotoTechLog로 연다. 시험하는 것(스크롤 위치, CSP, 다시 불러오기 횟수, 실패 화면 내용)은 그대로다. 부팅 실패 청크 수정 전후 WebKit 시간이 같아서(JS 14개일 때 3.8~4.6초, 36개일 때 3.8~4.1초) 청크 수가 원인은 아니다. 검증: 네 시험과 app-shell을 chromium·firefox·webkit에서 --repeat-each=3으로 81건 모두 통과.
138 lines
5.2 KiB
TypeScript
138 lines
5.2 KiB
TypeScript
import { appendFile, readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
|
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
|
import {
|
|
prepareFixtureBuilds,
|
|
removeFixtureBuilds,
|
|
type FixtureBuilds,
|
|
} from "./support/fixture-builds.ts";
|
|
import { startBuildServer } from "./support/service-worker-builds.ts";
|
|
|
|
/**
|
|
* 11-05. A tab opened on build A, in the default configuration (no Service
|
|
* Worker), after build B is deployed. B changes two lazy route pages, so their
|
|
* A chunks no longer exist on the server. The first missing chunk reloads the
|
|
* tab once, into B. A second missing chunk (the server alternates back to A,
|
|
* as mismatched replicas do) must not reload again: the tab shows the
|
|
* recovery failure instead.
|
|
*/
|
|
|
|
// Template sync (af3d8e6). Upstream uses two of its example pages, which this
|
|
// product deleted; two TechLog primary-navigation pages play the same part.
|
|
// Not Explore: the home page preloads the Explore (and Profile) chunk, so a
|
|
// tab on A already holds it and never asks the server for it again.
|
|
const PLATFORM = ROUTE_REGISTRY.TECH_LOG_PROJECTS;
|
|
const UI = ROUTE_REGISTRY.TECH_LOG_TOPICS;
|
|
const PAGES = [
|
|
"src/features/tech-log/presentation/public/pages/projects-page.tsx",
|
|
"src/features/tech-log/presentation/public/pages/topics-page.tsx",
|
|
] as const;
|
|
|
|
let builds: FixtureBuilds<"a" | "b"> | undefined;
|
|
|
|
test.beforeAll(async () => {
|
|
test.setTimeout(300_000);
|
|
builds = await prepareFixtureBuilds("chunk-recovery", [
|
|
{ name: "a" },
|
|
{
|
|
name: "b",
|
|
edit: async (root) => {
|
|
for (const page of PAGES) {
|
|
await appendFile(
|
|
path.join(root, page),
|
|
'\n(globalThis as Record<string, unknown>).__caFixtureBuild = "b";\n',
|
|
);
|
|
}
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
test.afterAll(async () => {
|
|
await removeFixtureBuilds(builds);
|
|
});
|
|
|
|
async function routeChunk(dist: string, chunkId: string): Promise<string> {
|
|
const manifest = JSON.parse(
|
|
await readFile(path.join(dist, "release-manifest.json"), "utf8"),
|
|
) as { routeChunks: Record<string, string> };
|
|
return `/${manifest.routeChunks[chunkId]}`;
|
|
}
|
|
|
|
// Each missing page chunk fails its request and the dynamic import. Chromium
|
|
// may also log the 404 itself (without its URL), Firefox logs the error
|
|
// object React caught, and WebKit logs its own import error without the URL.
|
|
// Nothing else is allowed.
|
|
const MISSING_PAGE = String.raw`/assets/route-tech-log-(?:projects|topics)-[\w-]+\.js`;
|
|
test.use({
|
|
allowedBrowserFailure: new RegExp(
|
|
[
|
|
String.raw`^requestfailed:GET:${MISSING_PAGE}:`,
|
|
String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${MISSING_PAGE}$`,
|
|
String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${MISSING_PAGE}” was blocked`,
|
|
String.raw`^console:error:Failed to load resource: the server responded with a status of 404 \(Not Found\)$`,
|
|
String.raw`^console:error:JSHandle@object$`,
|
|
String.raw`^console:error:TypeError: Importing a module script failed\.$`,
|
|
].join("|"),
|
|
"u",
|
|
),
|
|
});
|
|
|
|
test("an old tab reloads once into the new build, then stops reloading", async ({
|
|
page,
|
|
}) => {
|
|
if (!builds) throw new Error("Fixture builds were not prepared.");
|
|
const aPlatform = await routeChunk(builds.dist.a, PLATFORM.chunkId);
|
|
const bPlatform = await routeChunk(builds.dist.b, PLATFORM.chunkId);
|
|
const bUi = await routeChunk(builds.dist.b, UI.chunkId);
|
|
expect(bPlatform).not.toBe(aPlatform);
|
|
expect(bUi).not.toBe(await routeChunk(builds.dist.a, UI.chunkId));
|
|
|
|
const server = await startBuildServer(builds.dist);
|
|
try {
|
|
await page.goto(`${server.origin}/`);
|
|
// The app draws after the document loads; see scroll-restoration.spec.ts.
|
|
await page.locator(".site-frame").waitFor();
|
|
await expect(
|
|
page.getByRole("link", { name: PLATFORM.navigationLabel!, exact: true }),
|
|
).toBeVisible();
|
|
let loads = 0;
|
|
page.on("load", () => {
|
|
loads += 1;
|
|
});
|
|
|
|
// Build B is deployed while the A tab stays open.
|
|
server.serve("b");
|
|
await page
|
|
.getByRole("link", { name: PLATFORM.navigationLabel!, exact: true })
|
|
.click();
|
|
|
|
// The page's h1: the home page the tab is still on has an h2 「프로젝트」
|
|
// of its own, which matched before the reload had happened.
|
|
await expect(
|
|
page.getByRole("heading", { level: 1, name: PLATFORM.title }),
|
|
).toBeVisible();
|
|
expect(loads).toBe(1);
|
|
const served = server.served.map((entry) => entry.path);
|
|
expect(served).not.toContain(aPlatform);
|
|
expect(served).toContain(bPlatform);
|
|
await expect
|
|
.poll(() => page.evaluate(() => (globalThis as Record<string, unknown>).__caFixtureBuild))
|
|
.toBe("b");
|
|
|
|
// The replicas alternate: the B tab now meets A, which lacks B's chunk.
|
|
server.serve("a");
|
|
await page.getByRole("link", { name: UI.navigationLabel!, exact: true }).click();
|
|
|
|
await expect(page.getByRole("alert")).toContainText(
|
|
"화면 자산을 복구하지 못했습니다.",
|
|
);
|
|
expect(loads).toBe(1);
|
|
expect(page.url()).toBe(`${server.origin}${UI.path}`);
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|