2017-04-26 202 views
1

我有一个项目是我使用create-react-app创建的。当我第一次创建该项目时,测试运行良好。我决定不跑他们一段时间后运行测试(我还没有写任何所以生成的测试类是我的全部),现在我发现了以下错误:当运行react-scripts测试时出现“错误:产生git ENOENT”

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是肯定在路径上,我可以从命令行运行git --version,并按预期输出。如果我在cygwin或windows命令行中运行,会得到相同的错误。

我的package.json样子:

{ 
    "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" 
    } 
} 

编辑:一些玩弄我发现,当该项目是一个Git仓库我只测试失败之后。如果我拿了一个项目的副本,没有'.git'文件夹,然后从副本运行测试,他们都运行良好。

回答

1

我终于弄清楚是什么导致了这一点。关于我的本地设置的一些事情在git作为Jest观察者的一部分启动时引发错误(仍然不清楚是什么)。从创建反应的应用程序内的文档:

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

运行测试,好像他们是在一个CI环境set CI=true&&npm test运行绕过git的功能,我可以运行我的测试。 More information here

这个笑话项目还有一个开放的bug:https://github.com/facebook/jest/issues/3214

相关问题