簡體   English   中英

運行測試時npm錯誤ELIFECYCLE

[英]npm error ELIFECYCLE while running the test

我正在使用mocha-phantomjs設置進行單元測試。 我有以下package.json scriot來運行測試。

"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html" 
}

這在瀏覽器中運行正常。 當我在cmd中運行命令npm test時,測試運行正常,但它也會出現以下錯誤

3 passing (5s)
6 failing


npm ERR! flickr-test@ testFlickr: `mocha-phantomjs ./test/FlickrTest.html`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the flickr-test@ testFlickr script.
npm ERR! This is most likely a problem with the flickr-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mocha-phantomjs ./test/FlickrTest.html
npm ERR! You can get their info via:
npm ERR!     npm owner ls flickr-test
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testFlickr"
npm ERR! cwd C:\Users\user\Desktop\test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\user\Desktop\test\npm-debug.log
npm ERR! not ok code 0
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

請任何人都可以告訴我如何解決此錯誤。

我遇到了同樣的問題,為我修復的是當我運行單元測試時, 不要使用

npm run test

改為使用:

npm test

當運行npm test它會ELIFECYCLE錯誤,因此您永遠不會遇到這種體驗。

參考代碼

將測試腳本移動到其他腳本名稱后,您將開始看到ELIFECYCLE錯誤。

我的修復是在命令末尾添加一個exit 0 對於您的代碼,它看起來像這樣:

"scripts": {
  "test": "npm run testFlickr",
  "testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0" 
}

當我在cmd中運行命令npm test時,測試運行正常

不,他們不是。 你有6個失敗的測試。 mocha-phantomjs的退出代碼等於失敗測試的數量。 直接運行mocha-phantomjs ./test/FlickrTest.html ,查看失敗的原因。 實現PhantomJS與瀏覽器有點不同 - 您可能需要對其進行調試

您的腳本設置很奇怪。 你應該只有:

"scripts": {
   "test": "mocha-phantomjs ./test/FlickrTest.html"
}

然后奇數節點錯誤應該消失。

使用npm run時這是一個問題,只要測試失敗,它就與Mocha退出代碼!== 0有關。 如果您在Windows上試試這個:

"scripts": {
  "test": "npm run testFlickr || ECHO.",
  "testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO." 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM