workerd has a comprehensive test suite covering C++ unit tests, JavaScript runtime tests, Node.js compatibility tests, and Web Platform Tests.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/workerd/llms.txt
Use this file to discover all available pages before exploring further.
Test types
.wd-test files
.wd-test files are Cap’n Proto config files that define test workers. These are the primary way to test JavaScript APIs and worker behavior.
modules- Embed JavaScript/TypeScript filescompatibilityFlags- Enable specific compatibility behaviorsbindings- Service bindings, JSON, KV, and other resourcesdurableObjectNamespaces- Durable Object configurations
.js or .ts file:
C++ unit tests
KJ-based unit tests use thekj_test() Bazel macro:
Node.js compatibility tests
Run specific Node.js compatibility tests:Web Platform Tests
Run Web Platform Tests:Running tests
Run all tests
Run a specific test
Stream test output for debugging
Watch mode
Automatically re-run tests when files change:Test variants
Every test automatically generates multiple variants:name@- Default variant (oldest compat date, 2000-01-01)name@all-compat-flags- Newest compat date (2999-12-31), all flags enabledname@all-autogates- All autogates enabled + oldest compat date
The
@ suffix is required in target names. For example: //src/workerd/io:io-gate-test@BUILD.bazel file in the same directory for wd_test() or kj_test() rules:
Creating new tests
Scaffold a new test
Scaffold a new WPT test
Testing best practices
Do not submit untested code
If you are not able to build your code and run it locally to verify that it does what you expect, do not submit code changes. Include unit tests for any new functionality you add.Test at the right level
- JavaScript APIs - Use
.wd-testfiles - C++ implementation details - Use C++ unit tests
- Node.js compatibility - Use or extend Node.js compat tests
- Web standards - Use or extend Web Platform Tests
Write focused tests
Each test should verify one specific behavior:Test error cases
Don’t just test the happy path:Use appropriate assertions
Benchmarks
Run performance benchmarks:Code coverage
Generate a code coverage report (Linux only):Debugging tests
Stream output
By default, test output is buffered. Stream output for debugging:AddressSanitizer
Run tests with AddressSanitizer to detect memory errors:Test organization
Tests should live near the code they test:Compatibility flags in tests
When testing features behind compatibility flags:Next steps
Documentation guidelines
Learn about documentation requirements
I/O subsystem
Understand the I/O architecture