Jest: projects and collectCoverageFrom do not work together

Created on 2 Mar 2020  路  1Comment  路  Source: facebook/jest

馃悰 Bug Report

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.

To Reproduce

  • 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.

Expected behavior

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"
  ]
}

Link to repo

https://github.com/salto-io/jest_projects_coverage_issue

envinfo

 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)

Bug Report Needs Repro Needs Triage

Most helpful comment

Added PR #9633 which implements the DRY solution described above.

>All comments

Added PR #9633 which implements the DRY solution described above.

Was this page helpful?
0 / 5 - 0 ratings