Wrangler's unstable_startWorker()
If you do not want to use Vitest, consider using Wrangler's unstable_startWorker()
API. This API exposes the internals of Wrangler's dev server, and allows you to customise how it runs. Compared to using Miniflare directly for testing, you can pass in a Wrangler configuration file, and it will automatically load the configuration for you.
This example uses node:test
, but should apply to any testing framework:
import assert from "node:assert";import test, { after, before, describe } from "node:test";import { unstable_startWorker } from "wrangler";
describe("worker", () => { let worker;
before(async () => { worker = await unstable_startWorker({ config: "wrangler.json" }); });
test("hello world", async () => { assert.strictEqual( await (await worker.fetch("http://example.com")).text(), "Hello world", ); });
after(async () => { await worker.dispose(); });});
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark