testaged-coverage · ·
Use this library to execute tests on your git staged files and verify they comply with the test coverage threshold.
You can install this dependency globally now (starting 1.3.3)
yarn add global testaged-coverage
or
npm install testaged-coverage -g
.
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": 80
}
}
}
}
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": "testaged-coverage && <you can include other scripts here (e.g. lint-staged)>"
}
},
}
Directly in command line
Just execute testaged-coverage
Starting 1.3.0 you can add a --basedir array of folders where to look for tests
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 versions 1.3.3 or lower, when running testaged-coverage
, you will need to add the environment variable CI=true
to your test
script in your package.json
in order to prevent the script from running in watch mode. This will no longer be necessary from versions 1.3.4 and on.