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