Skip to content

Commit 7803500

Browse files
authored
update(docs): improve Jest cookbook and troubleshooting for coverage (#228)
* Clarify Generate code coverage reports for jest * Add Missing Jest coverage data to troubleshooting
1 parent 8214b84 commit 7803500

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docusaurus/docs/jest/cookbook.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,49 @@ npx knapsack-pro-jest --config=jest.config.e2e.js
4444

4545
## Generate code coverage reports
4646

47+
Each CI node executes multiple batches of tests in Knapsack Pro [Queue Mode](../overview/index.mdx#queue-mode-dynamic-split), and each batch starts a new Jest process. By default, a coverage report generated by each batch overwrites the previous one, which can lead to incomplete coverage data.
48+
49+
To avoid this, you can configure Knapsack Pro to generate a separate coverage report for each batch by setting the following environment variable:
50+
4751
```bash
4852
export KNAPSACK_PRO_COVERAGE_DIRECTORY=coverage
4953

5054
npx knapsack-pro-jest --coverage
5155
```
5256

53-
Knapsack Pro generates one coverage report for each batch of tests executed on the CI node. To merge the reports you may consider [this script](https://github.com/jestjs/jest/issues/2418#issuecomment-478932514).
57+
This ensures each batch creates a unique subfolder for its coverage report, preventing overwrites:
58+
59+
```
60+
coverage
61+
├── 04c9ea40-4477-11ea-8397-c539e4406df8
62+
│   ├── clover.xml
63+
│   ├── coverage-final.json
64+
│   ├── lcov-report
65+
│   │   ├── a.js.html
66+
│   │   ├── base.css
67+
│   │   ├── block-navigation.js
68+
│   │   ├── index.html
69+
│   │   ├── prettify.css
70+
│   │   ├── prettify.js
71+
│   │   ├── sort-arrow-sprite.png
72+
│   │   └── sorter.js
73+
│   └── lcov.info
74+
└── 0c584590-4477-11ea-8397-c539e4406df8
75+
├── clover.xml
76+
├── coverage-final.json
77+
├── lcov-report
78+
│   ├── b.js.html
79+
│   ├── base.css
80+
│   ├── block-navigation.js
81+
│   ├── index.html
82+
│   ├── prettify.css
83+
│   ├── prettify.js
84+
│   ├── sort-arrow-sprite.png
85+
│   └── sorter.js
86+
└── lcov.info
87+
```
88+
89+
You can merge the reports with [this script](https://github.com/jestjs/jest/issues/2418#issuecomment-478932514).
5490

5591
## Generate XML reports
5692

docusaurus/docs/jest/troubleshooting.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ npx knapsack-pro-jest --runInBand
4848
## No tests are executed (or `test_files: [ 'parameter is required' ]`)
4949

5050
Make sure [`KNAPSACK_PRO_TEST_FILE_PATTERN`](reference.md#knapsack_pro_test_file_pattern) is correct.
51+
52+
## Missing Jest coverage data
53+
54+
See [how to configure Jest code coverage](cookbook.md#generate-code-coverage-reports).

0 commit comments

Comments
 (0)