Skip to main content
Bun’s test runner has built-in code coverage reporting. Enable it with the --coverage flag.
terminal

To set a minimum coverage threshold, add the following to your bunfig.toml. A threshold of 0.9 requires that tests cover 90% of the lines and 90% of the functions of every file in the coverage report. Bun checks the threshold against each file, not against the All files average.
bunfig.toml

If your test suite does not meet this threshold, bun test exits with a non-zero exit code to signal a failure.
terminal

You can set different thresholds for line-level and function-level coverage.
bunfig.toml

See Code coverage.