Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// ServiceWorkerConflictError's fix: a site's worker at scope "/" that importScripts()// the runtime's worker IS the runtime's worker. boot() must recognize it by its answer// to a ping, use it rather than register over it, and leave the site's own listeners// working beside the runtime's.import { test, expect } from "@playwright/test";
test.afterEach(async ({ page }) => { await page.evaluate(async () => { for (const reg of await navigator.serviceWorker.getRegistrations()) await reg.unregister(); }).catch(() => {});});
test("a site worker that composes the runtime's boots, and keeps its own listeners", async ({ page, context }) => { await page.goto("/tests/fixtures/compose/"); const result = page.locator("#result"); await expect(result).not.toHaveText("pending", { timeout: 20_000 }); const text = await result.textContent() ?? ""; expect(text, "boot() threw instead of reporting an outcome").toMatch(/^\{/); const { base, ...outcome } = JSON.parse(text) as Record<string, unknown>; expect(outcome).toEqual({ // Still the site's worker: boot() did not register dist/runtime/sw.js over it. controller: "/tests/fixtures/compose/sw.js", registration: "/tests/fixtures/compose/sw.js", esm: "esm ok from file:///app/main.mjs", esmExit: 0, http: "http ok /ping", // The site's fetch handler still answers what the runtime does not serve, and its // install, activate and message listeners all ran; its top-level names survived. marker: { servedBy: "site", seen: ["install", "activate", "message"] }, });
// A restarted worker holds no bridges and asks this page for one again (rebridge): // that must work through the composed worker too. const cdp = await context.newCDPSession(page); await cdp.send("ServiceWorker.enable"); const stopped = new Promise<void>((resolve) => { cdp.on("ServiceWorker.workerVersionUpdated", ({ versions }) => { if (versions.some((v: { runningStatus: string }) => v.runningStatus === "stopped")) resolve(); }); }); await cdp.send("ServiceWorker.stopAllWorkers"); await stopped; const again = await page.evaluate(async (base) => { const http = await (await fetch(base + "again")).text(); const marker = await (await fetch("/tests/fixtures/compose/marker")).json() as { servedBy: string }; return { http, servedBy: marker.servedBy }; }, String(base)); expect(again).toEqual({ http: "http ok /again", servedBy: "site" });});