Bun's test runner now supports built-in _code coverage reporting_. This makes it easy to see how much of the codebase is covered by tests, and find areas that are not currently well-tested. ## Enabling coverage `bun:test` supports seeing which lines of code are covered by tests. To use this feature, pass `--coverage` to the CLI. It will print out a coverage report to the console: ```js $ bun test --coverage -------------|---------|---------|------------------- 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 | -------------|---------|---------|------------------- ``` To always enable coverage reporting by default, add the following line to your `bunfig.toml`: ```toml [test] # always enable coverage coverage = true ``` By default coverage reports will _include_ test files and _exclude_ sourcemaps. This is usually what you want, but it can be configured otherwise in `bunfig.toml`. ```toml [test] coverageSkipTestFiles = true # default false ``` ### Coverage thresholds It is possible to specify a coverage threshold in `bunfig.toml`. If your test suite does not meet or exceed this threshold, `bun test` will exit with a non-zero exit code to indicate the failure. ```toml [test] # to require 90% line-level and function-level coverage coverageThreshold = 0.9 # to set different thresholds for lines and functions coverageThreshold = { line = 0.9, function = 0.9 } ``` ### Sourcemaps Internally, Bun transpiles all files by default, so Bun automatically generates an internal [source map](https://web.dev/source-maps/) that maps lines of your original source code onto Bun's internal representation. If for any reason you want to disable this, set `test.coverageIgnoreSourcemaps` to `false`; this will rarely be desirable outside of advanced use cases. ```toml [test] coverageIgnoreSourcemaps = true # default false ``` >dave/import.meta.resolve Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/setTimeout.test.js (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2022-03-15Update Dockerfile.baseGravatar Jarred Sumner 1-1/+1
2022-03-15Add rust and lolhtml to dockerfileGravatar Jarred Sumner 2-0/+20
2022-03-15bump webkitGravatar Jarred Sumner 1-1/+1
2022-03-15Update WebKitGravatar Jarred Sumner 1-0/+0
2022-03-15:camera:Gravatar Jarred Sumner 60-799/+859
2022-03-15Fix test failureGravatar Jarred Sumner 1-15/+17
2022-03-15[bun:error] handle errors without a name or messageGravatar Jarred Sumner 1-6/+11
2022-03-15Update pool.zigGravatar Jarred Sumner 1-0/+1
2022-03-15Load .env by defaultGravatar Jarred Sumner 2-0/+8
2022-03-15mimalloc interpose is buggyGravatar Jarred Sumner 1-2/+25
2022-03-15higher max http requests for bun.jsGravatar Jarred Sumner 1-0/+29
2022-03-15zero copyGravatar Jarred Sumner 1-21/+15
2022-03-15Update javascript.zigGravatar Jarred Sumner 1-2/+0
2022-03-15[bun.js] utf8 console.{time, count, timeEnd, profile, profileEnd, count, ↵Gravatar Jarred Sumner 1-16/+16
countReset}