| 1 | import * as Alchemy from "alchemy"; |
| 2 | import * as Railway from "alchemy/Railway"; |
| 3 | import * as Test from "alchemy/Test/Bun"; |
| 4 | import { expect } from "bun:test"; |
| 5 | import * as Console from "effect/Console"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import Stack from "../alchemy.run.ts"; |
| 8 | |
| 9 | const { getWhenReady } = Test; |
| 10 | |
| 11 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 12 | providers: Railway.providers(), |
| 13 | state: Alchemy.localState(), |
| 14 | profile: process.env.ALCHEMY_PROFILE, |
| 15 | }); |
| 16 | |
| 17 | const stack = beforeAll(deploy(Stack).pipe(Effect.tap(Console.log)), { |
| 18 | timeout: 600_000, |
| 19 | }); |
| 20 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack)); |
| 21 | |
| 22 | const base = Effect.map(stack, ({ url }) => { |
| 23 | if (!url) throw new Error("expected the site to expose a url"); |
| 24 | return url.replace(/\/+$/, ""); |
| 25 | }); |
| 26 | |
| 27 | test( |
| 28 | "deploys and exposes a url", |
| 29 | Effect.gen(function* () { |
| 30 | const { url } = yield* stack; |
| 31 | expect(url).toBeString(); |
| 32 | }), |
| 33 | { timeout: 180_000 }, |
| 34 | ); |
| 35 | |
| 36 | test( |
| 37 | "serves documentation pages", |
| 38 | Effect.gen(function* () { |
| 39 | const url = yield* base; |
| 40 | const home = yield* getWhenReady(url); |
| 41 | expect(home.status).toBe(200); |
| 42 | expect(yield* home.text).toContain("Alchemy with Vocs"); |
| 43 | |
| 44 | const guide = yield* getWhenReady(`${url}/guide`); |
| 45 | expect(guide.status).toBe(200); |
| 46 | expect(yield* guide.text).toContain("Deployment guide"); |
| 47 | |
| 48 | const counter = yield* getWhenReady(`${url}/counter`); |
| 49 | expect(counter.status).toBe(200); |
| 50 | expect(yield* counter.text).toContain("Interactive component"); |
| 51 | }), |
| 52 | { timeout: 180_000 }, |
| 53 | ); |
| 54 | |
| 55 | test( |
| 56 | "serves public and generated assets", |
| 57 | Effect.gen(function* () { |
| 58 | const url = yield* base; |
| 59 | const asset = yield* getWhenReady(`${url}/hello.txt`); |
| 60 | expect(asset.status).toBe(200); |
| 61 | expect(yield* asset.text).toContain("Vocs public directory"); |
| 62 | |
| 63 | const llms = yield* getWhenReady(`${url}/llms.txt`); |
| 64 | expect(llms.status).toBe(200); |
| 65 | expect(yield* llms.text).toContain("Alchemy with Vocs"); |
| 66 | }), |
| 67 | { timeout: 180_000 }, |
| 68 | ); |