| 1 | import * as Hetzner from "@/Hetzner"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import { describe, expect } from "alchemy-test"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as pathe from "pathe"; |
| 6 | import { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.ts"; |
| 7 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 8 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: Hetzner.providers(), dev: true }); |
| 11 | |
| 12 | const fixtureDir = pathe.resolve( |
| 13 | import.meta.dirname, |
| 14 | "../../AWS/Website/fixtures/nextjs-app", |
| 15 | ); |
| 16 | const fixtureEntries = [ |
| 17 | ".gitignore", |
| 18 | "package.json", |
| 19 | "next.config.ts", |
| 20 | "tsconfig.json", |
| 21 | "app", |
| 22 | "public", |
| 23 | ]; |
| 24 | |
| 25 | describe( |
| 26 | "Hetzner.Website.Nextjs local", |
| 27 | { tags: ["provider:hetzner", "provider:hetzner: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 | // Clone OUTSIDE the repo (OS temp dir): an in-workspace clone makes |
| 36 | // Next treat the alchemy monorepo as the workspace root and look up |
| 37 | // the root's typescript (catalog:build = tsgo). |
| 38 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 39 | prefix: "alchemy-nextjs-hetzner-local-", |
| 40 | entries: fixtureEntries, |
| 41 | }); |
| 42 | yield* prepareNextjsFixture(rootDir); |
| 43 | |
| 44 | const deployed = yield* stack.deploy( |
| 45 | Effect.gen(function* () { |
| 46 | const site = yield* Hetzner.Website.Nextjs("Web", { |
| 47 | rootDir, |
| 48 | }); |
| 49 | return { site }; |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | const url = deployed.site.url; |
| 54 | expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+\/?$/); |
| 55 | expect(deployed.site.service).toBeUndefined(); |
| 56 | expect(deployed.site.server).toBeUndefined(); |
| 57 | |
| 58 | yield* expectUrlContains(`${url}/`, "NEXTJS_AWS_PAGE_MARKER", { |
| 59 | timeout: "180 seconds", |
| 60 | label: "dev home page", |
| 61 | }); |
| 62 | yield* expectUrlContains( |
| 63 | `${url}/api/hello?echo=roundtrip`, |
| 64 | "NEXTJS_AWS_API_MARKER", |
| 65 | { label: "api route (dev)" }, |
| 66 | ); |
| 67 | yield* expectUrlContains( |
| 68 | `${url}/static`, |
| 69 | "NEXTJS_AWS_STATIC_MARKER", |
| 70 | { |
| 71 | label: "extra route (dev)", |
| 72 | }, |
| 73 | ); |
| 74 | |
| 75 | yield* stack.destroy(); |
| 76 | }), |
| 77 | { timeout: 600_000 }, |
| 78 | ); |
| 79 | }, |
| 80 | ); |