|
|
3 days ago | |
|---|---|---|
| .. | ||
| README.md | 3 days ago | |
| api.md | 3 days ago | |
| configuration.md | 3 days ago | |
| gotchas.md | 3 days ago | |
| patterns.md | 3 days ago | |
Local simulator for Cloudflare Workers development/testing. Runs Workers in workerd sandbox implementing runtime APIs - no internet required.
Decision tree for testing Workers:
Need to test Workers?
│
├─ Unit tests for business logic only?
│ └─ getPlatformProxy (Vitest/Jest) → [patterns.md](./patterns.md#getplatformproxy)
│ Fast, no HTTP, direct binding access
│
├─ Integration tests with full runtime?
│ ├─ Single Worker?
│ │ └─ Miniflare API → [Quick Start](#quick-start)
│ │ Full control, programmatic access
│ │
│ ├─ Multiple Workers + service bindings?
│ │ └─ Miniflare workers array → [configuration.md](./configuration.md#multiple-workers)
│ │ Shared storage, inter-worker calls
│ │
│ └─ Vitest test runner integration?
│ └─ vitest-pool-workers → [patterns.md](./patterns.md#vitest-pool-workers)
│ Full Workers env in Vitest
│
└─ Local dev server?
└─ wrangler dev (not Miniflare)
Hot reload, automatic config
Use Miniflare for:
Use getPlatformProxy for:
Use Wrangler for:
npm i -D miniflare
Requires ES modules in package.json:
{"type": "module"}
import { Miniflare } from "miniflare";
const mf = new Miniflare({
modules: true,
script: `
export default {
async fetch(request, env, ctx) {
return new Response("Hello Miniflare!");
}
}
`,
});
const res = await mf.dispatchFetch("http://localhost:8787/");
console.log(await res.text()); // Hello Miniflare!
await mf.dispose();
New to Miniflare? Start here:
Troubleshooting:
API reference: