> ## 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.

# bun test

> Run tests with Bun's fast, Jest-compatible test runner

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.

```bash theme={null}
$ bun test
```

## Watch mode

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

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

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

<ParamField path="--timeout" type="number" default="5000">
  Set the per-test timeout in milliseconds

  ```bash theme={null}
  $ bun test --timeout 10000
  ```
</ParamField>

<ParamField path="--bail" type="number" default="unlimited">
  Exit the test suite after N failures. If you do not specify a number, it defaults to 1.

  ```bash theme={null}
  $ bun test --bail
  $ bun test --bail 3
  ```
</ParamField>

<ParamField path="--rerun-each" type="number">
  Re-run each test file N times. Useful for catching flaky tests.

  ```bash theme={null}
  $ bun test --rerun-each 10
  ```
</ParamField>

<ParamField path="--only" type="boolean">
  Only run tests marked with `.only()`

  ```bash theme={null}
  $ bun test --only
  ```
</ParamField>

<ParamField path="--todo" type="boolean">
  Include tests marked with `.todo()`

  ```bash theme={null}
  $ bun test --todo
  ```
</ParamField>

<ParamField path="--concurrent" type="boolean">
  Run tests concurrently by default

  ```bash theme={null}
  $ bun test --concurrent
  ```
</ParamField>

### Test filtering

<ParamField path="--test-name-pattern" type="string">
  Filter tests by name using a regular expression

  ```bash theme={null}
  $ bun test --test-name-pattern "auth"
  ```
</ParamField>

### Output & reporting

<ParamField path="--reporter" type="string" default="default">
  Select a test reporter. Options: `default`, `dot`, `junit`, `only-failures`

  ```bash theme={null}
  $ bun test --reporter dot
  $ bun test --reporter junit --reporter-outfile junit.xml
  ```
</ParamField>

<ParamField path="--reporter-outfile" type="string">
  Write reporter output to a file (for junit reporter)

  ```bash theme={null}
  $ bun test --reporter junit --reporter-outfile report.xml
  ```
</ParamField>

### Coverage

<ParamField path="--coverage" type="boolean">
  Generate code coverage report

  ```bash theme={null}
  $ bun test --coverage
  ```
</ParamField>

<ParamField path="--coverage-reporter" type="string" default="text">
  Coverage output format. Options: `text`, `lcov`. Can specify multiple.

  ```bash theme={null}
  $ bun test --coverage --coverage-reporter text
  $ bun test --coverage --coverage-reporter lcov --coverage-reporter text
  ```
</ParamField>

<ParamField path="--coverage-dir" type="string" default="./coverage">
  Directory to write coverage reports

  ```bash theme={null}
  $ bun test --coverage --coverage-dir my-coverage
  ```
</ParamField>

See [Code Coverage](/test/coverage) for more details.

### Snapshots

<ParamField path="--update-snapshots" type="boolean">
  Update snapshots instead of comparing them

  ```bash theme={null}
  $ bun test --update-snapshots
  ```
</ParamField>

See [Snapshot Testing](/test/snapshots) 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`:

```toml theme={null}
[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](/test/configuration) for all available options.

## Related

* [Writing Tests](/test/writing)
* [Lifecycle Hooks](/test/lifecycle)
* [Mocks](/test/mocks)
* [Snapshots](/test/snapshots)
