Built-in Reporters
Default Console Reporter
By default, bun test outputs results to the console in a human-readable format:terminal
terminal
JUnit XML Reporter
For CI/CD environments, Bun supports generating JUnit XML reports. JUnit XML is a widely-adopted format for test results that can be parsed by many CI/CD systems, including GitLab, Jenkins, and others.Using the JUnit Reporter
To generate a JUnit XML report, use the--reporter=junit flag along with --reporter-outfile to specify the output file:
terminal
Configuring via bunfig.toml
You can also configure the JUnit reporter in yourbunfig.toml file:
bunfig.toml
Environment Variables in JUnit Reports
The JUnit reporter automatically includes environment information as<properties> in the XML output. This can be helpful for tracking test runs in CI environments.
Specifically, it includes the following environment variables when available:
| Environment Variable | Property Name | Description |
|---|---|---|
GITHUB_RUN_ID, GITHUB_SERVER_URL, GITHUB_REPOSITORY, CI_JOB_URL | ci | CI build information |
GITHUB_SHA, CI_COMMIT_SHA, GIT_SHA | commit | Git commit identifiers |
| System hostname | hostname | Machine hostname |
Current Limitations
The JUnit reporter currently has a few limitations that will be addressed in future updates:stdoutandstderroutput from individual tests are not included in the report- Precise timestamp fields per test case are not included
GitHub Actions reporter
Bun test automatically detects when it’s running inside GitHub Actions and emits GitHub Actions annotations to the console directly. No special configuration is needed beyond installing Bun and runningbun test.
For a GitHub Actions workflow configuration example, see the CI/CD integration section of the CLI documentation.
Custom Reporters
Bun allows developers to implement custom test reporters by extending the WebKit Inspector Protocol with additional testing-specific domains.Inspector Protocol for Testing
To support test reporting, Bun extends the standard WebKit Inspector Protocol with two custom domains:- TestReporter: Reports test discovery, execution start, and completion events
- LifecycleReporter: Reports errors and exceptions during test execution
Key Events
Custom reporters can listen for these key events:TestReporter.found: Emitted when a test is discoveredTestReporter.start: Emitted when a test starts runningTestReporter.end: Emitted when a test completesConsole.messageAdded: Emitted when console output occurs during a testLifecycleReporter.error: Emitted when an error or exception occurs