Skip to content
TypeScript
1.5 KB
Raw Blame
import * as Cloudflare from "@alchemy.run/cloudflare";
import { expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
import * as pathe from "pathe";
import { expectUrlContains } from "../Utils/Http.ts";

const { test } = Test.make({
  providers: Cloudflare.providers(),
  dev: true,
});

const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");

const main = pathe.resolve(import.meta.dirname, "fixtures/python/worker.py");

// `dev: true` selects the local provider: the Python entry and its sibling
// modules are served by workerd (which embeds Pyodide) instead of being
// uploaded to Cloudflare. The first start may download the Pyodide runtime
// bundle, so the fetch retries generously.
test.provider(
  "serves a Python Worker from local workerd",
  (stack) =>
    Effect.gen(function* () {
      yield* stack.destroy();

      const worker = yield* stack.deploy(
        Effect.gen(function* () {
          return yield* Cloudflare.Worker("PythonLocalWorker", {
            main,
            env: { PY_SUFFIX: "local" },
          });
        }),
      );

      expect(worker.url).toBeDefined();
      yield* expectUrlContains(worker.url!, "alchemy-python-worker-7c1f suffix=local");

      yield* stack.destroy();
    }).pipe(logLevel),
  {
    tags: ["provider:cloudflare", "provider:cloudflare:worker", "local"],
    timeout: 240_000,
  },
);