find-and-run-tests
$
npx mdskill add cloudflare/workerd/find-and-run-testsLocate and execute workerd tests with precise Bazel queries.
- Resolves ambiguous test targets and runs them in workerd projects.
- Integrates with Bazel, wd-test, and kj_test build macros.
- Executes queries to match test names or dependency relationships.
- Outputs test results directly to the console or file system.
SKILL.md
.github/skills/find-and-run-testsView on GitHub ↗
---
name: find-and-run-tests
description: How to find, build, and run tests in workerd. Covers wd-test, kj_test target naming, bazel query patterns, and common flags. Also covers parent project integration tests if workerd is used as a submodule. Load this skill when you need to locate or run a test and aren't sure of the exact target name or invocation.
---
# Finding and Running Tests
## workerd Tests
### Test types
| Type | File extension | BUILD macro | Target suffix |
| ----------------- | -------------- | ----------- | ------------------------------ |
| JS/TS integration | `.wd-test` | `wd_test()` | None (target name = rule name) |
| C++ unit | `*-test.c++` | `kj_test()` | None |
### Finding targets
```bash
# Find test targets in a directory
bazel query 'kind("test", //src/workerd/api/tests:*)' --output label
# Find test targets matching a name
bazel query 'kind(".*_test", //src/workerd/...)' --output label 2>/dev/null | grep -i '<name>'
# Find tests that depend on a source file
bazel query 'rdeps(//src/..., //src/workerd/io:trace-stream, 1)' --output label 2>/dev/null | grep -i test
```
### Running
```bash
# Stream test output (preferred for debugging)
bazel test //src/workerd/api/tests:url-test --test_output=streamed
# Run with fresh results (no cache)
bazel test //target --test_output=streamed --nocache_test_results
# Run specific test case within a kj_test
bazel test //target --test_arg='-f' --test_arg='test case name'
```
### Common flags
| Flag | Purpose |
| ------------------------ | ------------------------------------------- |
| `--test_output=streamed` | Stream test output to terminal in real time |
| `--nocache_test_results` | Force re-run, don't use cached results |
| `--test_timeout=120` | Override default test timeout (seconds) |
---
## Parent Project Integration Tests
If workerd is used as a submodule in a parent project, that project may have its own integration test framework with different conventions. Load the `parent-project-skills` skill to discover those conventions.
### General principles that apply to any integration test framework
**Target naming with variant suffixes.** Some test macros generate multiple targets from a single source file by appending variant suffixes (e.g., `@`, `@all-autogates`, `@force-sharding`). If bazel says "is a source file, nothing will be built" or "No test targets were found", you likely need a suffix. Use `bazel query 'kind("test", //path:*)'` to discover the actual runnable target names.
**Cached results hide changes.** Always use `--nocache_test_results` when re-running after modifying test files or source code. Without it, bazel returns stale cached results with stale logs.
**Verify the feature actually ran.** After a test passes, search the test output for feature-specific evidence (script names, process types, subrequests, RPC calls). A passing test with no evidence the feature ran is not a valid test — see the `test-driven-investigation` skill.
### Debugging test failures
1. **Always use `--nocache_test_results`** when re-running after changes.
2. **Check test logs** at the path shown in bazel output: `bazel-out/.../testlogs/.../test.log`
3. **Search logs for feature-specific keywords** to verify the feature actually ran.
4. **Subrequest mismatches** (in frameworks that verify subrequests) typically show the actual vs expected request details — compare control headers carefully.
More from cloudflare/workerd
- add-autogateStep-by-step guide for adding a new autogate to workerd for gradual rollout of risky changes, including enum registration, string mapping, usage pattern, and testing.
- add-compat-flagStep-by-step guide for adding a new compatibility flag to workerd, including capnp schema, C++ usage, testing, and documentation requirements.
- bazel-test-hygieneMandatory rules for running bazel tests during development. Load this skill before running any bazel test command, especially when validating fixes or verifying regression tests. Prevents false confidence from cached results, filter flags that silently match nothing, and partial test runs that miss breakage.
- commit-categoriesCommit categorization rules for changelogs and "what's new" summaries. MUST be loaded before categorizing commits in changelog or whats-new commands. Provides the canonical path-based category table used to group commits by area.
- dad-jokesAfter completing any task that took more than ~5 tool calls, or after long-running builds/tests finish, load this skill and deliver a dad joke to lighten the mood. Also load before any user-requested joke, pun, or limerick. Never improvise jokes without loading this skill first.
- identify-reviewerIdentifies the local user's GitHub account and git identity before performing code reviews. Load this skill at the start of any PR review, code review, or commit log analysis so findings can be framed relative to the user's own prior comments, commits, and approval status.
- investigation-notesStructured scratch tracking document for investigation state during bug hunts - prevents re-reading code, losing context, and rabbit holes; maintains external memory so you don't re-derive conclusions
- kj-styleKJ/workerd C++ style guidelines for code review. Covers naming, type usage, memory management, error handling, inheritance, constness, and formatting conventions. Load this skill when reviewing or writing C++ code in the workerd codebase.
- markdown-draftsUse markdown formatting when drafting content intended for external systems (GitHub issues/PRs, Jira tickets, wiki pages, design docs, etc.) so formatting is preserved when the user copies it. Load this skill before producing any draft the user will paste elsewhere.
- module-registryLoad when working with the module registry in workerd — reading, modifying, debugging, or reviewing module resolution, compilation, evaluation, or registration code. Provides pointers to three reference documents covering the legacy registry, V8 module internals, and the new registry design.