Search code examples
npmjestjscommand-line-interfacehusky

How to escape Jest watchman when run with husky?


Hi i'm trying to integrate husky into my process and i can't find a way to make it work with Jest watchman.
My setup:
On root level .husky/pre-push

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run test

On package.json

"scripts": {
    "test": "cd packages/frontend && node scripts/test.js --watchAll",
    "prepare": "husky install"
  },

Now i run git push and husky does work by running npm run test but i can't exit the cli. enter image description here

I've been searching google and most people seem to config husky in package.json instead of a husky directory but the official docs does this way.
Any idea how to resolve this issue ?


Solution

  • You need to disable watchAll (interactive mode).

    #!/bin/sh
    . "$(dirname "$0")/_/husky.sh"
    
    npm run test -- --watchAll=false
    
    

    The issue

    Running jest will start an interactive mode waiting for a user input, therefor it does not exit once completed. If this is a script you run locally you need to manually specify that it should run and then exit.

    Note that you do not have to add this if the tests are going to be run by circleci for example because this is done automatically in CI environments.

    Documentation for watchAll