If you use out-of-the-box defaults (rush build orchestrator with heft
commands for individual builds), then all you need to do is turn on collectCoverage
in your jest config for each project.
{
"preset": "./node_modules/@rushstack/heft/includes/jest-shared.config.json",
"collectCoverage": true
}
By default, heft already outputs coverage in JSON format to temp/coverage-final.json
in each project folder. In order to collect this into a single report in your repo, you'll want to:
- Create a new project in your repo, such as
tools/collect-code-coverage
. - Write a script to loop through all the projects in
rush.json
, combine their coverage maps, and write the combined HTML report. Here's an example implementation written in TypeScript. - Add the dependencies you'll need (for the example implementation, you need
rush-lib
,istanbul-lib-coverage
,istanbul-lib-report
,istanbul-reports
, and of course,istanbul-reporter-html-monorepo
). - Build the project, and run it from your CI pipeline, with a command like
node tools/collect-code-coverage/lib/collect-code-coverage.js
.
These screenshots were generated by enabling code coverage for the rushstack monorepo itself, then running the example script provided above.
Each project in the monorepo is listed as a top-level entry, and after clicking into a project, each source file is listed relative to that project root (with the name of the project in the breadcrumb header).