| 1 | import * as Alchemy from "@/index.ts"; |
| 2 | import * as Prisma from "@/Prisma/index.ts"; |
| 3 | import * as Test from "@/Test/Alchemy.ts"; |
| 4 | import { getProject, getService } from "@distilled.cloud/prisma/management"; |
| 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 { bodyContaining, copyViteFixture } from "./Fixture.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: Prisma.providers(), dev: true }); |
| 12 | |
| 13 | test.provider( |
| 14 | "Vite dev serves native modules and updates without cloud resources", |
| 15 | (stack) => |
| 16 | Effect.gen(function* () { |
| 17 | yield* stack.destroy(); |
| 18 | const fs = yield* FileSystem.FileSystem; |
| 19 | const path = yield* Path.Path; |
| 20 | const rootDir = yield* copyViteFixture; |
| 21 | const { site } = yield* stack.deploy( |
| 22 | Prisma.Website.Vite("Web", { rootDir }).pipe( |
| 23 | Effect.map((site) => ({ site })), |
| 24 | ), |
| 25 | ); |
| 26 | expect(site.url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+/); |
| 27 | expect(site.compute).toBeUndefined(); |
| 28 | expect(site.project).toBeUndefined(); |
| 29 | yield* bodyContaining(`${site.url}/`, "Prisma Website fixture"); |
| 30 | yield* bodyContaining(`${site.url}/main.ts`, "first revision"); |
| 31 | yield* fs.writeFileString( |
| 32 | path.join(rootDir, "main.ts"), |
| 33 | 'document.querySelector("#message").textContent = "second revision";', |
| 34 | ); |
| 35 | yield* bodyContaining(`${site.url}/main.ts`, "second revision"); |
| 36 | yield* stack.destroy(); |
| 37 | }).pipe(Effect.scoped), |
| 38 | { |
| 39 | tags: ["provider:prisma", "provider:prisma:website", "local"], |
| 40 | timeout: 120_000, |
| 41 | }, |
| 42 | ); |
| 43 | |
| 44 | test.provider.skipIf(process.env.ALCHEMY_RUN_LIVE_PRISMA_TESTS !== "true")( |
| 45 | "Vite remote opt-out deploys real Compute from dev and removes it", |
| 46 | (stack) => |
| 47 | Effect.gen(function* () { |
| 48 | yield* stack.destroy(); |
| 49 | const rootDir = yield* copyViteFixture; |
| 50 | const { site } = yield* stack.deploy( |
| 51 | Prisma.Website.Vite("Web", { rootDir }).pipe( |
| 52 | Alchemy.remote(), |
| 53 | Effect.map((site) => ({ site })), |
| 54 | ), |
| 55 | ); |
| 56 | expect(site.url).toMatch(/^https:\/\//); |
| 57 | expect(site.compute).toBeDefined(); |
| 58 | expect(site.project).toBeDefined(); |
| 59 | const projectId = site.compute!.projectId; |
| 60 | const appId = site.compute!.appId; |
| 61 | expect((yield* getProject({ id: projectId })).data.id).toBe(projectId); |
| 62 | expect((yield* getService({ serviceId: appId })).data.id).toBe(appId); |
| 63 | yield* bodyContaining( |
| 64 | `${site.url}/client/route`, |
| 65 | "Prisma Website fixture", |
| 66 | ); |
| 67 | yield* stack.destroy(); |
| 68 | expect( |
| 69 | yield* getService({ serviceId: appId }).pipe( |
| 70 | Effect.as(false), |
| 71 | Effect.catchTag("NotFound", () => Effect.succeed(true)), |
| 72 | ), |
| 73 | ).toBe(true); |
| 74 | expect( |
| 75 | yield* getProject({ id: projectId }).pipe( |
| 76 | Effect.as(false), |
| 77 | Effect.catchTag("NotFound", () => Effect.succeed(true)), |
| 78 | ), |
| 79 | ).toBe(true); |
| 80 | }).pipe(Effect.scoped), |
| 81 | { |
| 82 | tags: ["provider:prisma", "provider:prisma:website", "live"], |
| 83 | timeout: 120_000, |
| 84 | }, |
| 85 | ); |