| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import { expect } from "alchemy-test"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 6 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 7 | import { dockerAvailable } from "../bindingHost.ts"; |
| 8 | import { |
| 9 | assertSiteGone, |
| 10 | awsFixture, |
| 11 | cloudRunUrl, |
| 12 | liveOptions, |
| 13 | logLevel, |
| 14 | serviceIdentity, |
| 15 | tempRoot, |
| 16 | } from "./site.ts"; |
| 17 | |
| 18 | const { test } = Test.make({ providers: GCP.providers() }); |
| 19 | |
| 20 | const fixtureDir = awsFixture("sveltekit-app"); |
| 21 | const fixtureEntries = [".gitignore", "package.json", "src", "static"]; |
| 22 | |
| 23 | test.provider.skipIf(!dockerAvailable)( |
| 24 | "SvelteKit: deploy, GET page and API route, destroy, gone", |
| 25 | (stack) => |
| 26 | Effect.gen(function* () { |
| 27 | yield* stack.destroy(); |
| 28 | |
| 29 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 30 | prefix: "alchemy-sveltekit-gcp-", |
| 31 | tempRoot, |
| 32 | entries: fixtureEntries, |
| 33 | }); |
| 34 | |
| 35 | const deployed = yield* stack.deploy( |
| 36 | Effect.gen(function* () { |
| 37 | const site = yield* GCP.Website.SvelteKit("Web", { |
| 38 | rootDir, |
| 39 | memo: { include: ["src/**", "static/**", "package.json"] }, |
| 40 | }); |
| 41 | return { site }; |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | const url = deployed.site.url as string; |
| 46 | expect(url).toMatch(cloudRunUrl); |
| 47 | expect(deployed.site.service).toBeDefined(); |
| 48 | const service = serviceIdentity(deployed.site.service!); |
| 49 | |
| 50 | yield* expectUrlContains(`${url}/`, "SVELTEKIT_AWS_PAGE_MARKER", { |
| 51 | timeout: "180 seconds", |
| 52 | label: "SvelteKit /", |
| 53 | }); |
| 54 | yield* expectUrlContains( |
| 55 | `${url}/api/hello?echo=roundtrip`, |
| 56 | "SVELTEKIT_AWS_API_MARKER", |
| 57 | { |
| 58 | timeout: "30 seconds", |
| 59 | label: "SvelteKit /api/hello?echo=roundtrip", |
| 60 | }, |
| 61 | ); |
| 62 | |
| 63 | yield* stack.destroy(); |
| 64 | yield* assertSiteGone(service); |
| 65 | }).pipe(logLevel), |
| 66 | liveOptions(900_000), |
| 67 | ); |