1import * as Alchemy from "alchemy";
2import * as Cloudflare from "alchemy/Cloudflare";
3import * as Test from "alchemy/Test/Bun";
4import { expect } from "bun:test";
5import * as Effect from "effect/Effect";
6import * as HttpClient from "effect/http/HttpClient";
7import { frameworks } from "../frameworks.ts";
8import Stack from "../alchemy.run.ts";
9
10const stage = "dev-service-bindings";
11const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
12 providers: Cloudflare.providers(),
13 profile: process.env.ALCHEMY_PROFILE,
14 stage,
15 dev: true,
16});
17
18const stack = beforeAll(
19 Alchemy.destroy({ stack: Stack, stage }).pipe(Effect.andThen(deploy(Stack))),
20 { timeout: 120_000 },
21);
22afterAll(destroy(Stack));
23
24for (const { name, marker } of frameworks) {
25 test(
26 `${name}: the local Website serves its page directly`,
27 Effect.gen(function* () {
28 const { websiteUrl } = (yield* stack)[name]!;
29 expect(websiteUrl).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+/);
30 const response = yield* Test.getWhenReady(String(websiteUrl), {
31 times: 3,
32 });
33 expect(response.status).toBe(200);
34 expect(yield* response.text).toContain(marker);
35 }).pipe(Effect.timeout("30 seconds")),
36 { timeout: 35_000 },
37 );
38 test(
39 `${name}: the Gateway reaches the Website through its service binding`,
40 Effect.gen(function* () {
41 const { gatewayUrl } = (yield* stack)[name]!;
42 const response = yield* HttpClient.get(String(gatewayUrl));
43 const body = yield* response.text;
44 expect(response.status, body).toBe(200);
45 expect(body).toContain(marker);
46 }).pipe(Effect.timeout("10 seconds")),
47 { timeout: 15_000 },
48 );
49}