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 git 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
Starting 1.3.0 you can add a --basedir array of folders where to look for tests
node ./node_modules/testaged-coverage --basedir="src scripts folder1 folder2"
By default --basedir is folder src
Troubleshooting
This library assumes you have a script setup for tests in your package.json
.
{
"scripts": {
"test": "jest"
},
}
If you are using react-scripts test
, you need to add the environment variable CI=true
to prevent the script from running in watch mode.