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 homepage markup", async ({ server }) => { |
| 9 | // Raw fetch, no JS: the page content (including the counter's initial |
| 10 | // state) must already be in the server-rendered HTML. |
| 11 | const response = await server.fetch("/"); |
| 12 | expect(response.status).toBe(200); |
| 13 | const html = await response.text(); |
| 14 | expect(html).toContain("Hello world!"); |
| 15 | // The counter's SSR markup — solid's hydration markers split the text |
| 16 | // ("Clicks: <!--...-->0"), so match the label and the button class. |
| 17 | expect(html).toContain("Clicks:"); |
| 18 | expect(html).toContain('class="increment"'); |
| 19 | }); |
| 20 | |
| 21 | it("renders the homepage", async ({ page, server }) => { |
| 22 | const response = await page.goto(server.url.toString()).then(async (response) => { |
| 23 | // solidstart has a bug where the first request is not always successful in dev mode. |
| 24 | // Retry the request if it is not successful as a temporary workaround. |
| 25 | if (response?.ok()) return response; |
| 26 | return page.goto(server.url.toString()); |
| 27 | }); |
| 28 | expect(response?.status()).toBe(200); |
| 29 | await page.waitForLoadState("networkidle"); |
| 30 | await page.evaluate(() => document.fonts.ready); |
| 31 | |
| 32 | await expect(page).toHaveScreenshot("index.png", { |
| 33 | animations: "disabled", |
| 34 | maxDiffPixelRatio: 0.03, |
| 35 | }); |
| 36 | |
| 37 | // Hydration: the SSR'd counter button responds to clicks. |
| 38 | expect(await page.textContent("button.increment")).toBe("Clicks: 0"); |
| 39 | await page.click("button.increment"); |
| 40 | expect(await page.textContent("button.increment")).toBe("Clicks: 1"); |
| 41 | |
| 42 | await page.click("a[href='/about']"); |
| 43 | await page.waitForURL("**/about"); |
| 44 | await page.evaluate(() => document.fonts.ready); |
| 45 | |
| 46 | await expect(page).toHaveScreenshot("about.png", { |
| 47 | animations: "disabled", |
| 48 | maxDiffPixelRatio: 0.03, |
| 49 | }); |
| 50 | }); |
| 51 | |
| 52 | it("serves a direct navigation to /about (SSR)", async ({ page, server }) => { |
| 53 | // Raw fetch: the about markup is server-rendered. |
| 54 | const raw = await server.fetch("/about"); |
| 55 | expect(raw.status).toBe(200); |
| 56 | expect(await raw.text()).toContain(">About</h1>"); |
| 57 | |
| 58 | // Hard browser navigation straight to the route. |
| 59 | const response = await page.goto(new URL("/about", server.url).toString()); |
| 60 | expect(response?.status()).toBe(200); |
| 61 | await expect(page.locator("h1")).toHaveText("About"); |
| 62 | }); |
| 63 | |
| 64 | it("renders the [...404] route for unmatched paths", async ({ page, server }) => { |
| 65 | // The [...404].tsx catch-all renders server-side. NOTE: despite the |
| 66 | // route's <HttpStatusCode code={404} />, SolidStart 2.0.0-alpha.3's |
| 67 | // streaming response commits status 200 in both modes (observed live |
| 68 | // and dev), so this asserts the route's markup, not the status code. |
| 69 | const raw = await server.fetch("/definitely/not/a/route"); |
| 70 | expect(await raw.text()).toContain("Page Not Found"); |
| 71 | |
| 72 | await page.goto(new URL("/definitely/not/a/route", server.url).toString()); |
| 73 | await expect(page.locator("h1")).toHaveText("Page Not Found"); |
| 74 | }); |
| 75 | |
| 76 | it("serves static assets from public/", async ({ server }) => { |
| 77 | const response = await server.fetch("/favicon.ico"); |
| 78 | expect(response.status).toBe(200); |
| 79 | expect(response.headers.get("content-type")).toContain("image"); |
| 80 | }); |
| 81 | |
| 82 | it("runs the API route server-side (GET)", async ({ server }) => { |
| 83 | const body = await server.fetchJson<{ method: string; server: boolean }>("/api/echo"); |
| 84 | expect(body).toMatchObject({ method: "GET", server: true }); |
| 85 | }); |
| 86 | |
| 87 | it("round-trips a POST through the API route", async ({ server }) => { |
| 88 | // Plain HTTP (not `server.fetch`): the live-mode dispatchFetch wrapper |
| 89 | // in the harness drops the RequestInit, losing POST bodies (see the |
| 90 | // same pattern in packages/frontend-frameworks/fixtures/waku/test/smoke.test.ts). Both modes listen |
| 91 | // on a real socket, so this exercises the same worker path. |
| 92 | const response = await fetch(new URL("/api/echo", server.url), { |
| 93 | method: "POST", |
| 94 | headers: { "content-type": "application/json" }, |
| 95 | body: JSON.stringify({ ping: "pong" }), |
| 96 | }); |
| 97 | expect(response.status).toBe(200); |
| 98 | expect(await response.json()).toMatchObject({ |
| 99 | method: "POST", |
| 100 | echoed: { ping: "pong" }, |
| 101 | }); |
| 102 | }); |
| 103 | }); |
| 104 | } |