Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Global and single file coverage thresholds #36

@ahnpnl

Description

@ahnpnl

Version

30.2.0

Steps to reproduce

Expected behavior

I'll describe my use case. A global threshold is configured as following:

coverageThreshold: {
  global: {
    statements: 85,
    branches: 80,
    functions: 85,
    lines: 85
  }
}

This makes it possible to commit completely untested files as long as the overall coverage is fulfilled. To solve this issue I would like to enforce every file being tested for at least 50%:

coverageThreshold: {
  global: {
    statements: 85,
    branches: 80,
    functions: 85,
    lines: 85
  },
  
  "app/**/*.js": {
    statements: 50,
    branches: 50,
    functions: 50,
    lines: 50
  }
}

However, this won't work as expected:

  • First, running this config will fail if app/ and global point to the same files (which is expected as "If the file specified by path is not found, error is returned.").
  • Second, now the global threshold is overruled by the "local" threshold.

It would be great to have an option to use a global threshold which always applies to all files in addition to glob/path thresholds for single file thresholds, similar to how Vitest does in NOTE section

Vitest counts all files, including those covered by glob-patterns, into the global coverage thresholds. This is different from Jest behavior.

{
  coverage: {
    thresholds: {
      // Thresholds for all files
      functions: 95,
      branches: 70,

      // Thresholds for matching glob pattern
      'src/utils/**.ts': {
        statements: 95,
        functions: 90,
        branches: 85,
        lines: 80,
      },

      // Files matching this pattern will only have lines thresholds set.
      // Global thresholds are not inherited.
      '**/math.ts': {
        lines: 100,
      }
    }
  }
}

it should work for cross OS

Actual behavior

Currently, when using both global and path/glob thresholds, the global config combines the coverage for remaining files only (as documented).

Additional context

No response

Environment

Windows 7
jest v22.1.4
node v8.9.1
npm v5.6.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions