Basic Code Coverage Protection Utility for comparing coverage between branches
npm install jest-code-coverage-protectionjson-summary as coverage reporter to jest configuration
npm install jest-code-coverage-protection --save-dev
`Add the command to package.json
`
"scripts": {
"jccp": "jccp"
},
`usage options
`
Usage: jccp [options]Compare coverage-summary.json generated by jest
Options:
-V, --version output the version number
-f, --file The file generated by the (feature) branch you want to check (default: "coverage/coverage-summary.json")
-c, --compare The file generate by the (master) branch you want to compare against (default: "master/coverage/coverage-summary.json")
-n, --new -v, --variance Allow for variance, e.g. allow 0.05 to allow a 5% decrease using hold (default: "0")
-m, --mode Force code threshold or do not allow decrease (default: "hold")
-h, --help display help for command
`Configure ci/cd:
- Make sure your branches generate the coverage-summary.json file using the coverage reporter json summary
- Add checkout of comparison branch(master) to your build step
- Run jccp command
- Catch exit codes of jccp, 0 = coverage check passed, 1 = coverage check failedExamples
`
jccp -m new -n 0.9
jccp -m hold -v 0.5
jccp -f cover.json
``