FAQ / @knapsack-pro/jest / Knapsack Pro Jest specific questions

How to generate code coverage for Jest with Knapsack Pro Jest in Queue Mode?

To generate code coverage for @knapsack-pro/jest you need to do 2 things:

  • provide --coverage flag to @knapsack-pro/jest
$(npm bin)/knapsack-pro-jest --coverage
  • you must set KNAPSACK_PRO_COVERAGE_DIRECTORY=coverage (this is the path to the directory where code coverage will be generated). Knapsack Pro in Queue Mode runs many batches of tests fetched from Queue API and because of that, we have to generate many reports with random directory name coverage/uuid for each batch of tests. Reports will be generated on a single CI node.

    If you won't set KNAPSACK_PRO_COVERAGE_DIRECTORY then each batch of tests would generate a new report and overrides the existing report file. You would lose previous reports because of that (learn more about the issue).

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
├── 0b5e5530-4477-11ea-8397-c539e4406df8
│   ├── clover.xml
│   ├── coverage-final.json
│   ├── lcov-report
│   │   ├── base.css
│   │   ├── block-navigation.js
│   │   ├── c.js.html
│   │   ├── 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


Here is a full example of how you should set command for @knapsack-pro/jest:

export KNAPSACK_PRO_COVERAGE_DIRECTORY=coverage
$(npm bin)/knapsack-pro-jest --coverage


Note If you want to merge those reports you can check if your CI provider can do it for you. GitLab CI can create a correct summary of multiple junit.xml files but it is not able to understand any of the coverage reports as far as we know, quite likely that other CI systems are unable as well. What you can do with this exact case, is use something very similar to this JS script here.

Start using Knapsack Pro

Sign up and speed up your tests.