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