@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 95 lines 2.84 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as machines from "@distilled.cloud/fly-io/machines";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import * as pathe from "pathe";
9 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
10 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
11
12 const { test } = Test.make({ providers: Fly.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const fixtureDir = pathe.resolve(
17 import.meta.dirname,
18 "../../AWS/Website/fixtures/react-router-app",
19 );
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21 const fixtureEntries = [
22 ".gitignore",
23 "package.json",
24 "react-router.config.ts",
25 "vite.config.ts",
26 "app",
27 "public",
28 ];
29
30 const waitUntilGone = (appName: string) =>
31 machines.getApp({ app_name: appName }).pipe(
32 Effect.as("found" as const),
33 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
34 Effect.repeat({
35 schedule: Schedule.spaced("1 second"),
36 until: (status) => status === "gone",
37 times: 10,
38 }),
39 );
40
41 test.provider(
42 "ReactRouter: deploy, GET /, destroy, gone",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const rootDir = yield* cloneFixture(fixtureDir, {
48 prefix: "alchemy-react-router-fly-",
49 tempRoot,
50 entries: fixtureEntries,
51 });
52
53 const deployed = yield* stack.deploy(
54 Effect.gen(function* () {
55 const site = yield* Fly.Website.ReactRouter("Web", {
56 rootDir,
57 memo: {
58 include: [
59 "app/**",
60 "public/**",
61 "package.json",
62 "react-router.config.ts",
63 "vite.config.ts",
64 ],
65 },
66 });
67 return { site };
68 }),
69 );
70
71 const url = deployed.site.url;
72 expect(url).toBeDefined();
73 expect(url).toMatch(/^https:\/\//);
74 expect(deployed.site.service).toBeDefined();
75 expect(deployed.site.app).toBeDefined();
76
77 yield* expectUrlContains(`${url!}/`, "REACT_ROUTER_AWS_PAGE_MARKER", {
78 timeout: "90 seconds",
79 label: "home page",
80 });
81 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "REACT_ROUTER_AWS_API_MARKER", {
82 timeout: "30 seconds",
83 label: "api route",
84 });
85
86 const appName = deployed.site.app!.appName;
87 yield* stack.destroy();
88 const gone = yield* waitUntilGone(appName);
89 expect(gone).toEqual("gone");
90 }).pipe(logLevel),
91 {
92 tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"],
93 timeout: 180000,
94 },
95 );