Skip to content

Commit

Permalink
update(docs): improve Jest cookbook and troubleshooting for coverage (#…
Browse files Browse the repository at this point in the history
…228)

* Clarify Generate code coverage reports for jest
* Add Missing Jest coverage data to troubleshooting
  • Loading branch information
ArturT authored Jan 17, 2025
1 parent 8214b84 commit 7803500
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 37 additions & 1 deletion docusaurus/docs/jest/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,49 @@ npx knapsack-pro-jest --config=jest.config.e2e.js

## Generate code coverage reports

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.

To avoid this, you can configure Knapsack Pro to generate a separate coverage report for each batch by setting the following environment variable:

```bash
export KNAPSACK_PRO_COVERAGE_DIRECTORY=coverage

npx knapsack-pro-jest --coverage
```

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).
This ensures each batch creates a unique subfolder for its coverage report, preventing overwrites:

```
coverage
├── 04c9ea40-4477-11ea-8397-c539e4406df8
│   ├── clover.xml
│   ├── coverage-final.json
│   ├── lcov-report
│   │   ├── a.js.html
│   │   ├── base.css
│   │   ├── block-navigation.js
│   │   ├── index.html
│   │   ├── prettify.css
│   │   ├── prettify.js
│   │   ├── sort-arrow-sprite.png
│   │   └── sorter.js
│   └── lcov.info
└── 0c584590-4477-11ea-8397-c539e4406df8
├── clover.xml
├── coverage-final.json
├── lcov-report
│   ├── b.js.html
│   ├── base.css
│   ├── block-navigation.js
│   ├── index.html
│   ├── prettify.css
│   ├── prettify.js
│   ├── sort-arrow-sprite.png
│   └── sorter.js
└── lcov.info
```

You can merge the reports with [this script](https://github.com/jestjs/jest/issues/2418#issuecomment-478932514).

## Generate XML reports

Expand Down
4 changes: 4 additions & 0 deletions docusaurus/docs/jest/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ npx knapsack-pro-jest --runInBand
## No tests are executed (or `test_files: [ 'parameter is required' ]`)

Make sure [`KNAPSACK_PRO_TEST_FILE_PATTERN`](reference.md#knapsack_pro_test_file_pattern) is correct.

## Missing Jest coverage data

See [how to configure Jest code coverage](cookbook.md#generate-code-coverage-reports).

0 comments on commit 7803500

Please sign in to comment.