Skip to main content
Bun has built-in code coverage reporting. Pass --coverage to see which lines and functions are exercised by your tests.

Enabling coverage

Bun prints a coverage summary to the console after the test run:
  • % Funcs — percentage of functions called during tests
  • % Lines — percentage of executable lines that were run
  • Uncovered Line #s — specific lines that were not executed

Always-on coverage

Enable coverage by default in bunfig.toml:
bunfig.toml

Coverage thresholds

Fail the test run if coverage falls below a specified level. This is useful in CI to enforce minimum quality gates.

Simple threshold

Apply the same threshold to lines, functions, and statements:
bunfig.toml

Per-metric thresholds

Set different thresholds for each coverage metric:
bunfig.toml
When any threshold is configured, bun test exits with a non-zero code if coverage is below the threshold.

Coverage reporters

By default, coverage is printed as a text table. Use coverageReporter to add additional output formats:
bunfig.toml
Via CLI:

LCOV integration

The LCOV format is supported by a wide range of tools:

VS Code

Extensions like Coverage Gutters can display coverage inline in the editor using the lcov.info file.

Codecov / Coveralls

Upload coverage/lcov.info as a coverage artifact to track coverage trends over time.

GitHub Actions

Use the codecov/codecov-action to upload and comment on PRs automatically.

GitLab CI

Configure coverage_report artifacts to display coverage in merge requests.

Excluding files from coverage

Skip test files

By default, test files themselves are included in the coverage report. Exclude them with:
bunfig.toml

Path ignore patterns

Exclude specific files or directories using glob patterns:
bunfig.toml
Files matching any pattern are excluded from both the text summary and any generated report files.

CI/CD integration

GitHub Actions

.github/workflows/test.yml

GitLab CI

.gitlab-ci.yml

Running coverage on a subset of tests

Run coverage for specific files or patterns:

Sourcemaps

Bun transpiles all files internally and automatically applies sourcemaps so that coverage reports reference your original source lines. To disable this (rarely needed):
bunfig.toml
When disabling sourcemaps, add // @bun at the top of source files to opt out of transpilation, otherwise line numbers will be confusing.

Coverage defaults

By default, coverage reports:
  • Exclude node_modules directories
  • Exclude files loaded through non-JS/TS loaders (e.g., .css, .txt)
  • Include test files (disable with coverageSkipTestFiles = true)

Best practices

High coverage does not guarantee good tests. Write assertions that verify behavior, not just lines that execute without throwing.
Run bun test --coverage periodically to identify untested branches. Use the uncovered line numbers to guide where to add tests next.
Coverage instrumentation adds overhead. For fast feedback during development, run tests without --coverage and let CI enforce thresholds.