diff --git a/tests/e2e/service-worker-update.spec.ts b/tests/e2e/service-worker-update.spec.ts index b0dab043..6906d97c 100644 --- a/tests/e2e/service-worker-update.spec.ts +++ b/tests/e2e/service-worker-update.spec.ts @@ -21,8 +21,7 @@ import { * copy of the repo, builds it twice (`VITE_BUILD_ID` sw-e2e-a / sw-e2e-b), * and serves either dist from its own port per test. The copy also records * the worker host's `onUpdateWaiting` / `onReloadRequired` callbacks, which - * the app itself does not subscribe to yet. See that file for the build-script - * workaround (product defect found here). + * the app itself does not subscribe to yet. * * The preview server of this suite is not used; each test uses absolute URLs. */ @@ -247,16 +246,11 @@ test("serves A's removed chunk from the previous cache once B controls the page" } }); -// quarantine(owner=frontend-platform, defect=R3-6-service-worker-config-loader, expires=2026-12-31) -// `vite.service-worker.config.ts` loads `.generated/frontend-runtime/*.ts` -// with a runtime `import("./.generated/...")`. Vite's default `bundle` config -// loader executes the config from `node_modules/.vite-temp/`, so the path -// resolves there and the ACTIVE build stops with ERR_MODULE_NOT_FOUND at -// `npx vite build --config vite.service-worker.config.ts`. Remove the fixme -// (and the helper's `configLoaderWorkaround`) once the build script works. -test.fixme("builds the ACTIVE worker with the repo's unmodified build script", async () => { - test.setTimeout(180_000); - await removeServiceWorkerBuilds( - await prepareServiceWorkerBuilds({ configLoaderWorkaround: false }), - ); +// `beforeAll` already ran `scripts/build-frontend.ts` unmodified (default +// `bundle` config loader); this pins that both builds emitted the worker. +test("builds the ACTIVE worker with the repo's unmodified build script", async () => { + const { dist } = requireBuilds(); + for (const root of [dist.a, dist.b]) { + expect(await readdir(root)).toContain("service-worker.js"); + } }); diff --git a/tests/e2e/support/service-worker-builds.ts b/tests/e2e/support/service-worker-builds.ts index be431514..ab591f46 100644 --- a/tests/e2e/support/service-worker-builds.ts +++ b/tests/e2e/support/service-worker-builds.ts @@ -104,17 +104,7 @@ function run(cwd: string, script: string, buildId: string): void { } } -/** - * `configLoaderWorkaround` (default on) works around a product defect found - * by this spec: `vite.service-worker.config.ts` imports its generated inputs - * with a runtime-relative `import("./.generated/...")`, and Vite's default - * `bundle` config loader runs the config from `node_modules/.vite-temp/`, so - * the ACTIVE worker build fails with ERR_MODULE_NOT_FOUND. The copy's - * `build-frontend.ts` is given `--configLoader native` for the worker step. - */ -export async function prepareServiceWorkerBuilds( - { configLoaderWorkaround = true } = {}, -): Promise { +export async function prepareServiceWorkerBuilds(): Promise { const root = await mkdtemp(path.join(tmpdir(), "ca-sw-builds-")); await cp(repoRoot, root, { recursive: true, @@ -127,13 +117,6 @@ export async function prepareServiceWorkerBuilds( "const SERVICE_WORKER: InstalledServiceWorkerSelection | null = null;", ACTIVE_SELECTION, ); - if (configLoaderWorkaround) { - await replaceOnce( - path.join(root, "scripts/build-frontend.ts"), - '"vite.service-worker.config.ts"]', - '"vite.service-worker.config.ts", "--configLoader", "native"]', - ); - } const hostFile = path.join(root, "src/bootstrap/register-service-worker.ts"); await replaceOnce( hostFile, diff --git a/vite.service-worker.config.ts b/vite.service-worker.config.ts index 31b0455d..28eeb96e 100644 --- a/vite.service-worker.config.ts +++ b/vite.service-worker.config.ts @@ -20,9 +20,15 @@ import { resolveServiceWorkerBuildInput } from "./scripts/lib/service-worker-bui const selection = INSTALLED_RUNTIME_CAPABILITIES.serviceWorker; +// Relative to this file: Vite's default `bundle` config loader runs the config +// from `node_modules/.vite-temp/`, so a bare `import("./.generated/...")` would +// resolve there. Every loader keeps `import.meta.url` pointing at this file. async function readGenerated(path: string, exportName: string): Promise { try { - const module = (await import(path)) as Record; + const module = (await import(new URL(path, import.meta.url).href)) as Record< + string, + unknown + >; if (!(exportName in module)) { throw new TypeError(`Generated module does not export ${exportName}.`); }