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

> Format and output test results with built-in reporters

Bun's test runner supports multiple reporters to format test output. Choose the reporter that best fits your workflow.

## Available reporters

### Default reporter

The default reporter shows detailed test results:

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

test/math.test.ts:
✓ addition works
✓ subtraction works
✗ division by zero

  Error: Division by zero
    at divide (src/math.ts:10:11)
    at test/math.test.ts:15:20

test/utils.test.ts:
✓ formatDate
✓ parseJSON

 4 pass
 1 fail
 5 expect() calls
Ran 5 tests across 2 files. 150ms
```

### Dot reporter

Minimal output showing dots for each test:

```bash theme={null}
$ bun test --reporter dot

.....✖

 5 pass
 1 fail
Ran 6 tests across 2 files. 150ms
```

Useful for:

* CI environments with log size limits
* Large test suites where detailed output is noisy
* Quick feedback during development

### JUnit reporter

Generates JUnit XML format for CI integration:

```bash theme={null}
$ bun test --reporter junit --reporter-outfile junit.xml
```

Creates `junit.xml`:

```xml theme={null}
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="bun test" tests="5" failures="1" time="0.150">
  <testsuite name="test/math.test.ts" tests="3" failures="1">
    <testcase name="addition works" time="0.002" />
    <testcase name="subtraction works" time="0.001" />
    <testcase name="division by zero" time="0.005">
      <failure type="AssertionError">Division by zero</failure>
    </testcase>
  </testsuite>
  <testsuite name="test/utils.test.ts" tests="2" failures="0">
    <testcase name="formatDate" time="0.003" />
    <testcase name="parseJSON" time="0.002" />
  </testsuite>
</testsuites>
```

### Only failures reporter

Shows only failing tests:

```bash theme={null}
$ bun test --reporter only-failures

test/math.test.ts:
✗ division by zero

  Error: Division by zero
    at divide (src/math.ts:10:11)
    at test/math.test.ts:15:20

 0 pass
 1 fail
Ran 1 test across 1 file. 150ms
```

Useful for:

* Large test suites where you only care about failures
* CI environments
* Debugging specific failures

## Using reporters

### Single reporter

```bash theme={null}
$ bun test --reporter dot
```

### Multiple reporters

Use multiple reporters simultaneously:

```bash theme={null}
$ bun test --reporter default --reporter junit --reporter-outfile junit.xml
```

## Reporter configuration

### Configure in bunfig.toml

```toml theme={null}
[test]
reporter = "dot"
reporterOutfile = "test-results.xml"
```

### JUnit reporter output

Specify output file:

```bash theme={null}
$ bun test --reporter junit --reporter-outfile results/junit.xml
```

## CI integration

### GitHub Actions

Publish test results:

```yaml theme={null}
name: Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: oven-sh/setup-bun@v1
      
      - run: bun install
      - run: bun test --reporter junit --reporter-outfile junit.xml
      
      - name: Publish test results
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: always()
        with:
          files: junit.xml
```

### GitLab CI

```yaml theme={null}
test:
  script:
    - bun install
    - bun test --reporter junit --reporter-outfile junit.xml
  artifacts:
    when: always
    reports:
      junit: junit.xml
```

### Jenkins

```groovy theme={null}
stage('Test') {
  steps {
    sh 'bun install'
    sh 'bun test --reporter junit --reporter-outfile junit.xml'
  }
  post {
    always {
      junit 'junit.xml'
    }
  }
}
```

### CircleCI

```yaml theme={null}
version: 2.1

jobs:
  test:
    docker:
      - image: oven/bun:1
    steps:
      - checkout
      - run: bun install
      - run:
          name: Run tests
          command: bun test --reporter junit --reporter-outfile junit.xml
      - store_test_results:
          path: junit.xml
```

## Custom output

### Redirect to file

Save test output to a file:

```bash theme={null}
$ bun test > test-output.txt 2>&1
```

### JSON output

For programmatic consumption:

```bash theme={null}
$ bun test --reporter json > results.json
```

Coming soon.

## Reporter behavior

### Color output

Reporters automatically detect TTY and disable colors in non-interactive environments:

```bash theme={null}
# Colors enabled (TTY)
$ bun test

# Colors disabled (pipe)
$ bun test | tee output.txt

# Force colors
$ FORCE_COLOR=1 bun test | tee output.txt
```

### Progress indication

Default reporter shows progress:

```
test/math.test.ts:
✓ test 1
✓ test 2
... (50 more tests)

test/utils.test.ts:
✓ test 1
...
```

### Error formatting

Errors include:

* Error message
* Stack trace
* Source location
* Diff (for equality assertions)

```
✗ addition is incorrect

  Expected: 5
  Received: 4

  - Expected
  + Received

  - 5
  + 4

    at test/math.test.ts:10:20
```

## Performance metrics

All reporters show:

* Number of passed/failed tests
* Number of test files
* Total execution time
* Number of assertions

```
 42 pass
 3 fail
 45 expect() calls
Ran 45 tests across 5 files. 1.2s
```

## Watch mode reporters

In watch mode, reporters show incremental updates:

```bash theme={null}
$ bun test --watch --reporter dot

Watching for changes...

......

 6 pass
Ran 6 tests across 2 files. 150ms

[1:23:45 PM] File changed: src/math.ts

.......

 7 pass
Ran 7 tests across 2 files. 120ms
```

## Troubleshooting

### No output file created

Ensure you specify `--reporter-outfile`:

```bash theme={null}
$ bun test --reporter junit --reporter-outfile junit.xml
```

### Invalid XML in JUnit output

Ensure test names don't contain invalid XML characters. Bun automatically escapes them.

### Colors not working

Force color output:

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

Or disable:

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

## Related

* [bun test command](/cli/test)
* [Configuration](/test/configuration)
* [Writing Tests](/test/writing)
