secondsky/claude-skills / plugins/cloudflare-workers/skills/cloudflare-workers-testing
cloudflare-workers-testing
VerifiedComprehensive 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 20.6 KB |
| references/binding-mocks.md | markdown | 12.1 KB |
| references/coverage-optimization.md | markdown | 7.4 KB |
| references/integration-testing.md | markdown | 8.9 KB |
| references/troubleshooting.md | markdown | 7.3 KB |
| references/vitest-setup.md | markdown | 6.8 KB |
| scripts/run-tests.sh | script | 4.2 KB |
| scripts/setup-vitest.sh | script | 5.0 KB |
| templates/basic-test.ts | script | 5.3 KB |
| templates/binding-mock-test.ts | script | 8.7 KB |
| templates/vitest-config.ts | script | 3.0 KB |
templates/vitest-config.ts
View on GitHub/**
* Complete Vitest Configuration for Cloudflare Workers
*
* Features:
* - Loads bindings from wrangler.jsonc
* - Miniflare v3 with latest compatibility
* - Coverage with thresholds
* - TypeScript support
* - Test isolation (automatic)
*
* Usage:
* 1. Copy to project root as vitest.config.ts
* 2. Update wrangler configPath if needed
* 3. Adjust coverage thresholds as needed
* 4. Run: bunx vitest
*/
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
export default defineWorkersConfig({
test: {
// Use Workers pool for edge runtime testing
poolOptions: {
workers: {
// Load bindings from wrangler configuration
wrangler: {
configPath: './wrangler.jsonc', // Update if using wrangler.toml
environment: process.env.VITEST_ENV || 'development' // Support env-specific config
},
// Miniflare configuration
miniflare: {
// Match production runtime
compatibilityDate: '2025-01-27',
// Enable Node.js compatibility if needed
compatibilityFlags: [
'nodejs_compat', // For Node.js APIs
// 'streams_enable_constructors', // If using streams
],
// Custom bindings for testing (override wrangler if needed)
bindings: {
ENVIRONMENT: 'test',
// Add test-specific vars here
},
// Prevent real network requests in tests (optional)
// fetchMock: {
// disableNetConnect: true
// }
},
// Parallel workers (default: CPU cores)
workers: 4
}
},
// Coverage configuration
coverage: {
provider: 'v8', // Use V8 coverage (recommended)
// Coverage reporters
reporter: [
'text', // Terminal output
'json', // JSON for programmatic access
'html', // Interactive browser report
'lcov' // For Codecov/Coveralls
],
// Files to include in coverage
include: [
'src/**/*.ts',
'src/**/*.tsx'
],
// Files to exclude from coverage
exclude: [
'src/**/*.test.ts',
'src/**/*.spec.ts',
'src/**/*.test.tsx',
'src/types/**',
'src/**/*.d.ts',
'node_modules/**'
],
// Coverage thresholds (adjust as needed)
thresholds: {
lines: 80, // 80% of lines must be covered
functions: 80, // 80% of functions must be covered
branches: 75, // 75% of branches must be covered
statements: 80 // 80% of statements must be covered
},
// Apply thresholds per file (more strict)
// perFile: true,
// Auto-update thresholds
// autoUpdate: true,
},
// Global test timeout (30 seconds)
testTimeout: 30000,
// Setup files to run before tests
// setupFiles: ['./test/setup.ts'],
// Globals (if using expect without import)
// globals: true,
},
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |