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
| 1 | import * as Playwright from "@alchemy.run/cloudflare-test-tools/e2e/Playwright"; |
| 2 | import { expect, test } from "@playwright/test"; |
| 3 | |
| 4 | for (const method of Playwright.SERVER_METHODS) { |
| 5 | test.describe(method, () => { |
| 6 | const it = Playwright.make(method); |
| 7 | |
| 8 | it("server-renders the home page markup (RSC -> SSR)", async ({ server }) => { |
| 9 | // Raw fetch, no JS: the worker runs the `rsc` environment and renders |
| 10 | // HTML through the `ssr` environment — the server-component copy must |
| 11 | // already be in the payload. |
| 12 | const response = await server.fetch("/"); |
| 13 | expect(response.status).toBe(200); |
| 14 | const html = await response.text(); |
| 15 | expect(html).toContain("<h1>Home</h1>"); |
| 16 | expect(html).toContain("rendered as a React Server Component"); |
| 17 | }); |
| 18 | |
| 19 | it("renders the homepage and hydrates client routes", async ({ page, server }) => { |
| 20 | const response = await page.goto(server.url.toString()); |
| 21 | expect(response?.status()).toBe(200); |
| 22 | await page.waitForLoadState("networkidle"); |
| 23 | await page.evaluate(() => document.fonts.ready); |
| 24 | |
| 25 | await expect(page).toHaveScreenshot("index.png", { |
| 26 | animations: "disabled", |
| 27 | maxDiffPixelRatio: 0.03, |
| 28 | }); |
| 29 | |
| 30 | await page.click("a[href='/about']"); |
| 31 | await page.waitForURL("**/about"); |
| 32 | await page.evaluate(() => document.fonts.ready); |
| 33 | |
| 34 | await expect(page).toHaveScreenshot("about.png", { |
| 35 | animations: "disabled", |
| 36 | maxDiffPixelRatio: 0.03, |
| 37 | }); |
| 38 | |
| 39 | expect(await page.textContent("button.counter")).toBe("Count is 0"); |
| 40 | await page.click("button.counter"); |
| 41 | expect(await page.textContent("button.counter")).toBe("Count is 1"); |
| 42 | }); |
| 43 | |
| 44 | it("serves a direct navigation to /about and hydrates the client component", async ({ |
| 45 | page, |
| 46 | server, |
| 47 | }) => { |
| 48 | // Raw fetch: the "use client" about route is still server-rendered |
| 49 | // through the rsc/ssr topology. |
| 50 | const raw = await server.fetch("/about"); |
| 51 | expect(raw.status).toBe(200); |
| 52 | expect(await raw.text()).toContain("rendered as a client component"); |
| 53 | |
| 54 | // Hard browser navigation straight to the route (no client-side |
| 55 | // transition from /) — the client component must hydrate. |
| 56 | const response = await page.goto(new URL("/about", server.url).toString()); |
| 57 | expect(response?.status()).toBe(200); |
| 58 | await expect(page.locator("h1")).toHaveText("About"); |
| 59 | const counter = page.locator("button.counter"); |
| 60 | await expect(counter).toHaveText("Count is 0"); |
| 61 | // A click can land before hydration attaches the handler on a direct |
| 62 | // navigation (observed in dev mode) — retry click-and-observe until |
| 63 | // the component is interactive. |
| 64 | await expect(async () => { |
| 65 | await counter.click(); |
| 66 | await expect(counter).not.toHaveText("Count is 0", { timeout: 250 }); |
| 67 | }).toPass(); |
| 68 | await expect(counter).toHaveText(/Count is [1-9]\d*/); |
| 69 | }); |
| 70 | |
| 71 | it("returns 404 for an unmatched route", async ({ server }) => { |
| 72 | // No catch-all route is configured: react-router's default error |
| 73 | // boundary renders with a 404 status. |
| 74 | const response = await server.fetch("/definitely/not/a/route"); |
| 75 | expect(response.status).toBe(404); |
| 76 | expect(await response.text()).toContain("404 Not Found"); |
| 77 | }); |
| 78 | }); |
| 79 | } |