import { test, expect } from "@playwright/test"; import { resetData } from "./helpers"; // ONE POLLING ROUTE, AND THE OLD PATHS THAT STILL ANSWER. // // Eight route files became `/api/view/[name]` plus a handler table // (app/api/view/views.ts). The eight paths the clients used to call are // REWRITES in next.config.ts — server-internal, so a pinned widget and the // dashboard keep polling exactly what they always polled. // // The rewrite table, the dispatcher's 404s and the presets route are unit // tests now (app/api/view/[name]/route.test.ts), and the ~30 assertions the // rest of the suite makes at the old paths are the remap's runtime regression // test. What stays here is the one thing only a running Next can show: that a // rewrite carries the QUERY STRING, which is the whole of `/api/pulse?rev=`. test.describe("/api/view/[name]", () => { test.beforeEach(async () => { await resetData("channel-with-counts"); }); test("the rev query survives the rewrite", async ({ request }) => { const seed = await (await request.get("/api/view/pulse")).json(); expect(seed.changed).toBe(true); const rev = encodeURIComponent(seed.rev); // Directly: the idle fast path answers `changed: false`. const direct = await (await request.get(`/api/view/pulse?rev=${rev}`)).json(); expect(direct.rev).toBe(seed.rev); expect(direct.changed).toBe(false); // And through the rewrite — which is the assertion that matters, because a // rewrite that dropped the query string would silently turn every idle // poll into a full one (a disk read per client per 5 seconds) while // returning a body that still looks correct. const viaOldPath = await (await request.get(`/api/pulse?rev=${rev}`)).json(); expect(viaOldPath.rev).toBe(seed.rev); expect(viaOldPath.changed).toBe(false); expect(viaOldPath.cleanableBytes).toBe(-1); }); });