I've noticed that our pre-commit script is running too long. After some investigation, I found it is running ALL the tests in the source code, rather than just the tests related to staged files.
I tested by staging a file that breaks a test. When the scripts run, after 4 minutes it gives an error, and the git output shows 1 test suite failed and 356 passed.
I want the pre-commit hook to only run tests against staged files, and thought that --findRelatedTests
should do that. Is there an error with my set up?
{
"devDependencies": {
"eslint": "8.20.0",
"husky": "1.3.1",
"jest": "26.5.3",
"lint-staged": "8.1.0",
"prettier": "2.5.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{json,scss,md}": [
"prettier --write",
"git add"
],
"*.{ts,tsx}": [
"eslint --quiet",
"prettier --write",
"jest --findRelatedTests",
"git add"
]
}
}