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
Set the per-test timeout in milliseconds
Exit the test suite after N failures. If you do not specify a number, it defaults to 1.
Re-run each test file N times. Useful for catching flaky tests.
Only run tests marked with
.only()Include tests marked with
.todo()Run tests concurrently by default
Test filtering
Filter tests by name using a regular expression
Output & reporting
Select a test reporter. Options:
default, dot, junit, only-failuresWrite reporter output to a file (for junit reporter)
Coverage
Generate code coverage report
Coverage output format. Options:
text, lcov. Can specify multiple.Directory to write coverage reports
Snapshots
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: