Skip to main content
Configure bun test via bunfig.toml and command-line flags. CLI flags always take precedence over configuration file values.

bunfig.toml

Add a [test] section to your bunfig.toml file to configure the test runner:
bunfig.toml

Test discovery

root

Set the root directory for test file scanning. By default, Bun scans from the current working directory.
bunfig.toml

pathIgnorePatterns

Exclude files and directories from test discovery using glob patterns. Matched directories are pruned during scanning — their contents are never traversed.
bunfig.toml
This is equivalent to the --path-ignore-patterns CLI flag. Note that CLI flags override the config file value entirely — they are not merged.

Preload scripts

Run setup scripts before any test files with preload. This is the recommended way to configure global state, mocks, or DOM environments.
bunfig.toml
Equivalent CLI usage:

Example setup file

setup.ts

Example global mocks file

global-mocks.ts

Timeouts

Default timeout

Set the default timeout (in milliseconds) for all tests. Individual tests can override this with a third argument to test().
bunfig.toml
Use 0 or Infinity in test() to disable timeout for a specific test:

Environment variables

Bun automatically loads .env files from the project root. For test-specific variables, create a .env.test file and load it explicitly:
.env.test
bun test automatically sets NODE_ENV to "test" unless it is already defined in the environment or an .env file.

TypeScript

Bun compiles TypeScript natively — no extra configuration is needed. To use a custom tsconfig.json for tests:

Test execution settings

randomize and seed

Run tests in random order to detect hidden dependencies:
bunfig.toml

retry

Set a global retry count for flaky tests:
bunfig.toml

rerunEach

Re-run each test file multiple times to detect non-deterministic failures:
bunfig.toml

concurrentTestGlob

Run test files matching a glob pattern with concurrent execution enabled automatically:
bunfig.toml

smol

Reduce memory usage during test runs (useful in memory-constrained CI environments):
bunfig.toml

Reporters

Configure the JUnit XML reporter output path in bunfig.toml:
bunfig.toml
Equivalent CLI usage:

Coverage

Enable coverage reporting and configure thresholds:
bunfig.toml
See Code Coverage for full documentation.

Install settings inheritance

bun test inherits relevant settings from the [install] section of bunfig.toml, including registry, prefer, and exact. This matters when tests trigger auto-installs or interact with a private registry.
bunfig.toml

Complete example

bunfig.toml