| 1 | import { providers } from "@/Neon/Providers.ts"; |
| 2 | import * as Website from "@/Neon/Website/index.ts"; |
| 3 | import * as Test from "@/Test/Alchemy.ts"; |
| 4 | import { describe, expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { bodyContaining, exampleRoot } from "./Fixture.ts"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: providers(), dev: true }); |
| 9 | const constructors = [ |
| 10 | Website.Vite, |
| 11 | Website.Astro, |
| 12 | Website.Nextjs, |
| 13 | Website.Nuxt, |
| 14 | Website.SvelteKit, |
| 15 | Website.ReactRouter, |
| 16 | Website.SolidStart, |
| 17 | Website.TanStackStart, |
| 18 | Website.Waku, |
| 19 | Website.Octane, |
| 20 | Website.Foldkit, |
| 21 | Website.Vocs, |
| 22 | ]; |
| 23 | |
| 24 | describe.sequential( |
| 25 | "Neon Website explicit local scope", |
| 26 | { tags: ["provider:neon", "provider:neon:website", "local"] }, |
| 27 | () => { |
| 28 | for (const [index, website] of constructors.entries()) { |
| 29 | test.provider( |
| 30 | `constructor ${index} preserves explicit branch and project without an implicit backend`, |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | const dev = { |
| 35 | mode: "external" as const, |
| 36 | url: "http://localhost:5173", |
| 37 | }; |
| 38 | const branch = { |
| 39 | projectId: "explicit-project", |
| 40 | branchId: "explicit-branch", |
| 41 | }; |
| 42 | const project = { projectId: "explicit-project" }; |
| 43 | const first = yield* stack.deploy(website("Web", { branch, dev })); |
| 44 | expect(first.branch).toEqual(branch); |
| 45 | expect(first.project).toBeUndefined(); |
| 46 | expect(first.function).toBeUndefined(); |
| 47 | expect(first.url).toBe(dev.url); |
| 48 | const second = yield* stack.deploy( |
| 49 | website("Web", { project, dev }), |
| 50 | ); |
| 51 | expect(second.project).toEqual(project); |
| 52 | expect(second.branch).toBeUndefined(); |
| 53 | expect(second.function).toBeUndefined(); |
| 54 | yield* stack.destroy(); |
| 55 | }), |
| 56 | { timeout: 120_000 }, |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | test.provider( |
| 61 | "StaticSite preserves explicit branch and project without an implicit backend", |
| 62 | (stack) => |
| 63 | Effect.gen(function* () { |
| 64 | yield* stack.destroy(); |
| 65 | const rootDir = yield* exampleRoot("static"); |
| 66 | const branch = { |
| 67 | projectId: "explicit-project", |
| 68 | branchId: "explicit-branch", |
| 69 | }; |
| 70 | const project = { projectId: "explicit-project" }; |
| 71 | const props = { |
| 72 | rootDir, |
| 73 | command: "bun run build", |
| 74 | outdir: "dist", |
| 75 | dev: { command: "bun run dev:site" }, |
| 76 | }; |
| 77 | const first = yield* stack.deploy( |
| 78 | Website.StaticSite("Web", { ...props, branch }), |
| 79 | ); |
| 80 | expect(first.branch).toEqual(branch); |
| 81 | expect(first.project).toBeUndefined(); |
| 82 | expect(first.function).toBeUndefined(); |
| 83 | yield* bodyContaining(String(first.url), "Static site on Neon"); |
| 84 | const second = yield* stack.deploy( |
| 85 | Website.StaticSite("Web", { ...props, project }), |
| 86 | ); |
| 87 | expect(second.project).toEqual(project); |
| 88 | expect(second.branch).toBeUndefined(); |
| 89 | expect(second.function).toBeUndefined(); |
| 90 | yield* stack.destroy(); |
| 91 | }), |
| 92 | { timeout: 120_000 }, |
| 93 | ); |
| 94 | }, |
| 95 | ); |