| 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("nuxt-app"); |
| 21 | const fixtureEntries = [ |
| 22 | ".gitignore", |
| 23 | "package.json", |
| 24 | "nuxt.config.ts", |
| 25 | "app", |
| 26 | "server", |
| 27 | "public", |
| 28 | ]; |
| 29 | |
| 30 | test.provider.skipIf(!dockerAvailable)( |
| 31 | "Nuxt: deploy, GET page, API and prerendered routes, destroy, gone", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 37 | prefix: "alchemy-nuxt-gcp-", |
| 38 | tempRoot, |
| 39 | entries: fixtureEntries, |
| 40 | }); |
| 41 | |
| 42 | const deployed = yield* stack.deploy( |
| 43 | Effect.gen(function* () { |
| 44 | const site = yield* GCP.Website.Nuxt("Web", { |
| 45 | rootDir, |
| 46 | memo: { |
| 47 | include: [ |
| 48 | "app/**", |
| 49 | "server/**", |
| 50 | "public/**", |
| 51 | "package.json", |
| 52 | "nuxt.config.ts", |
| 53 | ], |
| 54 | }, |
| 55 | }); |
| 56 | return { site }; |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | const url = deployed.site.url as string; |
| 61 | expect(url).toMatch(cloudRunUrl); |
| 62 | expect(deployed.site.service).toBeDefined(); |
| 63 | const service = serviceIdentity(deployed.site.service!); |
| 64 | |
| 65 | yield* expectUrlContains(`${url}/`, "NUXT_AWS_PAGE_MARKER", { |
| 66 | timeout: "180 seconds", |
| 67 | label: "Nuxt /", |
| 68 | }); |
| 69 | yield* expectUrlContains( |
| 70 | `${url}/api/hello?echo=roundtrip`, |
| 71 | "NUXT_AWS_API_MARKER", |
| 72 | { |
| 73 | timeout: "30 seconds", |
| 74 | label: "Nuxt /api/hello?echo=roundtrip", |
| 75 | }, |
| 76 | ); |
| 77 | yield* expectUrlContains( |
| 78 | `${url}/prerendered`, |
| 79 | "NUXT_AWS_PRERENDERED_MARKER", |
| 80 | { |
| 81 | timeout: "30 seconds", |
| 82 | label: "Nuxt /prerendered", |
| 83 | }, |
| 84 | ); |
| 85 | |
| 86 | yield* stack.destroy(); |
| 87 | yield* assertSiteGone(service); |
| 88 | }).pipe(logLevel), |
| 89 | liveOptions(900_000), |
| 90 | ); |