I have created app using create-react-app and I have been trying to set up lint-staged with husky. I have 4 stages but it hangs on npm run test.
create react app using create-react-app and then replace following package.json into project directory.
{
"name": "dsp-admin-fe",
"version": "0.1.0",
"private": true,
"jest": {
"collectCoverageFrom": ["src/**/*.js"],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"dependencies": {
"axios": "^0.18.0",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.0",
"react-scripts": "2.1.8",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"standard-http-error": "^2.0.1",
"styled-components": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"husky": "^1.3.1",
"install": "^0.12.2",
"lint-staged": "^8.1.5",
"prettier": "1.16.4"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"npm run test",
"git add"
]
}
}
COPY THE DEBUG LOGS HERE
lint-staged: "^8.1.5"I鈥檓 closing since there are no debug logs attached. Unless these are provided I believe we can鈥檛 help any further.
@okonet I had my lint-staged and it works!. I don't what was the issue but its seems fine now. But still if i use npm run test it hangs forever. Might be CI=true is doing some magic.
"scripts": {
...
"test": "react-scripts test",
"test:staged": "cross-env CI=true react-scripts test --coverage --env=jsdom --findRelatedTests"
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"npm run test:staged",
"git add"
]
}
@jitenderchand1 try using the --watchAll=false flag as well .. react-scripts test runs by default in watch mode, but that doesn't jive with lint-staged .. hope this helps!
Most helpful comment
@jitenderchand1 try using the
--watchAll=falseflag as well ..react-scripts testruns by default in watch mode, but that doesn't jive with lint-staged .. hope this helps!