1import * as Fly from "@/Fly";
2import * as Test from "@/Test/Alchemy";
3import { describe, expect } from "alchemy-test";
4import * as Effect from "effect/Effect";
5import * as pathe from "pathe";
6import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
7import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
8
9const { test } = Test.make({ providers: Fly.providers(), dev: true });
10
11const fixtureDir = pathe.resolve(
12 import.meta.dirname,
13 "../../AWS/Website/fixtures/react-router-app",
14);
15const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
16const fixtureEntries = [
17 ".gitignore",
18 "package.json",
19 "react-router.config.ts",
20 "vite.config.ts",
21 "app",
22 "public",
23];
24
25describe(
26 "Fly.Website.ReactRouter local",
27 { tags: ["provider:fly", "provider:fly:website", "local"] },
28 () => {
29 test.provider(
30 "dev runs the framework server with no cloud resources",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const rootDir = yield* cloneFixture(fixtureDir, {
36 prefix: "alchemy-react-router-fly-local-",
37 tempRoot,
38 entries: fixtureEntries,
39 });
40
41 const deployed = yield* stack.deploy(
42 Effect.gen(function* () {
43 const site = yield* Fly.Website.ReactRouter("Web", {
44 rootDir,
45 });
46 return { site };
47 }),
48 );
49
50 const url = deployed.site.url;
51 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+\/?$/);
52 expect(deployed.site.service).toBeUndefined();
53 expect(deployed.site.app).toBeUndefined();
54 expect(deployed.site.ip).toBeUndefined();
55
56 const origin = String(url).replace(/\/+$/, "");
57 yield* expectUrlContains(
58 `${origin}/`,
59 "REACT_ROUTER_AWS_PAGE_MARKER",
60 {
61 timeout: "90 seconds",
62 label: "dev home page",
63 },
64 );
65 yield* expectUrlContains(
66 `${origin}/api/hello?echo=roundtrip`,
67 "REACT_ROUTER_AWS_API_MARKER",
68 { label: "api route (dev)" },
69 );
70
71 yield* stack.destroy();
72 }),
73 { timeout: 120_000 },
74 );
75 },
76);