testaged-coverage
Use this library to execute tests on your git staged files and verify they comply with the test coverage threshold.
Before the tests are run, make sure you have set a Jest "coverageThreshold". You can learn how to configure it here.
{
...
"jest": {
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": -10
}
}
}
}
How to use it
You need to stage your files first with gir add
.
In a pre-commit hook
You will need to have husky installed.
In your package.json
, add the script to run as a pre-commit hook.
{
"husky": {
"hooks": {
"pre-commit": "node ./node_modules/testaged-coverage && <you can include other scripts here (e.g. lint-staged)>"
}
},
}
Directly in command line
Just execute node ./node_modules/testaged-coverage