Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/miniflare/README.md
1# Miniflare23Local simulator for Cloudflare Workers development/testing. Runs Workers in workerd sandbox implementing runtime APIs - no internet required.45## Features67- Full-featured: KV, Durable Objects, R2, D1, WebSockets, Queues8- Fully-local: test without internet, instant reload9- TypeScript-native: detailed logging, source maps10- Advanced testing: dispatch events without HTTP, simulate Worker connections1112## When to Use1314**Decision tree for testing Workers:**1516```17Need to test Workers?18│19├─ Unit tests for business logic only?20│ └─ getPlatformProxy (Vitest/Jest) → [patterns.md](./patterns.md#getplatformproxy)21│ Fast, no HTTP, direct binding access22│23├─ Integration tests with full runtime?24│ ├─ Single Worker?25│ │ └─ Miniflare API → [Quick Start](#quick-start)26│ │ Full control, programmatic access27│ │28│ ├─ Multiple Workers + service bindings?29│ │ └─ Miniflare workers array → [configuration.md](./configuration.md#multiple-workers)30│ │ Shared storage, inter-worker calls31│ │32│ └─ Vitest test runner integration?33│ └─ vitest-pool-workers → [patterns.md](./patterns.md#vitest-pool-workers)34│ Full Workers env in Vitest35│36└─ Local dev server?37└─ wrangler dev (not Miniflare)38Hot reload, automatic config39```4041**Use Miniflare for:**42- Integration tests with full Worker runtime43- Testing bindings/storage locally44- Multiple Workers with service bindings45- Programmatic event dispatch (fetch, queue, scheduled)4647**Use getPlatformProxy for:**48- Fast unit tests of business logic49- Testing without HTTP overhead50- Vitest/Jest environments5152**Use Wrangler for:**53- Local development workflow54- Production deployments5556## Setup5758```bash59npm i -D miniflare60```6162Requires ES modules in `package.json`:63```json64{"type": "module"}65```6667## Quick Start6869```js70import { Miniflare } from "miniflare";7172const mf = new Miniflare({73modules: true,74script: `75export default {76async fetch(request, env, ctx) {77return new Response("Hello Miniflare!");78}79}80`,81});8283const res = await mf.dispatchFetch("http://localhost:8787/");84console.log(await res.text()); // Hello Miniflare!85await mf.dispose();86```8788## Reading Order8990**New to Miniflare?** Start here:911. [Quick Start](#quick-start) - Running in 2 minutes922. [When to Use](#when-to-use) - Choose your testing approach933. [patterns.md](./patterns.md) - Testing patterns (getPlatformProxy, Vitest, node:test)944. [configuration.md](./configuration.md) - Configure bindings, storage, multiple workers9596**Troubleshooting:**97- [gotchas.md](./gotchas.md) - Common errors and debugging9899**API reference:**100- [api.md](./api.md) - Complete method reference101102## See Also103- [wrangler](../wrangler/) - CLI tool that embeds Miniflare for `wrangler dev`104- [workerd](../workerd/) - Runtime that powers Miniflare105- [workers](../workers/) - Workers runtime API documentation106