import { expect, test } from "@playwright/test"; import { PRODUCTION_PORT } from "../playwright.config"; const SITE = `http://127.0.0.1:${PRODUCTION_PORT}`; test.describe("the production build (CR-014 Step 14.11)", () => { test("loads nothing but its own static files", async ({ page }) => { const origin = new URL(SITE).origin; const requests: string[] = []; page.on("request", (request) => requests.push(request.url())); // Start a company and fly a tutorial run, then reload: everything a first session does. await page.goto(SITE); await page.getByRole("button", { name: "Start your company" }).click(); await page.getByRole("button", { name: "Fly it" }).first().click(); await expect(page.getByText(/in flight/i).first()).toBeVisible(); await page.reload(); await expect(page.getByRole("button", { name: "Fly it" }).first()).toBeVisible(); expect(requests.length).toBeGreaterThan(0); const elsewhere = requests.filter((url) => new URL(url).origin !== origin); expect(elsewhere).toEqual([]); // Every request is for a file the build contains: there is no API. const paths = requests.map((url) => new URL(url).pathname); expect(paths.filter((p) => p.startsWith("/api"))).toEqual([]); // Developer tools and the test hook are not in production. expect(await page.evaluate(() => window.deadhead)).toBeUndefined(); }); });