I am facing a strange issue with lint-staged
plugin. It was working fine earlier.
So the issue is when I run npm run test
it generates the coverage report.
"test": "cross-env CI=true react-scripts test --coverage",
But when I run the same command with husky
pre-commit and lint-staged
it is not working. When I checked the console I found that it is running against the file which has been modified.
> portal@0.1.0 test /Users/carlos/Desktop/portal
> cross-env CI=true react-scripts test --coverage "/Users/carlos/Desktop/portal/src/container/Auth/Login.page.js"
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/carlos/Desktop/portal
44 files checked.
testMatch: /Users/carlos/Desktop/portal/src/**/__tests__/**/*.{js,jsx,ts,tsx}, /Users/carlos/Desktop/portal/src/**/*.{spec,test}.{js,jsx,ts,tsx} - 6 matches
testPathIgnorePatterns: /node_modules/ - 44 matches
testRegex: - 0 matches
Pattern: /Users/carlos/Desktop/portal/src/container/Auth/Login.page.js - 0 matches
npm ERR! code ELIFECYCLE
npm ERR! errno 1
There is a noticeable difference
When I run
npm run test
it runs with
cross-env CI=true react-scripts test --coverage
and when npm run test
being called by husky and lint-staged
it's called with
cross-env CI=true react-scripts test --coverage "/Users/carlos/Desktop/portal/src/container/Auth/Login.page.js"
There is file path getting appended after --covrage
Here is my package JSON config.
"jest": {
"collectCoverageFrom": [
"src/**/*.js"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"eslintConfig": {
"extends": "react-app"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"npm run test",
"git add"
]
}
Note: This is happing when I use lint-staged only if I use the pre-commit:npm run test
it is working fine.