// Guest apps use absolute paths (/app.js, /api, /about); the SW attributes those // requests to the guest by the requesting client, not by URL prefix. import { test, expect, type Page } from "@playwright/test"; import { appUrl } from "./http-golden"; async function bootServer(page: Page): Promise { await page.goto("/demo/http.html"); await expect(page.frameLocator("#app").locator("#hi")).toBeVisible({ timeout: 20_000 }); } test("a CSS @import chain from an absolute stylesheet reaches the guest", async ({ page }) => { await bootServer(page); await expect(page.frameLocator("#app").locator("#hi")).toHaveCSS("color", "rgb(1, 2, 3)"); }); test("absolute module imports, fetches and worker scripts reach the guest", async ({ page }) => { await bootServer(page); const app = page.frameLocator("#app"); await expect(app.locator("#js")).toHaveText("from lib.js"); await expect(app.locator("#api")).toHaveText("42"); await expect(app.locator("#worker")).toHaveText("worker:42"); }); test("an absolute link navigates the iframe inside the prefix", async ({ page }) => { await bootServer(page); await page.frameLocator("#app").locator("#about").click(); await expect(page.frameLocator("#app").locator("#about-h")).toHaveText("About"); const frame = page.frame({ url: /\/about$/ }); expect(frame && new URL(frame.url()).pathname).toBe(`${await appUrl(page)}about`); }); // A guest document's location is the frame's virtual URL, so its scripts read // /~/@/http// where the server was asked for /. A client router matches // that path: React Router hydrates the server-rendered home route into its 404, which // is why tests/react-router.spec.ts passes only when it reads #hi before hydration. // VISION D28 fixed it with an origin per guest server (boot's `guests`), which // tests/guest-origin.spec.ts covers here and packages/app's guest-origin.spec.ts covers // in the browser panel. This demo keeps the prefixed scheme, which tier 1 (one origin, // no wildcard DNS) still needs, so on it the limit stays, recorded rather than fixed. test.fixme("a guest document's location is the path its server was asked for", async ({ page }) => { await bootServer(page); const app = page.frameLocator("#app"); expect(await app.locator(":root").evaluate(() => location.pathname)).toBe("/"); await app.locator("#about").click(); await expect(app.locator("#about-h")).toHaveText("About"); expect(await app.locator(":root").evaluate(() => location.pathname)).toBe("/about"); }); test("a form POST to an absolute action keeps its method and body", async ({ page }) => { await bootServer(page); await page.frameLocator("#app").locator("#f button").click(); await expect(page.frameLocator("#app").locator("#submitted")).toHaveText("q=hello"); }); test("the shell page's own absolute requests still hit the static server", async ({ page }) => { await bootServer(page); const statuses = await page.evaluate(async () => [ (await fetch("/style.css")).status, (await fetch("/demo/demo.css")).status, ]); expect(statuses).toEqual([404, 200]); });