Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion docusaurus/docs/jest/cookbook.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include a similar sentence in the other runners?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because there are no examples of code coverage for Cypress & Vitest.

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).
Loading