Setting the file. One moment.
Chapter 04 · Cloudflare Deploy
Subchapter 4.122
references/miniflare/README.mdMarkdown3 KBView on GitHub
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 configUse Miniflare for:
Use getPlatformProxy for:
Use Wrangler for:
npm i -D miniflareRequires 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:
wrangler dev