Environment:
git version 2.25.1.windows.1
node 12.x
Npm 6.14.11
husky 7.0.4
windows 10
How to correctly setup husky & pre-commit hook? In my case I just want to add npm test script to run, so with every commit tests are run.
Environment:
git version 2.25.1.windows.1
node 12.x
Npm 6.14.11
husky 7.0.4
windows 10
How to correctly setup husky & pre-commit hook? In my case I just want to add npm test script to run, so with every commit tests are run.
Although most of things are covered in docs (if not all), I will share steps which I took in order to make this work because I have put several hours effort before finally made it.
npm i husky -Dpackage.json-"prepare": "husky install"npm run prepare-> .husky folder is created in project root directorypackage.jsonfile (read more in additional at the bottom):npm run husky add ./husky/pre-commit "npm test"->pre-commithook is createdgit commitADDITIONAL explanation to step 4:
npx husky add .husky/pre-commit "npm test"- this is command stated in docs and many stackoverflow questions/github issues or blogs, but this doesn't work by default on Windows & npm@6 (at least not for me).Output after this command is like this, it is just showing how to use command, no pre-commit file is created inside .husky folder:
It is documented in
huskydocs how this can be approached differently, and that is what I tried to do in step 4.