You should check coverageThreshold documentation of jest from here
Below options are possible for global coverage threshold and file name pattern thresholds.
{
...
"jest": {
"coverageThreshold": {
"global": {
"branches": 50,
"functions": 50,
"lines": 50,
"statements": 50
},
"./src/components/": {
"branches": 40,
"statements": 40
},
"./src/reducers/**/*.js": {
"statements": 90
},
"./src/api/very-important-module.js": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
}
}
You can combine this with lint staged and husky to make the check in pre-commit.
In the end, your package.json would look like this:
{
...package.json
"husky": {
"hooks": {
"pre-commit": "jest",
}
}
}