// The runtime runs from a layout unlike the repo's: scripts/serve.mjs's test-only alias // serves dist/runtime/ at /__nib/0.0.0/ and dist/runtime/sw.js at /nib-sw.js. boot() must // reach every runtime file (kernel.js, runtime.js, swc.wasm) there and none under /dist/. import { test, expect, type Page } from "@playwright/test"; const RELOCATED = "/__nib/0.0.0/"; /** Record the path of every request the page, its workers and its SW make. */ function recordPaths(page: Page): string[] { const paths: string[] = []; page.context().on("request", (req) => { paths.push(new URL(req.url()).pathname); }); return paths; } async function bootRelocated(page: Page, fixture: string): Promise { await page.goto(fixture); await expect(page.frameLocator("#app").locator("#hi")).toHaveText("Hello from Express", { timeout: 20_000 }); await expect(page.locator("#out")).toHaveText("hello relocated\n"); await expect(page.locator("#err")).toHaveText(""); expect(await page.evaluate(() => new URL(navigator.serviceWorker.controller!.scriptURL).pathname)).toBe("/nib-sw.js"); } test("boot() with base from host.js's own URL loads nothing from /dist/", async ({ page }) => { const paths = recordPaths(page); await bootRelocated(page, "/tests/fixtures/relocated/index.html"); for (const file of ["host.js", "kernel.js", "runtime.js", "swc.wasm"]) expect(paths).toContain(RELOCATED + file); // The snapshot is the embedder's content, not a runtime file. expect(paths.filter((p) => p.startsWith("/dist/"))).toEqual(["/dist/fixtures/express.snap"]); }); test("an explicit base steers kernel, runtime and swc.wasm away from host.js's directory", async ({ page }) => { const paths = recordPaths(page); await bootRelocated(page, "/tests/fixtures/relocated/explicit-base.html"); for (const file of ["kernel.js", "runtime.js", "swc.wasm"]) expect(paths).toContain(RELOCATED + file); expect(paths.filter((p) => p.startsWith("/dist/"))).toEqual(["/dist/runtime/host.js", "/dist/fixtures/express.snap"]); });