@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 97 lines 4.51 KB
Raw
1 import { readFile } from "node:fs/promises";
2 import * as Playwright from "@alchemy.run/cloudflare-test-tools/e2e/Playwright";
3 import { expect, test } from "@playwright/test";
4
5 // The static-output path: a pure `output: "static"` Astro site deploys
6 // ASSETS-ONLY (no worker, `BuildOutput.serverModules` undefined/empty).
7 //
8 // The live-only assertions live INSIDE the loop's `live` describe (not a
9 // separate describe block): each describe can land on its own Playwright
10 // worker, and the worker-scoped `server` fixture builds when
11 // `dist/build.json` is missing — two describes owning `live` servers means
12 // two workers racing the same astro build in the same dist/ on a fresh
13 // checkout (astro's prerender cleanup in one build deletes chunks the
14 // other's manifest injection still reads).
15 for (const mode of Playwright.SERVER_METHODS) {
16 test.describe(mode, () => {
17 const it = Playwright.make(mode);
18
19 it("serves the prerendered home page", async ({ page, server }) => {
20 const response = await page.goto(server.url.toString());
21 expect(response?.status()).toBe(200);
22 await expect(page.locator("#title")).toHaveText("Astro Static Fixture");
23 await expect(page.locator("#mode")).toHaveText("static");
24 });
25
26 it("navigates the whole site through the nav (sitemap-ish)", async ({ page, server }) => {
27 await page.goto(server.url.toString());
28 await page.locator("#nav-about").click();
29 await expect(page.locator("#title")).toHaveText("About");
30 await page.locator("#nav-blog").click();
31 await expect(page.locator("#title")).toHaveText("Blog");
32 await expect(page.locator("#post-list li")).toHaveCount(2);
33 await page.locator("#nav-first-post").click();
34 await expect(page.locator("#slug")).toHaveText("first-post");
35 await page.locator("#nav-second-post").click();
36 await expect(page.locator("#slug")).toHaveText("second-post");
37 await page.locator("#nav-home").click();
38 await expect(page.locator("#title")).toHaveText("Astro Static Fixture");
39 });
40
41 it("serves getStaticPaths-enumerated routes", async ({ server }) => {
42 const first = await server.fetch("/blog/first-post/");
43 expect(first.status).toBe(200);
44 expect(await first.text()).toContain("First post");
45
46 const second = await server.fetch("/blog/second-post/");
47 expect(second.status).toBe(200);
48 expect(await second.text()).toContain("Second post");
49 });
50
51 it("hydrates the client-side island", async ({ page, server }) => {
52 await page.goto(new URL("/counter/", server.url).toString());
53 // The prerendered HTML says "no"; the bundled client script flips it.
54 await expect(page.locator("#hydrated")).toHaveText("yes");
55 await expect(page.locator("#count")).toHaveText("0");
56 await page.locator("#increment").click();
57 await page.locator("#increment").click();
58 await expect(page.locator("#count")).toHaveText("2");
59 });
60
61 it("serves public assets", async ({ server }) => {
62 const response = await server.fetch("/robots.txt");
63 expect(response.status).toBe(200);
64 expect(await response.text()).toContain("User-agent");
65 });
66
67 it("returns the custom 404 page for unmatched routes", async ({ server }) => {
68 const response = await server.fetch("/definitely-not-a-route");
69 expect(response.status).toBe(404);
70 expect(await response.text()).toContain("Page not found");
71 });
72
73 // Live-only assertions: the production artifact itself.
74 if (mode === "live") {
75 it("serves build-frozen HTML (no per-request rendering)", async ({ server }) => {
76 // `#built-at` is stamped at BUILD time; two requests must be
77 // byte-identical. (Dev renders on demand by design, so live-only.)
78 const first = await (await server.fetch("/")).text();
79 const second = await (await server.fetch("/")).text();
80 expect(first).toBe(second);
81 expect(first).toContain('id="built-at"');
82 });
83
84 // THE POINT of this fixture: a fully-static build must be assets-only.
85 it("build output contains NO server modules (assets-only)", async ({ server }) => {
86 // The harness builds before serving live mode, so dist/build.json
87 // exists once the worker-scoped server fixture is up.
88 void server;
89 const raw = await readFile(new URL("../dist/build.json", import.meta.url), "utf8");
90 const build = JSON.parse(raw) as {
91 serverModules?: Array<{ name: string }> | undefined;
92 };
93 expect(build.serverModules ?? []).toEqual([]);
94 });
95 }
96 });
97 }