question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for precedence in coverageThreshold file glob patterns

See original GitHub issue

🚀 Feature Proposal

Motivation

We have the following configuration which our codebase adheres to but, although the accumulated coverage of the codebase fulfills it, there are individual files with coverage that falls below these thresholds.

coverageThreshold: {
  global: {
    branches: 95,
    // I will omit these to keep code snippets short
    // functions: 95,
    // lines: 95,
    // statements: 95
  }
}

We could add the following, but it would mean every file needing its coverage improving immediately for builds to pass.

coverageThreshold: {
  global: {
    branches: 95,
  },
  './src/**/*.+(js|jsx)': {
    branches: 95,
  }
}

Instead we want to set a rising watermark for files with insufficient coverage, so they can’t get any worse, then gradually raise and remove them as they are improved.

Example

Given a file at ./src/some-file.js which has 60% branch coverage and this configuration:

coverageThreshold: {
  global: {
    branches: 95,
  },
  './src/**/*.js': {
    branches: 95
  },
  './src/some-file.js': {
    branches: 60
  }
}

My request is that the pattern "./src/some-file.js" takes precedence over "./src/**/*.js" and resolves to a coverageThreshold of 60% being applied to ./src/some-file.js. Currently all patterns are checked independently of one another, which results in an error being thrown for the pattern "./src/**/*.js" setting a threshold of 95% (which is violated by ./src/some-file.js having branch coverage of 60%).

The pattern './src/some-file.js' allows for leniency on files known to need improvement, while './src/**/*.js' ensures any new files being added to the project are caught straight away and made to meet the desired threshold.

Precedence is defined by the order of the keys in the object, so in this example where I have swapped './src/some-file.js' and './src/**/*.js' around, './src/**/*.js' wins because it appears later.

coverageThreshold: {
  global: {
    branches: 95
  },
  './src/some-file.js': {
    branches: 60
  },
  './src/**/*.js': {
    branches: 95
  }
}

This change would only apply to patterns which refer to files, the "global" pattern and those which point to directories would be unaffected.

Pitch

This is a change to an existing Jest feature.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rkaartikeyancommented, Mar 9, 2022

Any update on this?

1reaction
thymikeecommented, Dec 18, 2018

I’m not yet convinced which is better, but I would lean towards paths being always more specific than globs. We could solve this by checking if globbing over string produces a single or multiple output, and act accordingly. Obvious shortcoming is when glob returns just one file, but it seems kind of an edge case where users should re-consider their config.

cc @rickhanlonii @SimenB

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
An array of glob patterns indicating a set of files for which coverage information should be collected. If a file matches the specified...
Read more >
jest-message-util | Yarn - Package Manager
... with files (#8912); [jest-resolve] moduleNameMapper should take precedence ... [jest-cli] Glob patterns ignore non- require -able files (e.g. README.md ) ...
Read more >
jest coverageThreshold glob exclude some sub folders
config.projectb.js) and run Jest with each of these configuration files, but putting the output into different directories. I use this for test ...
Read more >
Phing User Guide
attribute allows you to define the minimum Phing version required to ... You can include or exclude specific files and patterns to/from a ......
Read more >
Help prompts for different compilers
--allowJs Allow javascript files to be compiled. ... this message and exits -r "FILE" Requires the given files/patterns (*) -S SCRIPT Finds and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found