The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Prisma from "@alchemy.run/prisma"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import { getProject, getService } from "@distilled.cloud/prisma/management"; |
| 5 | import * as Alchemy from "alchemy"; |
| 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(Effect.map((site) => ({ site }))), |
| 23 | ); |
| 24 | expect(site.url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+/); |
| 25 | expect(site.compute).toBeUndefined(); |
| 26 | expect(site.project).toBeUndefined(); |
| 27 | yield* bodyContaining(`${site.url}/`, "Prisma Website fixture"); |
| 28 | yield* bodyContaining(`${site.url}/main.ts`, "first revision"); |
| 29 | yield* fs.writeFileString( |
| 30 | path.join(rootDir, "main.ts"), |
| 31 | 'document.querySelector("#message").textContent = "second revision";', |
| 32 | ); |
| 33 | yield* bodyContaining(`${site.url}/main.ts`, "second revision"); |
| 34 | yield* stack.destroy(); |
| 35 | }).pipe(Effect.scoped), |
| 36 | { |
| 37 | tags: ["provider:prisma", "provider:prisma:website", "local"], |
| 38 | timeout: 120_000, |
| 39 | }, |
| 40 | ); |
| 41 | |
| 42 | test.provider( |
| 43 | "Vite remote opt-out deploys real Compute from dev and removes it", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | yield* stack.destroy(); |
| 47 | const rootDir = yield* copyViteFixture; |
| 48 | const { site } = yield* stack.deploy( |
| 49 | Prisma.Website.Vite("Web", { rootDir }).pipe( |
| 50 | Alchemy.remote(), |
| 51 | Effect.map((site) => ({ site })), |
| 52 | ), |
| 53 | ); |
| 54 | expect(site.url).toMatch(/^https:\/\//); |
| 55 | expect(site.compute).toBeDefined(); |
| 56 | expect(site.project).toBeDefined(); |
| 57 | const projectId = site.compute!.projectId; |
| 58 | const appId = site.compute!.appId; |
| 59 | expect((yield* getProject({ id: projectId })).data.id).toBe(projectId); |
| 60 | expect((yield* getService({ serviceId: appId })).data.id).toBe(appId); |
| 61 | yield* bodyContaining(`${site.url}/client/route`, "Prisma Website fixture"); |
| 62 | yield* stack.destroy(); |
| 63 | expect( |
| 64 | yield* getService({ serviceId: appId }).pipe( |
| 65 | Effect.as(false), |
| 66 | Effect.catchTag("NotFound", () => Effect.succeed(true)), |
| 67 | ), |
| 68 | ).toBe(true); |
| 69 | expect( |
| 70 | yield* getProject({ id: projectId }).pipe( |
| 71 | Effect.as(false), |
| 72 | Effect.catchTag("NotFound", () => Effect.succeed(true)), |
| 73 | ), |
| 74 | ).toBe(true); |
| 75 | }).pipe(Effect.scoped), |
| 76 | { |
| 77 | tags: ["provider:prisma", "provider:prisma:website", "live"], |
| 78 | timeout: 120_000, |
| 79 | }, |
| 80 | ); |