| 1 | import { providers } from "@/Neon/Providers.ts"; |
| 2 | import { WebsiteArtifact } from "@/Neon/Website/Artifact.ts"; |
| 3 | import { deployWebsite } from "@/Neon/Website/FrameworkSite.ts"; |
| 4 | import * as Test from "@/Test/Alchemy.ts"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as FileSystem from "effect/FileSystem"; |
| 8 | import * as Path from "effect/Path"; |
| 9 | import { exampleRoot } from "./Fixture.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: providers() }); |
| 12 | |
| 13 | test.provider( |
| 14 | "website fixtures isolate sources, build output and dependency caches", |
| 15 | (stack) => |
| 16 | Effect.gen(function* () { |
| 17 | yield* stack.destroy(); |
| 18 | const fs = yield* FileSystem.FileSystem; |
| 19 | const path = yield* Path.Path; |
| 20 | const roots = yield* Effect.gen(function* () { |
| 21 | const first = yield* exampleRoot("vite"); |
| 22 | const second = yield* exampleRoot("vite"); |
| 23 | expect(first).not.toBe(second); |
| 24 | expect(path.basename(path.dirname(first))).toBe("examples"); |
| 25 | const asset = "public/example.json"; |
| 26 | const original = yield* fs.readFileString(path.join(second, asset)); |
| 27 | yield* fs.writeFileString(path.join(first, asset), "changed"); |
| 28 | expect(yield* fs.readFileString(path.join(second, asset))).toBe( |
| 29 | original, |
| 30 | ); |
| 31 | yield* fs.makeDirectory(path.join(first, "node_modules/.vite")); |
| 32 | yield* fs.writeFileString( |
| 33 | path.join(first, "node_modules/.vite/marker"), |
| 34 | "private", |
| 35 | ); |
| 36 | expect( |
| 37 | yield* fs.exists(path.join(second, "node_modules/.vite/marker")), |
| 38 | ).toBe(false); |
| 39 | expect( |
| 40 | yield* fs.exists(path.resolve(first, "../../tsconfig.base.json")), |
| 41 | ).toBe(true); |
| 42 | expect(yield* fs.realPath(path.join(first, "node_modules/vite"))).toBe( |
| 43 | yield* fs.realPath(path.join(second, "node_modules/vite")), |
| 44 | ); |
| 45 | expect(yield* fs.exists(path.join(first, "dist"))).toBe(false); |
| 46 | return [first, second]; |
| 47 | }).pipe(Effect.scoped); |
| 48 | for (const root of roots) expect(yield* fs.exists(root)).toBe(false); |
| 49 | yield* stack.destroy(); |
| 50 | }), |
| 51 | { tags: ["provider:neon", "provider:neon:website", "live"] }, |
| 52 | ); |
| 53 | |
| 54 | test.provider( |
| 55 | "owned backend provisioning depends on artifact validation", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | const plan = yield* stack.plan( |
| 60 | Effect.gen(function* () { |
| 61 | const artifact = yield* WebsiteArtifact("Artifact", { |
| 62 | root: ".", |
| 63 | distDir: "dist", |
| 64 | static: {}, |
| 65 | }); |
| 66 | return yield* deployWebsite({}, artifact); |
| 67 | }), |
| 68 | ); |
| 69 | expect(plan.resources.Artifact?.downstream).toContain("Project"); |
| 70 | expect(plan.resources.Project?.action).toBe("create"); |
| 71 | expect(plan.resources.Function?.action).toBe("create"); |
| 72 | yield* stack.destroy(); |
| 73 | }), |
| 74 | { |
| 75 | tags: ["provider:neon", "provider:neon:website", "live"], |
| 76 | timeout: 120_000, |
| 77 | }, |
| 78 | ); |