Jest: feature request: automatically raise coverage?

Created on 1 Jun 2017  路  7Comments  路  Source: facebook/jest

Currently, if I have coverageThresholds defined, jest will (correctly) error out if any of the 4 metrics is below their threshold.

However, when coverage goes up, i'd like a way to automatically bump the thresholds to match the new, higher, coverage values.

One or both of the following would be helpful:

  1. a command that exited nonzero when coverage did not exactly meet the (whole-number-rounded) thresholds
  2. a command that updated my jest config inline (whether in package.json or a separate file) to make thresholds match current values, only if they are not lower than the current ones.
Feature Request

Most helpful comment

I mean, it shouldn't do this by default if that's what you mean; that'd be needlessly surprising and semver-major. A flag sounds good, and imo it only makes sense to invoke when coverage thresholds would otherwise be enforced (given the proper flag)

All 7 comments

I really like the idea of a bump-thresholds command. Currently I've just been setting them all to 100, running coverage, getting the values jest states, copying them to my jest config.
We do this every fortnight to lock in coverage gains.

The problem with trying to update inline would typically require committing those changes back to your source control repository. I wrote a script that we use as the testResultsProcessor and loops over all of the coverage to print out the current configured thresholds, the newly calculated thresholds and the difference between the 2. Makes it really easy to see how coverage changed and what numbers need to be updated. If you're interested: https://gist.github.com/bookman25/bc782c56062c03f34d34933563575778

Indeed, the result of running with this feature enabled would be a git diff that I'd then have to commit to my repo if I wanted to keep it.

Should this be a flag (similar to -u for snapshots) or do you want it automatically raised for every single test run, as long as it goes up (and is a test run for all tests, not just a subset of tests)?

I mean, it shouldn't do this by default if that's what you mean; that'd be needlessly surprising and semver-major. A flag sounds good, and imo it only makes sense to invoke when coverage thresholds would otherwise be enforced (given the proper flag)

馃憢 What about some sort of upper threshold? I would like jest to break if my threshold is much higher than the one configured. It could be done on a per threshold basis:

functions: [85, 90],

or a fixed number to be defined somewhere? I would just want to be notified if the threshold increases, it is sometimes hard to keep it up to date.

FYI, there is a https://github.com/Koleok/jest-coverage-ratchet project that is doing what people want here, although it properly works only with thresholds defined in package.json, not in jest.config.js.

Was this page helpful?
0 / 5 - 0 ratings