为什么NPM run test命令失败并显示npm ERR!代码ELIFECYCLE错误?

时间:2020-06-04 10:37:55

标签: node.js angular npm angular-cli angular-test

我的Angular CI构建在NPM测试任务中失败,我在CI中运行 npm run Test:sonar 命令。

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 run test:sonar,

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超时还是其他导致此错误的原因。我已经使用了很多个月了,直到今天它工作正常。 任何建议或帮助都会很棒。

同时,我还将寻找其他导致此错误的解决方案/原因。

enter image description here

2 个答案:

答案 0 :(得分:0)

这个错误往往会让人很困惑,但是您对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提供的钩子集的一部分,以提供钩子进入软件包构建/安装生命周期。这是一条普通的错误消息,使您无法自拔。

答案 1 :(得分:0)

我能够通过将karma.conf.sonar.js文件中执行程序的值从3更新为4来解决此问题。由于它必须执行1700多个测试用例,因此我认为3个chrome无法执行它们,因此将其更新为4个可以停止抛出错误。

当前,npm测试在CI构建和CMD提示符下都可以正常工作。

enter image description here