| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import { expect } from "alchemy-test"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import { MinimumLogLevel } from "effect/References"; |
| 6 | import * as pathe from "pathe"; |
| 7 | import { expectUrlContains } from "../Utils/Http.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ |
| 10 | providers: Cloudflare.providers(), |
| 11 | dev: true, |
| 12 | }); |
| 13 | |
| 14 | const logLevel = Effect.provideService( |
| 15 | MinimumLogLevel, |
| 16 | process.env.DEBUG ? "Debug" : "Info", |
| 17 | ); |
| 18 | |
| 19 | const main = pathe.resolve(import.meta.dirname, "fixtures/python/worker.py"); |
| 20 | |
| 21 | // `dev: true` selects the local provider: the Python entry and its sibling |
| 22 | // modules are served by workerd (which embeds Pyodide) instead of being |
| 23 | // uploaded to Cloudflare. The first start may download the Pyodide runtime |
| 24 | // bundle, so the fetch retries generously. |
| 25 | test.provider( |
| 26 | "serves a Python Worker from local workerd", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | yield* stack.destroy(); |
| 30 | |
| 31 | const worker = yield* stack.deploy( |
| 32 | Effect.gen(function* () { |
| 33 | return yield* Cloudflare.Worker("PythonLocalWorker", { |
| 34 | main, |
| 35 | env: { PY_SUFFIX: "local" }, |
| 36 | }); |
| 37 | }), |
| 38 | ); |
| 39 | |
| 40 | expect(worker.url).toBeDefined(); |
| 41 | yield* expectUrlContains( |
| 42 | worker.url!, |
| 43 | "alchemy-python-worker-7c1f suffix=local", |
| 44 | ); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { |
| 49 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "local"], |
| 50 | timeout: 240_000, |
| 51 | }, |
| 52 | ); |