aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/test/coverage.md
blob: a09d8103a55a815e98978eb1f974dfe99a882368 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
name: Generate code coverage reports with the Bun test runner
---

Bun's test runner 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.

---

Pass the `--coverage` flag to `bun test` to enable this feature. This will print a coverage report after the test run.

The coverage report lists the source files that were executed during the test run, the percentage of functions and lines that were executed, and the line ranges that were not executed during the run.

```sh
$ 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 always enable coverage reporting by default, add the following line to your `bunfig.toml`:

```toml
[test]
coverage = true # always enable coverage
```

---

Refer to [Docs > Test runner > Coverage](/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
thub-api-option&id=62541f1ac89bbca1318838dce1bf82a014bddb8a&follow=1'>`path.normalize()` tests passGravatar Jarred Sumner 2-146/+213 2022-02-03Fix test failures in path.joinGravatar Jarred Sumner 1-8/+115 2022-02-03Update mimalloc_arena.zigGravatar Jarred Sumner 1-0/+9 2022-02-03[bun test] Support multiple filesGravatar Jarred Sumner 1-2/+12 2022-02-03Update js_ast.zigGravatar Jarred Sumner 1-0/+1 2022-02-03Support loading multiple entry points by changing what `bun:main` points toGravatar Jarred Sumner 6-4/+36 2022-02-03[bun install] Configurable max http retry countGravatar Jarred Sumner 1-0/+7 2022-02-03Missing newline in errors in bun installGravatar Jarred Sumner 1-4/+8 2022-02-03Fix bug with http clientGravatar Jarred Sumner 6-107/+101 2022-02-03Move detectFastRefresh to later so HTTP request handler starts fasterGravatar Jarred Sumner 1-2/+1 2022-02-03Fix bug with macro remaps in Bun.Transpiler apiGravatar Jarred Sumner 2-5/+8 2022-02-03Slight improvement to non-ascii file path handlingGravatar Jarred Sumner 4-18/+79 2022-02-02`path.relative` passes Node's tests (which also fixed bugs)Gravatar Jarred Sumner 8-283/+571