We're using using Jest's projects feature to run tests in all packages of a monorepo concurrently. It's blazingly fast, and especially useful in CI 鉂わ笍 .
The problem is that some packages need to exclude a pattern (e.g, /index.js) from test coverage. Other packages need to include the same pattern in their test coverage.
Specifying collectCoverageFrom in each package's config works when running Jest at the specific package. When running at the repo root (using projects), the individual collectCoverageFrom props are ignored.
Specifying collectCoverageFrom at the root config does not work: The package path is not included in the tested path/glob, and so you cannot include package1/index.js while excluding package2/index.js.
Have two packages with the same relative source filename, (e.g, index.js at the package root).
Try to include only one package's file in coverage, while excluding the other package's file.
To keep things DRY, I would prefer if collectCoverageFrom at the root config would be inherited from the individual project's config.
Another option is specifying the project's path in collectCoverageFrom at the root:
{
"collectCoverageFrom": [
"packages/package1/index.js",
"!packages/package2/index.js"
]
}
https://github.com/salto-io/jest_projects_coverage_issue
System:
OS: macOS 10.15.3
Binaries:
Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
Yarn: 1.22.0 - ~/.nvm/versions/node/v12.14.1/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
Jest version: 25.1.0
(Also tried with 24.9)
Added PR #9633 which implements the DRY solution described above.
Most helpful comment
Added PR #9633 which implements the DRY solution described above.