Skip to content

[Bug]: Cannot specify unique test coverage per project #15588

@JPStrydom

Description

@JPStrydom

Version

29.7.0

Steps to reproduce

I have a monorepo where I'm using npm workspaces and "type": "module" in my package.json file. I have a central Jest config file (jest.config.e2e.mjs) for my E2E tests that looks like this:

export default {
  clearMocks: true,
  collectCoverage: true,
  collectCoverageFrom: ['./**/index.js', '!./test-e2e/**/*.js'],
  coverageProvider: 'v8',
  coverageReporters: ['clover', 'json', 'lcov', 'text', 'cobertura'],
  coverageThreshold: { global: { statements: 80, branches: 80, functions: 80, lines: 80 } },
  projects: [
    {
      displayName: 'Package 1',
      rootDir: '<rootDir>/packages/package-1',
      testMatch: ['<rootDir>/test-e2e/**/*.e2e.js']
    },
    {
      displayName: 'Package 2',
      rootDir: '<rootDir>/packages/package-2',
      testMatch: ['<rootDir>/test-e2e/**/*.e2e.js']
    },
    // ↓ I don't want to have coverage on this package ↓
    {
      collectCoverage: true, // This line throws a warning within the terminal
      displayName: 'Package 3',
      rootDir: '<rootDir>/packages/package-3',
      testMatch: ['<rootDir>/test-e2e/**/*.e2e.js']
    },
}

When running with:

cross-env NODE_ENV=test-e2e NODE_OPTIONS=--experimental-vm-modules jest --config=jest.config.e2e.mjs --runInBand --detectOpenHandles --forceExit --silent"

I get this warning in the terminal and the coverage still seems to run for Package 3:

● Validation Warning:

  Unknown option "collectCoverage" with value false was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

See this CodeSandbox for a repo that reproduces the issue.

Expected behavior

When I add custom per-project code coverage settings to my monorepo's root Jest config file, I expect the per-project code coverage setting to apply to each project.

Actual behavior

When running my monorepo's Jest tests with a root Jest config that has per-project code coverage settings, I get a warning in the terminal saying that the per-project config isn't supported and I can see the per-project config isn't applied.

Environment

System:
- Windows 11

Binaries:
- Node: 22.14.0
- npm: 11.2.0

NPM Packages:
- jest: 29.7.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions