diff options
author | 2023-08-06 06:30:23 -0700 | |
---|---|---|
committer | 2023-08-06 06:30:23 -0700 | |
commit | 14624454196370e08309d4f0b0463b494e4df9ca (patch) | |
tree | 538421bfffc3d804807a4ec70a1323fbcbe3416f /docs/test/coverage.md | |
parent | ecdf2ffa6c615d8a431c2919c0b9bdc4cbe2c4f0 (diff) | |
download | bun-14624454196370e08309d4f0b0463b494e4df9ca.tar.gz bun-14624454196370e08309d4f0b0463b494e4df9ca.tar.zst bun-14624454196370e08309d4f0b0463b494e4df9ca.zip |
Code coverage for `bun test` (#3975)
* WIP code coverage initial commit
* almost works
* one approach
* Code Coverage
* Update WebKit
* it works but is not yet accurate
* skip double ascii check
* wrapper
* it works but i'm not sure what to do about blocks
* hide blocks for now
* Update ZigSourceProvider.cpp
* Create coverage.md
* Update nav.ts
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'docs/test/coverage.md')
-rw-r--r-- | docs/test/coverage.md | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/docs/test/coverage.md b/docs/test/coverage.md new file mode 100644 index 000000000..abf8cf94c --- /dev/null +++ b/docs/test/coverage.md @@ -0,0 +1,57 @@ +`bun:test` supports seeing which lines of code are covered by tests. To use this feature, pass `--coverage` to the CLI: + +```sh +bun test --coverage +``` + +It will print out a coverage report to the console: + +```js +-------------|---------|---------|------------------- +File | % Funcs | % Lines | Uncovered Line #s +-------------|---------|---------|------------------- +All files | 38.89 | 42.11 | + index-0.ts | 33.33 | 36.84 | 10-15,19-24 + index-1.ts | 33.33 | 36.84 | 10-15,19-24 + index-10.ts | 33.33 | 36.84 | 10-15,19-24 + index-2.ts | 33.33 | 36.84 | 10-15,19-24 + index-3.ts | 33.33 | 36.84 | 10-15,19-24 + index-4.ts | 33.33 | 36.84 | 10-15,19-24 + index-5.ts | 33.33 | 36.84 | 10-15,19-24 + index-6.ts | 33.33 | 36.84 | 10-15,19-24 + index-7.ts | 33.33 | 36.84 | 10-15,19-24 + index-8.ts | 33.33 | 36.84 | 10-15,19-24 + index-9.ts | 33.33 | 36.84 | 10-15,19-24 + index.ts | 100.00 | 100.00 | +-------------|---------|---------|------------------- +``` + +If coverage is below a threshold, `bun:test` will exit with a non-zero exit code to indicate the failure. + +### Configuring coverage + +`bunfig.toml` supports configuring coverage: + +```toml +[test] + +# Always enable coverage +coverage = true + +# Anything less than 90% coverage will fail the test +# coverageThreshold = 0.9 +coverageThreshold = { line = 0.9, function = 0.9 } + + +# Don't include .test.* files in coverage reports +coverageSkipTestFiles = true + +# Disable sourcemap support in coverage reports +# By default, coverage reports will automatically use Bun's internal sourcemap. +# You probably don't want to configure this +# coverageIgnoreSourcemaps = false +``` + +`coverageThreshold` can be either a number or an object with `line` and `function` keys. When a number, it is treated as both the line and function threshold. + +Coverage support was added in Bun v0.7.2. |