Skip to main content
You can configure Bun’s test runner behavior in your bunfig.toml file under the [test] section.

Configuration options

Timeout

Set the default timeout for all tests (in milliseconds):
[test]
timeout = 10000  # 10 seconds
This can be overridden per-test:
test("custom timeout", async () => {
  // ...
}, 30000); // 30 second timeout

Preload

Specify modules to load before running tests. This is useful for setting up global test utilities or mocking:
[test]
preload = [
  "./test/setup.ts",
  "./test/polyfills.ts"
]
Preloaded files run before any test files are loaded.

Concurrency

Run tests concurrently by default:
[test]
concurrent = true
This is equivalent to running bun test --concurrent or marking individual tests with .concurrent().

Coverage

coverageSkipTestFiles

Exclude test files from coverage reports:
[test]
coverageSkipTestFiles = true
By default, test files are included in coverage reports. Set this to true to exclude them.

coveragePathIgnorePatterns

Specify patterns to exclude from coverage:
[test]
coveragePathIgnorePatterns = [
  "node_modules",
  "*.config.ts",
  "test/fixtures"
]
Patterns use glob syntax. Files matching any pattern will be excluded from coverage reports.

coverageThreshold

Set minimum coverage thresholds. Tests will fail if coverage is below these values:
[test]
[test.coverageThreshold]
line = 80
function = 80
statement = 80
branch = 80
All thresholds are percentages (0-100).

coverageReporter

Configure default coverage reporters:
[test]
coverageReporter = ["text", "lcov"]
Available reporters:
  • text - Human-readable text output to console
  • lcov - LCOV format (can be used with coverage visualization tools)

Root directory

Set the root directory for test discovery:
[test]
root = "./src"

Environment variables

You can also configure tests via environment variables:

BUN_TEST_TIMEOUT

Set default test timeout:
BUN_TEST_TIMEOUT=10000 bun test

CI

When CI=true is set, Bun makes the following changes:
  • Disables interactive snapshot updates
  • Fails tests if new snapshots are created (unless --update-snapshots is used)
  • Changes error output formatting
CI=true bun test

Complete example

Here’s a comprehensive bunfig.toml configuration:
[test]
# Test execution
timeout = 10000
concurrent = true
root = "./src"

# Preload files
preload = [
  "./test/setup.ts",
  "./test/global-mocks.ts"
]

# Coverage
coverageSkipTestFiles = true
coverageReporter = ["text", "lcov"]
coveragePathIgnorePatterns = [
  "node_modules",
  "*.config.ts",
  "test/fixtures",
  "*.mock.ts"
]

# Coverage thresholds
[test.coverageThreshold]
line = 80
function = 75
statement = 80
branch = 70

Per-directory configuration

You can have multiple bunfig.toml files in different directories. Bun will use the closest configuration file when running tests:
project/
├── bunfig.toml          # Root config
├── src/
│   └── bunfig.toml      # Overrides for src/
└── test/
    └── bunfig.toml      # Overrides for test/

Build docs developers (and LLMs) love