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’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:
$ 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:
$ 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:
$ bun test --reporter junit --reporter-outfile junit.xml
Creates junit.xml:
<?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:
$ 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
$ bun test --reporter dot
Multiple reporters
Use multiple reporters simultaneously:
$ bun test --reporter default --reporter junit --reporter-outfile junit.xml
Reporter configuration
[test]
reporter = "dot"
reporterOutfile = "test-results.xml"
JUnit reporter output
Specify output file:
$ bun test --reporter junit --reporter-outfile results/junit.xml
CI integration
GitHub Actions
Publish test results:
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
test:
script:
- bun install
- bun test --reporter junit --reporter-outfile junit.xml
artifacts:
when: always
reports:
junit: junit.xml
Jenkins
stage('Test') {
steps {
sh 'bun install'
sh 'bun test --reporter junit --reporter-outfile junit.xml'
}
post {
always {
junit 'junit.xml'
}
}
}
CircleCI
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:
$ bun test > test-output.txt 2>&1
JSON output
For programmatic consumption:
$ bun test --reporter json > results.json
Coming soon.
Reporter behavior
Color output
Reporters automatically detect TTY and disable colors in non-interactive environments:
# 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
...
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
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:
$ 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:
$ 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:
Or disable: