2017-04-26 199 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

相關問題