> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Configuration

> Configure Bun's test runner behavior via bunfig.toml

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):

```toml theme={null}
[test]
timeout = 10000  # 10 seconds
```

This can be overridden per-test:

```ts theme={null}
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:

```toml theme={null}
[test]
preload = [
  "./test/setup.ts",
  "./test/polyfills.ts"
]
```

Preloaded files run before any test files are loaded.

### Concurrency

Run tests concurrently by default:

```toml theme={null}
[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:

```toml theme={null}
[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:

```toml theme={null}
[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:

```toml theme={null}
[test]
[test.coverageThreshold]
line = 80
function = 80
statement = 80
branch = 80
```

All thresholds are percentages (0-100).

#### coverageReporter

Configure default coverage reporters:

```toml theme={null}
[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:

```toml theme={null}
[test]
root = "./src"
```

## Environment variables

You can also configure tests via environment variables:

### BUN\_TEST\_TIMEOUT

Set default test timeout:

```bash theme={null}
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

```bash theme={null}
CI=true bun test
```

## Complete example

Here's a comprehensive `bunfig.toml` configuration:

```toml theme={null}
[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/
```

## Related

* [bun test command](/cli/test)
* [Writing Tests](/test/writing)
* [Code Coverage](/test/coverage)
