| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { exerciseSqlSurface } from "./exercise.ts"; |
| 5 | import Stack from "./fixtures/d1-stack.ts"; |
| 6 | |
| 7 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 8 | providers: Cloudflare.providers(), |
| 9 | state: Cloudflare.state(), |
| 10 | }); |
| 11 | |
| 12 | const HOOK_TIMEOUT = 300_000; |
| 13 | const TEST_TIMEOUT = 120_000; |
| 14 | |
| 15 | /** |
| 16 | * End-to-end test of `SQL.D1` — the raw `@effect/sql-d1` client wrapped in |
| 17 | * alchemy's deferred `proxyChain` — against a real Cloudflare Worker + D1 |
| 18 | * database. The shared exercise drives every `SqlClient` constructor helper |
| 19 | * the D1 driver supports (transactions and `updateValues` are not supported |
| 20 | * by `@effect/sql-d1`); because the client is proxyChain-wrapped, every |
| 21 | * nested helper (`sql.insert`, `sql.and`, `sql.in`, `sql.csv`, identifiers) |
| 22 | * also regression-tests deferred-proxy replay. |
| 23 | */ |
| 24 | const stack = beforeAll(deploy(Stack), { timeout: HOOK_TIMEOUT }); |
| 25 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), { |
| 26 | timeout: HOOK_TIMEOUT, |
| 27 | }); |
| 28 | |
| 29 | test( |
| 30 | "SQL.D1 exercises the full client surface over a deployed Worker", |
| 31 | Effect.gen(function* () { |
| 32 | const { url } = yield* stack; |
| 33 | yield* exerciseSqlSurface(url); |
| 34 | }), |
| 35 | { |
| 36 | tags: [ |
| 37 | "provider:cloudflare", |
| 38 | "provider:cloudflare:d1", |
| 39 | "provider:cloudflare:worker", |
| 40 | "live", |
| 41 | ], |
| 42 | timeout: TEST_TIMEOUT, |
| 43 | }, |
| 44 | ); |