简体   繁体   中英

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

My Angular CI build is failing in NPM test task, I am running the npm run Test:sonar command in the CI.

The test:sonar is defined in package.json file at the top having below details,

"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",

Currently, I am getting below error with CI and also if executed manually for 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

Adding screenshot of CMD prompt as well, not sure whether it is due to chrome timeout or something else that's causing this error. I have been using this from many months and it was working fine till today. Any suggestion or help on this would be great.

In the meantime I will also look for any other solution\reason that's causing this error.

在此处输入图像描述

This error tends to be very confusing, but you're right about the Chrome bit. The actual error is the test script getting killed by the test runner as pointed out by the final warn message:

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

You're probably invoking the test via npm run <> command, and that's the "lifecycle" script that the error message mentions. The scripts can be used as part of a larger set of hooks that npm provides to hook into the package building/installation lifecycle. And it's a generic error message that's throwing you off here.

I was able to resolve this issue by updating the value for executors from 3 to 4 in karma.conf.sonar.js file. As it has to execute more than 1700+ test cases and I think 3 chromes were unable to execute them and thus updating it to 4 stopped throwing the error.

Currently npm test is working fine with both CI build and with CMD prompt.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM