Watch mode
Run tests in watch mode to automatically re-run tests when files change:Test file discovery
Bun automatically discovers test files based on naming conventions:- Files with
.test.ts,.test.tsx,.test.js, or.test.jsxextensions - Files with
_test.ts,_test.tsx,_test.js, or_test.jsxextensions - Files in
__tests__directories
Command-line flags
Test execution
number
default:"5000"
Set the per-test timeout in milliseconds
number
default:"unlimited"
Exit the test suite after N failures. If you do not specify a number, it defaults to 1.
number
Re-run each test file N times. Useful for catching flaky tests.
boolean
Only run tests marked with
.only()boolean
Include tests marked with
.todo()boolean
Run tests concurrently by default
Test filtering
string
Filter tests by name using a regular expression
Output & reporting
string
default:"default"
Select a test reporter. Options:
default, dot, junit, only-failuresstring
Write reporter output to a file (for junit reporter)
Coverage
boolean
Generate code coverage report
string
default:"text"
Coverage output format. Options:
text, lcov. Can specify multiple.string
default:"./coverage"
Directory to write coverage reports
Snapshots
boolean
Update snapshots instead of comparing them
Exit codes
Thebun test command will exit with:
0if all tests pass1if any test fails1if no tests are found
Configuration
Test runner behavior can be configured inbunfig.toml: