skills/bun-guides-test-coverage-threshold/SKILL.md
Set a code coverage threshold with the Bun test runner
npx skillsauth add jarle/bun-skills Bun Set a code coverage threshold with the Bun test runnerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Bun's test runner supports built-in code coverage reporting via the --coverage flag.
bun test --coverage
test.test.ts:
✓ math > add [0.71ms]
✓ math > multiply [0.03ms]
✓ random [0.13ms]
-------------|---------|---------|-------------------
File | % Funcs | % Lines | Uncovered Line #s
-------------|---------|---------|-------------------
All files | 66.67 | 77.78 |
math.ts | 50.00 | 66.67 |
random.ts | 50.00 | 66.67 |
-------------|---------|---------|-------------------
3 pass
0 fail
3 expect() calls
To set a minimum coverage threshold, add the following line to your bunfig.toml. This requires that 90% of your codebase is covered by tests.
[test]
# to require 90% line-level and function-level coverage
coverageThreshold = 0.9
If your test suite does not meet this threshold, bun test will exit with a non-zero exit code to signal a failure.
bun test --coverage
<test output>
$ echo $?
1 # this is the exit code of the previous command
Different thresholds can be set for line-level and function-level coverage.
[test]
# to set different thresholds for lines and functions
coverageThreshold = { lines = 0.5, functions = 0.7 }
See Docs > Test runner > Coverage for complete documentation on code coverage reporting in Bun.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling