Matt  Watson
Matt Watson

Reputation: 5317

"Error: spawn git ENOENT" when running react-scripts test

I have a project that I created using the create-react-app. When I first created the project the tests ran fine. I decided to run the tests after not running them for a while (I still haven't written any so the generated test class is all I have) and now I'm getting the following error:

Determining test suites to run...Error: spawn git ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)

Git is definitely on the path, I can run git --version from the command line and it outputs as expected. I get the same error if I run in cygwin or the windows command line.

My package.json looks like:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "immutable": "^3.8.1",
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  },
  "devDependencies": {
    "react-scripts": "0.9.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

EDIT: After some playing around I've discovered that my tests only fail when the project is in a git repository. If I take a copy of the project, without the '.git' folder then run the tests from the copy they all run fine.

Upvotes: 4

Views: 5692

Answers (1)

Matt  Watson
Matt Watson

Reputation: 5317

I eventually figured out what was causing this. Something about my local setup is causing an error when git is launched as part of the Jest watcher (still not clear what). From the create-react-app docs:

By default, when you run npm test, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests runs fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests.

Source

Running the tests as if they were running in a CI environment with set CI=true&&npm test bypasses the git functionality and I can run my tests. More information here

There is also an open bug in the jest project: https://github.com/facebook/jest/issues/3214

Upvotes: 3

Related Questions