1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import { describe, expect } from "alchemy-test";
4import * as Effect from "effect/Effect";
5import * as pathe from "pathe";
6import { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.ts";
7import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
8import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
9
10const { test } = Test.make({ providers: GCP.providers(), dev: true });
11
12const fixtureDir = pathe.resolve(
13 import.meta.dirname,
14 "../../AWS/Website/fixtures/nextjs-app",
15);
16const fixtureEntries = [
17 ".gitignore",
18 "package.json",
19 "next.config.ts",
20 "tsconfig.json",
21 "app",
22 "public",
23];
24
25describe(
26 "GCP.Website.Nextjs local",
27 { tags: ["provider:gcp", "provider:gcp: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-gcp-local-",
40 entries: fixtureEntries,
41 });
42 yield* prepareNextjsFixture(rootDir);
43
44 const deployed = yield* stack.deploy(
45 Effect.gen(function* () {
46 const site = yield* GCP.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
57 yield* expectUrlContains(`${url}/`, "NEXTJS_AWS_PAGE_MARKER", {
58 timeout: "180 seconds",
59 label: "dev home page",
60 });
61 yield* expectUrlContains(
62 `${url}/api/hello?echo=roundtrip`,
63 "NEXTJS_AWS_API_MARKER",
64 { label: "api route (dev)" },
65 );
66 yield* expectUrlContains(
67 `${url}/static`,
68 "NEXTJS_AWS_STATIC_MARKER",
69 {
70 label: "extra route (dev)",
71 },
72 );
73
74 yield* stack.destroy();
75 }),
76 {
77 tags: ["provider:gcp", "provider:gcp:website", "live"],
78 timeout: 600_000,
79 },
80 );
81 },
82);