@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 100 lines 3.35 KB
Raw
1 import { expect } from "bun:test";
2 import * as Cloudflare from "@alchemy.run/cloudflare";
3 import * as Test from "@alchemy.run/test/Bun";
4 import * as Console from "effect/Console";
5 import * as Effect from "effect/Effect";
6 import Stack from "../alchemy.run.ts";
7
8 // Fresh `workers.dev` URLs transiently 404 while the route propagates.
9 // `Test.getWhenReady` fails on that cold-start window and retries until the
10 // worker serves a real response.
11 const { getWhenReady } = Test;
12
13 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
14 providers: Cloudflare.providers(),
15 state: Cloudflare.state(),
16 });
17
18 // The first deploy runs the full Waku build, so give the hook more headroom
19 // than the default 120s.
20 const stack = beforeAll(deploy(Stack).pipe(Effect.tap(Console.log)), {
21 timeout: 600_000,
22 });
23 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
24
25 const base = Effect.map(stack, ({ url }) => {
26 if (!url) throw new Error("expected the site to expose a workers.dev url");
27 return url.replace(/\/+$/, "");
28 });
29
30 test(
31 "deploys and exposes a url",
32 Effect.gen(function* () {
33 const { url } = yield* stack;
34 expect(url).toBeString();
35 }),
36 { timeout: 180_000 },
37 );
38
39 test(
40 "serves the server-rendered home page",
41 Effect.gen(function* () {
42 const url = yield* base;
43 const res = yield* getWhenReady(url);
44 expect(res.status).toBe(200);
45 const html = yield* res.text;
46 // The `GREETING` env value from alchemy.run.ts, read via `getEnv` in the
47 // dynamic RSC page — proves the Worker rendered it at request time.
48 expect(html).toContain("Hello from Waku on Cloudflare!");
49 expect(html).toContain("This page is rendered by the Worker on every request.");
50 }),
51 { timeout: 180_000 },
52 );
53
54 test(
55 "compiles tailwind from waku.config.ts",
56 Effect.gen(function* () {
57 const url = yield* base;
58 const res = yield* getWhenReady(url);
59 expect(res.status).toBe(200);
60 const html = yield* res.text;
61 // The utility class from src/pages/index.tsx made it into the markup.
62 expect(html).toContain("text-3xl");
63
64 // Locate the emitted stylesheet. Waku links the compiled CSS bundle in
65 // the document head; the @tailwindcss/vite plugin registered via
66 // waku.config.ts's `vite` field is what compiles it.
67 const links = [...html.matchAll(/<link\b[^>]*>/g)]
68 .map((m) => m[0])
69 .filter((tag) => /rel="stylesheet"/.test(tag))
70 .map((tag) => /href="([^"]+)"/.exec(tag)?.[1])
71 .filter((href): href is string => !!href);
72 expect(links.length).toBeGreaterThan(0);
73
74 let compiled = "";
75 for (const href of links) {
76 const cssUrl = href.startsWith("http")
77 ? href
78 : `${url}${href.startsWith("/") ? "" : "/"}${href}`;
79 const cssRes = yield* getWhenReady(cssUrl);
80 expect(cssRes.status).toBe(200);
81 compiled += yield* cssRes.text;
82 }
83 // The compiled rule proves tailwind ran through the plugin from
84 // waku.config.ts — not just that the class name appears in markup.
85 expect(compiled).toContain(".text-3xl");
86 expect(compiled).toContain("font-bold");
87 }),
88 { timeout: 180_000 },
89 );
90
91 test(
92 "serves a static asset from public/",
93 Effect.gen(function* () {
94 const url = yield* base;
95 const res = yield* getWhenReady(`${url}/hello.txt`);
96 expect(res.status).toBe(200);
97 expect(yield* res.text).toContain("hello from public/");
98 }),
99 { timeout: 180_000 },
100 );