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