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

main
ts 53 lines 2.34 KB
Raw
1 import * as Playwright from "@alchemy.run/cloudflare-test-tools/e2e/Playwright";
2 import { expect, test } from "@playwright/test";
3
4 // Specs written against the INTENDED custom-worker-entry behavior (see
5 // README): the deployed worker is the user's src/worker-entry.ts, which
6 // wraps waku's fetch handler and exports the Counter SQLite DO.
7 for (const mode of Playwright.SERVER_METHODS) {
8 test.describe(mode, () => {
9 const it = Playwright.make(mode);
10
11 it("SSR renders the page through the wrapped waku handler", async ({ page, server }) => {
12 const response = await page.goto(server.url.toString());
13 expect(response?.status()).toBe(200);
14 await expect(page.getByTestId("page-marker")).toHaveText("PAGE_MARKER");
15 await expect(page.getByTestId("env-message")).toHaveText(
16 "MESSAGE=hello-from-waku-do-binding",
17 );
18 // The page reads the DO at request time: any non-negative count proves
19 // the COUNTER namespace resolved against the user entry's Counter class.
20 await expect(page.getByTestId("do-count")).toHaveText(/COUNT=\d+/);
21 });
22
23 it("increments the Counter DO across requests via the API route", async ({ server }) => {
24 // Plain HTTP fetch (not `server.fetch`): the live-mode dispatchFetch
25 // wrapper drops RequestInit, losing the POST method. Both modes listen
26 // on a real socket.
27 const post = async (): Promise<number> => {
28 const response = await fetch(new URL("/counter", server.url), {
29 method: "POST",
30 });
31 expect(response.status).toBe(200);
32 const body = (await response.json()) as { count: number };
33 return body.count;
34 };
35
36 const first = await post();
37 const second = await post();
38 // Relative assertion: DO storage may persist across runs locally.
39 expect(second).toBe(first + 1);
40
41 // GET observes the state written by the POSTs — same DO instance.
42 const read = await fetch(new URL("/counter", server.url));
43 expect(read.status).toBe(200);
44 expect(((await read.json()) as { count: number }).count).toBe(second);
45 });
46
47 it("serves the static asset alongside the custom entry", async ({ server }) => {
48 const response = await server.fetch("/hello.txt");
49 expect(response.status).toBe(200);
50 expect(await response.text()).toContain("hello from public/");
51 });
52 });
53 }