chilly_maximus
chilly_maximus

Reputation: 772

husky pre-commit yarn/npm test does not react to keybord input

I have simple app create by create-react-app so my yarn test runs react-scripts test. When i run it from console I see standard output

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.

And it properly reacts to pressed key. However when i create husky pre-commit hook

. "$(dirname "$0")/_/husky.sh"

yarn test

i see the same output in console, but this time it doesn't react to press. When I press any button it is just printed in console and Im unable to proceed. Any idea how to force husky to properly run Jest tests? Thx in advance.

Upvotes: 0

Views: 964

Answers (1)

Ali Hosseini
Ali Hosseini

Reputation: 959

the problem is the yarn test command by default runs in interactive mode to solve this i recommand to add annother command to your package.json file like this

"scripts": {
...
"test:exit": "react-scripts test --force Exit"
...
}

and in husky instead of yarn test use yarn test -- --watchAll=false

Upvotes: 1

Related Questions