Agent skill · software engineering · secondsky
cloudflare-workers-testing
Comprehensive testing guide for Cloudflare Workers using Vitest and @cloudflare/vitest-pool-workers. Use for test setup, binding mocks (D1/KV/R2/DO), integration tests, or encountering test failures, mock errors, coverage issues.
Why this skill is useful
Adds executable scripts and specific testing patterns for Cloudflare Workers that the AI wouldn't reliably generate on its own.
What it needs
Requires bun installed locally. About 9k tokens when loaded. Last updated 2026-08-06. 204 stars on the source repository.
What this skill does
Cloudflare Workers Testing with Vitest Status: ✅ Production Ready Last Verified: 2025-01-27 Vitest: ^2.0.0 @cloudflare/vitest-pool-workers: 0.7.2 Miniflare: Latest Table of Contents What Is Workers Testing? New in 2025 Quick Start (5 Minutes) Critical Rules Core Concepts Top 5 Use Cases Best Practices Top 8 Errors Prevented When to Load References --- What Is Workers Testing? Testing Cloudflare Workers with Vitest and @cloudflare/vitest-pool-workers enables writing unit and integration tests that run in a real Workers environment with full binding support (D1, KV, R2, Durable Objects, Queues, AI). Tests execute in Miniflare for local development and can run in CI/CD with actual Workers runtime behavior. Key capabilities: Binding mocks, execution context testing, edge runtime simulation, coverage tracking, fast test execution. --- New in 2025 @cloudflare/vitest-pool-workers 0.7.2 (January 2025): BREAKING: Miniflare v3 → requires Node.js 20+ NEW: cloudflare:test module for env/ctx access IMPROVED: Faster isolated storage for bindings FIXED: Worker-to-worker service bindings now work correctly ADDED: Support for Vectorize and Workers AI bindings Migration from older versions: --- Quick Start (5 Minutes) 1. Install Dependencies 2. Create vitest.config.ts 3. Write Your First Test 4. Run Tests --- Critical Rules 1. Always Use cloudflare:test for Env Access ✅ CORRECT: ❌ WRONG: Why: cloudflare:test provides real bindings configured from wrangler.jsonc with isolated storage per test. 2. Always Wait on Execution Context ✅ CORRECT: ❌ WRONG: Why: Workers use ctx.waitUntil() for background tasks (logging, analytics). Without waiting, these tasks may not complete in tests. 3. Each Test Gets Isolated Storage ✅ CORRECT: Why: Each test runs with fresh binding storage (automatic isolation). 4. Use Wrangler Config for Bindings ✅ CORRECT: ❌ WRONG: Why: Wrangler config defines all bindings (D1, KV, R2, etc.). Without it, env will be empty. 5. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills secondsky/cloudflare-workers-testing