Jest from create-react-app not running on Windows Jest from create-react-app not running on Windows reactjs reactjs

Jest from create-react-app not running on Windows


create-react-app is CLI that generates react-scripts pre-configured setup that includes Webpack and Jest configuration, among other things.

When Jest is used directly as jest, it ignores generated configuration and requires to be configured from scratch.

npm test (defaults to react-scripts test in CRA setup) should be used instead of jest to make use of generated Jest configuration.

In case the problem with npm test is interactive mode:

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

It can be addressed with npm test a.


Just to clarify the answer of @estus-flask.
There are 2 solutions.

First Solution:

package.json

"scripts": {  "test": "react-scripts test --watchAll",  ...},

And then run

npm test

Second Solution:

Or when you run the tests, run them like this:

npm test a


In my case, I am running a an Azure DevOps pipeline, to build and deploy a react app to Azure app service. So I used the following script task to do npm install, npm build and then test as follows.

- script: |    echo Working dir and file list are as follows.    echo -----------------------------------------    pwd    ls -la    echo Changing directory to reactonazure    ehco ----------------------------------    cd reactonazure    echo Working dir and file list now after chaning directory are as follows.    echo ---------------------------------------------------------------------    pwd    ls -la    echo Running npm install    echo -------------------    npm install    echo Running npm build --if-present    echo ------------------------------    npm run build --if-present    echo Running CI=true npm test    echo ------------------------                 CI=true npm test  displayName: 'npm install, build and test'

You can ignore echo, ls, pwd and cd statements. The point in focus it the last one

CI=true npm test

That finally started working. Earlier I had

npm run test --if-present

which gave me the error.

No tests found related to files changed since last commit.