Coder Social home page Coder Social logo

koleok / jest-coverage-ratchet Goto Github PK

View Code? Open in Web Editor NEW
41.0 5.0 12.0 97 KB

Uses jest coverage output to raise acceptable coverage threshold to current coverage

License: MIT License

JavaScript 100.00%
jest testing coverage coverage-report coverage-testing ratchet node javascript

jest-coverage-ratchet's Introduction

jest-coverage-ratchet

Raises jest's minimum coverage thresholds (per category) if current coverage is higher.

What does it do?

Lets say you have some jest coverage thresholds set in the package.json for your project at the following values:

{
  "branches": 30,
  "functions": 30,
  "lines": 30,
  "statements": 50,
}

then you get inspired one day and write lots of tests. Now your actual coverage summary might look like this:

{
  "branches": 50,
  "functions": 60,
  "lines": 77,
  "statements": 50,
}

Great πŸŒΈβ€Ό Except you'd really like your accomplishment to set the new standard for test coverage in this project. jest-coverage-ratchet just does that automatically by looking at your current coverage summary, comparing it to your specified coverage thresholds, and updating the minimum for any threshold that is higher in the summary.

So given the previous values, running this script will update your coverage thresholds specified in the jest key of package.json to the following values:

{
  "branches": 50,
  "functions": 60,
  "lines": 77,
  "statements": 50,
}

Installation

Just add as a dev dependency to your project like

npm install --save-dev jest-coverage-ratchet

or

yarn add --dev jest-coverage-ratchet

I recommend then using the binary jest-coverage-ratchet as part of a prepush hook.

Assumptions

I know what happens when you assume, but jest-coverage-ratchet makes the following assumptions about your project.

  • jest has been run for project at least once with --coverage so that there is a valid file at the path ./coverage/coverage-summary.json (alternatively pass a path with --coverageSummaryPath of ./your/path/to/coverage-summary.json)
  • jest configuration object is present in the package.json that specifies at least:
    {
      // ...
      "jest": {
        "coverageReporters": [
          "json-summary"
        ],
        "coverageThreshold": {
          "global": {
            "branches": Number,
            "functions": Number,
            "lines": Number,
            "statements": Number,
          }
        }
      },
      // ...
    }

Should this tool support things like piping the coverage data in as an argument? Of course it should. If you want to build that and send a PR I will be all smiles πŸ˜€βœ¨. If not then you probably see me do it eventually.

Questions?

Just submit an issue or a PR, I'm no elitist.

jest-coverage-ratchet's People

Contributors

koleok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jest-coverage-ratchet's Issues

Command returns empty object as new coverage thresholds

I defined the following script in my package.json:

"ratchet": "./node_modules/.bin/jest-coverage-ratchet",
"test:ratchet": "npm run ratchet -- --coverageSummaryPath './coverage/coverage-final.json'"

(I had to redefine coverageSummaryPath because the coverage report's name has changed since... 5 years ago)

When running npm run test:ratchet, I get the following output:

new coverage thresholds:
{}

coverage thresholds ratcheted πŸ”§

Note that my coverage-final.json is faaaaar from being empty.
Does anyone know how to fix this?

Rounding coverage values down

How do you guys handle small (<1%) fluctuations of coverage values?
I propose to enable an option to round the threshold values down in order to avoid errors thrown on minor test coverage decrements

utils.js

const takeMaxValues = R.reduce(
  (result, [key, val]) =>
    R.merge(result, { [key]: R.max(result[key] || 0, Math.floor(val)) }),
  {}
)

Not working with categories

jest-coverage-ratchet doesn't raise jest's minimum coverage thresholds per category if current coverage is higher.

In my case, I have in my package.json :

"coverageThreshold": { "./src/shared/utils/Misc.js": { "lines": 80, "statements": 80, "functions": 80, "branches": 80 }

And in my coverage-summary, the coverage for this file is 100%,, then when I run jest-coverage-ratchet it doesn't raise the current threshold coverage for this file, it only raises the global.

Is there a mechanism to check the previously ran thresholds

Currently i am hardcoding the threshold values

 "coverageThreshold": {
      "global": {
        "lines": 80.00,
        "statements": 80.00,
        "functions": 80.00,
        "branches": 80.00
      }
    },

Is there a way to check the previous build coverage threshold and make sure that the coverage did not go low in the current build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.