skills/bun-test-discovery/SKILL.md
Learn how Bun's test runner discovers and filters test files in your project
npx skillsauth add jarle/bun-skills Bun Finding testsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Learn how Bun's test runner discovers and filters test files in your project
bun test's file discovery mechanism determines which files to run as tests. Understanding how it works helps you structure your test files effectively.
By default, bun test recursively searches the project directory for files that match specific patterns:
*.test.{js|jsx|ts|tsx} - Files ending with .test.js, .test.jsx, .test.ts, or .test.tsx*_test.{js|jsx|ts|tsx} - Files ending with _test.js, _test.jsx, _test.ts, or _test.tsx*.spec.{js|jsx|ts|tsx} - Files ending with .spec.js, .spec.jsx, .spec.ts, or .spec.tsx*_spec.{js|jsx|ts|tsx} - Files ending with _spec.js, _spec.jsx, _spec.ts, or _spec.tsxBy default, Bun test ignores:
node_modules directories.)You can filter which test files run by passing additional positional arguments to bun test:
bun test <filter> <filter> ...
Any test file with a path that contains one of the filters will run. These filters are simple substring matches, not glob patterns.
For example, to run all tests in a utils directory:
bun test utils
This would match files like src/utils/string.test.ts and lib/utils/array_test.js.
To run a specific file in the test runner, make sure the path starts with ./ or / to distinguish it from a filter name:
bun test ./test/specific-file.test.ts
To filter tests by name rather than file path, use the -t/--test-name-pattern flag with a regex pattern:
# run all tests with "addition" in the name
bun test --test-name-pattern addition
The pattern is matched against a concatenated string of the test name prepended with the labels of all its parent describe blocks, separated by spaces. For example, a test defined as:
describe("Math", () => {
describe("operations", () => {
test("should add correctly", () => {
// ...
});
});
});
Would be matched against the string "Math operations should add correctly".
By default, Bun looks for test files starting from the current working directory. You can change this with the root option in your bunfig.toml:
[test]
root = "src" # Only scan for tests in the src directory
Tests are run in the following order:
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling