@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.8 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(import.meta.dirname, "../../AWS/Website/fixtures/nuxt-app");
17 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
18 const fixtureEntries = [".gitignore", "package.json", "nuxt.config.ts", "app", "server", "public"];
19
20 const waitUntilGone = (appName: string) =>
21 machines.getApp({ app_name: appName }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "Nuxt: deploy, GET /, destroy, gone",
33 (stack) =>
34 Effect.gen(function* () {
35 yield* stack.destroy();
36
37 const rootDir = yield* cloneFixture(fixtureDir, {
38 prefix: "alchemy-nuxt-fly-",
39 tempRoot,
40 entries: fixtureEntries,
41 });
42
43 const deployed = yield* stack.deploy(
44 Effect.gen(function* () {
45 const site = yield* Fly.Website.Nuxt("Web", {
46 rootDir,
47 memo: {
48 include: ["app/**", "server/**", "public/**", "package.json", "nuxt.config.ts"],
49 },
50 });
51 return { site };
52 }),
53 );
54
55 const url = deployed.site.url;
56 expect(url).toBeDefined();
57 expect(url).toMatch(/^https:\/\//);
58 expect(deployed.site.service).toBeDefined();
59 expect(deployed.site.app).toBeDefined();
60
61 yield* expectUrlContains(`${url!}/`, "NUXT_AWS_PAGE_MARKER", {
62 timeout: "90 seconds",
63 label: "home page",
64 });
65 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "NUXT_AWS_API_MARKER", {
66 timeout: "30 seconds",
67 label: "api route",
68 });
69 yield* expectUrlContains(`${url!}/prerendered`, "NUXT_AWS_PRERENDERED_MARKER", {
70 timeout: "30 seconds",
71 label: "extra route",
72 });
73
74 const appName = deployed.site.app!.appName;
75 yield* stack.destroy();
76 const gone = yield* waitUntilGone(appName);
77 expect(gone).toEqual("gone");
78 }).pipe(logLevel),
79 {
80 tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"],
81 timeout: 240000,
82 },
83 );