sdxc-cloudflare-mocks

Creates in-memory Cloudflare binding mocks with real SQL execution for unit tests.

5|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-cloudflare-mocks-sergiodxa
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sdxc-cloudflare-mocks
Source: https://github.com/sergiodxa/monorepo/tree/main/.agents/skills/sdxc-cloudflare-mocks
Command: npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-cloudflare-mocks-sergiodxa

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Testing Cloudflare Workers code that depends on KV, D1, R2, queues, or Durable Objects normally requires a wrangler runtime, making fast unit tests difficult. This Skill provides in-memory, behavior-accurate binding mocks where storage bindings really store and SQL bindings run real SQL through the runtime's SQLite, so malformed statements and constraint violations fail in the test rather than in production. ## Core Features & Use Cases - Binding factories: createKVNamespace, createD1Database, createSqlStorage, createR2Bucket, createQueue, createDurableObjectState, createExecutionContext, and createEnv, each typed against @cloudflare/workers-types so drift from the platform fails typecheck. - Real SQL execution: D1 and SqlStorage run actual SQL via the runtime's built-in SQLite (Bun or Node), letting you cover a repository's generated SQL with ordinary unit tests. - Deterministic async control: queues hold messages until consume() is called, alarms fire only when the test invokes alarm(), and createExecutionContext().settled() awaits waitUntil background work. - Use Case: Unit-test a Worker fetch handler that reads KV and writes to D1 by calling createEnv({ DB: createD1Database(), CACHE: createKVNamespace() }) in beforeEach, then asserting on stored rows without starting wrangler. ## Quick Start Add @sdxc/cloudflare-mocks as a workspace dev dependency and ask the AI to write a unit test for your Worker handler using createEnv with the bindings your code expects.

Frequently Asked Questions about sdxc-cloudflare-mocks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I unit test a Cloudflare Worker without wrangler?▼

Use the factories from @sdxc/cloudflare-mocks to build an Env object in memory, for example createEnv({ DB: createD1Database(), CACHE: createKVNamespace() }). Each factory returns an isolated instance typed against @cloudflare/workers-types, so tests run in Bun or Node without a wrangler runtime.

How to test D1 database queries in unit tests?▼

Call createD1Database() and pass it to the code under test; it runs real SQL through the runtime's built-in SQLite, so malformed statements and constraint violations fail in the test. Call the factory in beforeEach for isolated state, or use its reset() when the binding lives at module scope.

Does the D1 mock enforce Cloudflare platform limits?▼

No. D1 runs local SQLite, so unsupported SQL and oversized results pass, and D1, KV, and R2 size, time, and consistency limits are unenforced. Treat a green test as behavioral coverage, not a production guarantee.

Can I test queue consumers and Durable Object alarms?▼

Yes, but delivery is manual. A queue holds messages until you call consume(), letting you assert on retries and attempts, and setAlarm only records a time so the test invokes the object's alarm() handler itself.

What Cloudflare bindings are not supported by the mocks?▼

Hyperdrive, Vectorize, Workers AI, and Browser Rendering have no mock at all. ExecutionContext exports and tracing, and DurableObjectState exports and facets, are also unsupported, and idFromName yields an id whose string form is the name.