Skip to main content
Bun ships with a fast, built-in, Jest-compatible test runner. Tests are executed with the Bun runtime, and support TypeScript and JSX out of the box.

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.jsx extensions
  • Files with _test.ts, _test.tsx, _test.js, or _test.jsx extensions
  • 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-failures
string
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
See Code Coverage for more details.

Snapshots

boolean
Update snapshots instead of comparing them
See Snapshot Testing for more details.

Exit codes

The bun test command will exit with:
  • 0 if all tests pass
  • 1 if any test fails
  • 1 if no tests are found

Configuration

Test runner behavior can be configured in bunfig.toml:
See Test Configuration for all available options.