| 1 | import * as GCP from "@/GCP"; |
| 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 { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 7 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers(), dev: true }); |
| 10 | |
| 11 | const fixtureDir = pathe.resolve( |
| 12 | import.meta.dirname, |
| 13 | "../../Cloudflare/Website/staticsite-fixture", |
| 14 | ); |
| 15 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 16 | |
| 17 | describe( |
| 18 | "GCP.Website.StaticSite local", |
| 19 | { tags: ["provider:gcp", "provider:gcp:website", "local"] }, |
| 20 | () => { |
| 21 | test.provider( |
| 22 | "dev builds and serves outdir locally with no cloud resources", |
| 23 | (stack) => |
| 24 | Effect.gen(function* () { |
| 25 | yield* stack.destroy(); |
| 26 | |
| 27 | const cwd = yield* cloneFixture(fixtureDir, { |
| 28 | prefix: "alchemy-staticsite-gcp-local-", |
| 29 | tempRoot, |
| 30 | entries: ["src", "build.sh"], |
| 31 | }); |
| 32 | |
| 33 | const deployed = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | const site = yield* GCP.Website.StaticSite("Blog", { |
| 36 | path: cwd, |
| 37 | build: { command: "bash build.sh", output: "dist" }, |
| 38 | }); |
| 39 | return { site }; |
| 40 | }), |
| 41 | ); |
| 42 | |
| 43 | const url = deployed.site.url; |
| 44 | expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+\/?$/); |
| 45 | expect(deployed.site.service).toBeUndefined(); |
| 46 | |
| 47 | yield* expectUrlContains(`${url}/`, "StaticSite fixture v1", { |
| 48 | timeout: "90 seconds", |
| 49 | label: "dev staticsite index", |
| 50 | }); |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | }), |
| 54 | { |
| 55 | tags: ["provider:gcp", "provider:gcp:website", "live"], |
| 56 | timeout: 120_000, |
| 57 | }, |
| 58 | ); |
| 59 | }, |
| 60 | ); |