@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 83 lines 2.54 KB
Raw
1 import { expect } from "bun:test";
2 import * as Prisma from "@alchemy.run/prisma";
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 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
10 providers: Prisma.providers(),
11 state: Alchemy.localState(),
12 profile: process.env.ALCHEMY_PROFILE,
13 });
14
15 const stack = beforeAll(
16 destroy(Stack).pipe(Effect.andThen(deploy(Stack)), Effect.tap(Console.log)),
17 {
18 timeout: 120_000,
19 },
20 );
21 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), { timeout: 120_000 });
22
23 const base = Effect.map(stack, ({ url }) => {
24 if (!url) throw new Error("Expected a deployed website URL");
25 return String(url).replace(/\/+$/, "");
26 });
27
28 test(
29 "serves the rendered home page",
30 Effect.gen(function* () {
31 const url = yield* base;
32 const response = yield* Test.getWhenReady(url);
33 expect(response.status).toBe(200);
34 expect(yield* response.text).toContain("Hello from Astro on Prisma!");
35 }),
36 { timeout: 120_000 },
37 );
38
39 test(
40 "serves a static asset without falling back to HTML",
41 Effect.gen(function* () {
42 const url = yield* base;
43 const response = yield* Test.getWhenReady(`${url}/example.json`);
44 expect(response.status).toBe(200);
45 expect(yield* response.json).toEqual({
46 framework: "Astro",
47 greeting: "Hello from Astro on Prisma!",
48 });
49 }),
50 { timeout: 120_000 },
51 );
52
53 test(
54 "serves a request-dependent endpoint with runtime environment",
55 Effect.gen(function* () {
56 const url = yield* base;
57 for (const name of ["Prisma", "Alchemy"]) {
58 const response = yield* Test.getWhenReady(`${url}/api/hello?name=${name}`);
59 expect(response.status).toBe(200);
60 expect(yield* response.json).toEqual({
61 name,
62 greeting: "Hello from Astro on Prisma!",
63 });
64 }
65 }),
66 { timeout: 120_000 },
67 );
68
69 test(
70 "serves the fully static Astro build and its assets",
71 Effect.gen(function* () {
72 const { staticUrl } = yield* stack;
73 if (!staticUrl) throw new Error("Expected the static Astro URL");
74 const url = String(staticUrl).replace(/\/+$/, "");
75 const response = yield* Test.getWhenReady(url);
76 expect(response.status).toBe(200);
77 expect(yield* response.text).toContain("Static Astro on Prisma");
78 const asset = yield* Test.getWhenReady(`${url}/example.json`);
79 expect(asset.status).toBe(200);
80 expect(yield* asset.json).toHaveProperty("framework", "Astro");
81 }),
82 { timeout: 120_000 },
83 );