Run Create-React-App Tests not in Watch Mode

Yuschick picture Yuschick · Mar 7, 2018 · Viewed 8.8k times · Source

I have a project created using Create-React-App. I am looking to add in a precommit hook to run our linter and tests with the pre-commit package.

"pre-commit": [
  "precommit-msg",
  "lint",
  "test"
],

However, since the test script runs by default in watch mode, this prevents the commit from ever actually happening. How can add the tests not in watch move in the pre-commit?

Answer

Boogie picture Boogie · Nov 30, 2019

You can use the --watchAll=false parameter. So for example you can create another script like this:

"scripts": {
  "test:nowatch": "react-scripts test --watchAll=false",
}

And then run

"pre-commit": [
  "precommit-msg",
  "lint",
  "test:nowatch"
],