test(e2e): Service Worker 갱신 시험을 이 제품의 빌드에 맞춘다

service-worker-update 시험이 두 가지를 템플릿 빌드 기준으로 가정한다.
- 빌드 B에서 바꿀 route 화면으로 src/presentation/pages/not-found-page.tsx를
  연다. 이 제품에는 없는 파일이라 beforeAll이 ENOENT로 떨어지고, 이
  파일의 시험 넷이 전부 돌지 않는다.
- 캐시 목록을 dist/assets/의 모든 파일과 비교한다. 템플릿 빌드는 그
  폴더가 곧 정적 자산 집합이다. 이 제품은 두 방향으로 다르다. IBM Plex
  Mono의 .woff 대체 파일은 캐시 대상 확장자가 아니고(SW-RR-03, .woff2만),
  dist/media/의 SVG는 캐시 대상이다.

바꿀 화면은 같은 방식으로 lazy load되는 TechLog Public not-found 화면이다.
기대하는 캐시 목록은 빌드가 선언한 집합, 즉 생성기의 collectStaticAssets
결과다. route 청크가 사라졌는지 보는 곳은 그대로 dist/assets를 쓴다.

검증: service-worker-update.spec.ts 4개 시험이 chromium·firefox·webkit
모두 통과한다.
This commit is contained in:
DongHyeonka
2026-11-12 15:03:16 +09:00
parent 70f3125c8e
commit a124e11463
+15 -2
View File
@@ -1,6 +1,7 @@
import { appendFile, readdir, readFile } from "node:fs/promises";
import path from "node:path";
import { collectStaticAssets } from "../../scripts/generate-service-worker-assets.ts";
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
import {
prepareServiceWorkerBuilds,
@@ -39,8 +40,10 @@ let builds: ServiceWorkerBuilds | undefined;
// because they embedded the build ID; since 09-02 they do not, so two builds
// of the same source emit the same route chunks. A dynamically imported
// module keeps all its exports, so the extra export survives the bundler.
// Template sync (af3d8e6): upstream's not-found page is TechLog's Public one,
// lazy-loaded like upstream's by `tech-log-route-runtime.tsx`.
const CHANGED_ROUTE_SOURCE =
"src/presentation/pages/not-found-page.tsx";
"src/features/tech-log/presentation/public/pages/public-not-found-page.tsx";
test.beforeAll(async () => {
test.setTimeout(180_000);
@@ -89,6 +92,16 @@ async function hashedAssets(dist: string): Promise<string[]> {
.sort();
}
// Template sync (af3d8e6). Upstream compares the cache with every file under
// assets/, which is its whole static asset set. This product's set differs
// from that folder both ways: IBM Plex Mono's `.woff` fallbacks there are not
// cacheable (SW-RR-03), and `media/` files outside it are. So the expected set
// is the one the build declares, from the generator's own scan.
async function staticAssetSet(dist: string): Promise<string[]> {
const manifest = await collectStaticAssets(dist, "expected", "expected");
return manifest.assets.map((asset) => asset.url).sort();
}
const headerCases = [
{
name: "Content-Type: application/javascript",
@@ -121,7 +134,7 @@ for (const { name, headers } of headerCases) {
return { names, paths };
});
expect(cached.names).toHaveLength(1);
expect(cached.paths.sort()).toEqual(await hashedAssets(dist.a));
expect(cached.paths.sort()).toEqual(await staticAssetSet(dist.a));
// The server really sent the headers under test.
const assets = server.served.filter((response) =>