Run Create-React-App Tests not in Watch Mode

I found a solution for my setup by adding the following script in my package.json file.

"test:nowatch": "CI=true react-scripts-ts test --env=jsdom",

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

This came from the following thread: https://github.com/facebook/create-react-app/issues/2336


Cross platform solution for this:

  1. Install cross-env
  2. Use your test command with such props: "test:nowatch": "cross-env CI=true react-scripts test --env=jsdom --findRelatedTests"

Just adding the CI=true like this "test": "CI=true react-scripts test" worked for me


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"
],