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.
$ bun test

Watch mode

Run tests in watch mode to automatically re-run tests when files change:
$ bun test --watch

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
# Run all test files
$ bun test

# Run specific test file
$ bun test path/to/file.test.ts

# Run tests matching a pattern
$ bun test --test-name-pattern "should handle"

Command-line flags

Test execution

--timeout
number
default:"5000"
Set the per-test timeout in milliseconds
$ bun test --timeout 10000
--bail
number
default:"unlimited"
Exit the test suite after N failures. If you do not specify a number, it defaults to 1.
$ bun test --bail
$ bun test --bail 3
--rerun-each
number
Re-run each test file N times. Useful for catching flaky tests.
$ bun test --rerun-each 10
--only
boolean
Only run tests marked with .only()
$ bun test --only
--todo
boolean
Include tests marked with .todo()
$ bun test --todo
--concurrent
boolean
Run tests concurrently by default
$ bun test --concurrent

Test filtering

--test-name-pattern
string
Filter tests by name using a regular expression
$ bun test --test-name-pattern "auth"

Output & reporting

--reporter
string
default:"default"
Select a test reporter. Options: default, dot, junit, only-failures
$ bun test --reporter dot
$ bun test --reporter junit --reporter-outfile junit.xml
--reporter-outfile
string
Write reporter output to a file (for junit reporter)
$ bun test --reporter junit --reporter-outfile report.xml

Coverage

--coverage
boolean
Generate code coverage report
$ bun test --coverage
--coverage-reporter
string
default:"text"
Coverage output format. Options: text, lcov. Can specify multiple.
$ bun test --coverage --coverage-reporter text
$ bun test --coverage --coverage-reporter lcov --coverage-reporter text
--coverage-dir
string
default:"./coverage"
Directory to write coverage reports
$ bun test --coverage --coverage-dir my-coverage
See Code Coverage for more details.

Snapshots

--update-snapshots
boolean
Update snapshots instead of comparing them
$ bun test --update-snapshots
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:
[test]
# Set default timeout
timeout = 10000

# Coverage settings
coverageSkipTestFiles = true
coveragePathIgnorePatterns = ["node_modules", "*.config.ts"]

# Pre-load modules before running tests
preload = ["./setup.ts"]

# Set concurrency
concurrent = true
See Test Configuration for all available options.

Build docs developers (and LLMs) love