簡體   English   中英

為什么 NPM 運行測試命令失敗並出現 npm ERR? 代碼生命周期錯誤?

[英]Why NPM run test command fails with npm ERR! code ELIFECYCLE Error?

我的 Angular CI 構建在 NPM 測試任務中失敗,我正在 CI 中運行npm run Test:sonar命令。

測試:聲納在頂部的 package.json 文件中定義,詳細信息如下,

"test:sonar": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage --karma-config=src/karma.conf.sonar.js" ,

目前,我在 CI 上遇到錯誤,如果手動執行 npm 運行測試:聲納,

2020-06-04T10:12:40.5784545Z Browserslist: caniuse-lite is outdated. Please run next command `npm update`
2020-06-04T10:12:41.7505089Z [32m04 06 2020 06:12:41.749:INFO [framework:karma-parallel]: [39msharding specs across 3 browsers
2020-06-04T10:13:03.9245412Z [32m04 06 2020 06:13:03.921:INFO [karma-server]: [39mKarma v4.1.0 server started at http://0.0.0.0:9876/
2020-06-04T10:13:03.9245412Z [32m04 06 2020 06:13:03.921:INFO [launcher]: [39mLaunching browsers Chrome, Chrome, Chrome with concurrency unlimited
2020-06-04T10:13:03.9245412Z [32m04 06 2020 06:13:03.921:INFO [launcher]: [39mStarting browser Chrome
2020-06-04T10:13:04.0026773Z [32m04 06 2020 06:13:03.999:INFO [launcher]: [39mStarting browser Chrome
2020-06-04T10:13:04.0339834Z [32m04 06 2020 06:13:04.030:INFO [launcher]: [39mStarting browser Chrome
2020-06-04T10:13:55.9279235Z [32m04 06 2020 06:13:55.925:INFO [Chrome 83.0.4103 (Windows 10.0.0)]: [39mConnected on socket gpO5ue6BN2Mpg7E1AAAB with id 40174053
2020-06-04T10:13:55.9369226Z [32m04 06 2020 06:13:55.929:INFO [Chrome 83.0.4103 (Windows 10.0.0)]: [39mConnected on socket detlQaSArnTujK4UAAAA with id 82416436
2020-06-04T10:13:55.9369226Z [32m04 06 2020 06:13:55.931:INFO [Chrome 83.0.4103 (Windows 10.0.0)]: [39mConnected on socket mhjlHwvj60_SZr0tAAAC with id 99954543
2020-06-04T10:15:08.0931637Z [33m04 06 2020 06:15:08.091:WARN [launcher]: [39mChrome was not killed in 2000 ms, sending SIGKILL.
2020-06-04T10:15:08.4838243Z npm ERR! code ELIFECYCLE
2020-06-04T10:15:08.4838243Z npm ERR! errno 1
2020-06-04T10:15:08.4838243Z npm ERR! nextgen@0.0.1 test:sonar: `node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage --karma-config=src/karma.conf.sonar.js`
2020-06-04T10:15:08.4994524Z npm ERR! Exit status 1
2020-06-04T10:15:08.4994524Z npm ERR! 
2020-06-04T10:15:08.4994524Z npm ERR! Failed at the nextgen@0.0.1 test:sonar script.
2020-06-04T10:15:08.4994524Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-04T10:15:08.4994524Z 
2020-06-04T10:15:08.4994524Z npm ERR! A complete log of this run can be found in:
2020-06-04T10:15:08.4994524Z npm ERR!     C:\Users\svc_TFSservice\AppData\Roaming\npm-cache\_logs\2020-06-04T10_15_08_499Z-debug.log

還添加了 CMD 提示的屏幕截圖,不確定是由於 chrome 超時還是其他導致此錯誤的原因。 幾個月以來我一直在使用它,直到今天它運行良好。 對此的任何建議或幫助都會很棒。

同時,我還將尋找導致此錯誤的任何其他解決方案\原因。

在此處輸入圖像描述

這個錯誤往往很令人困惑,但您對 Chrome 位的看法是正確的。 實際錯誤是測試腳本被測試運行程序殺死,正如最終警告消息所指出的那樣:

2020-06-04T10:15:08.0931637Z [33m04 06 2020 06:15:08.091:WARN [launcher]: [39mChrome was not killed in 2000 ms, sending SIGKILL.

您可能正在通過npm run <>命令調用測試,這就是錯誤消息中提到的“生命周期”腳本。 這些scripts可以用作npm提供的更大掛鈎集的一部分,以掛鈎到 package 構建/安裝生命周期。 這是一個通用的錯誤消息,讓你離開這里。

我能夠通過在 karma.conf.sonar.js 文件中將 executors 的值從 3 更新為 4 來解決此問題。 因為它必須執行超過 1700 多個測試用例,我認為 3 個 chrome 無法執行它們,因此將其更新為 4 個停止拋出錯誤。

目前 npm 測試在 CI 構建和 CMD 提示下工作正常。

在此處輸入圖像描述

暫無
暫無

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

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