简体   繁体   中英

ng test fails midway with "[karma-server]: UnhandledRejection"

Today when I ran ng test on a project I got the following error [karma-server]: UnhandledRejection and the tests stopped midway - "Executed 26 of 1371". Chrome appears and then disappears and the tests stop.

Those tests used to run and I have not made any changes to the source code, so I assume it must be something environment specific that got updated - Karma, Chrome, node, some npm package, or maybe a Windows Update. Also, the same tests run on a Jenkins server which runs on Windows Server.

This is the full error log:

$ ng test
Your global Angular CLI version (13.1.3) is greater than your local version (10.2.1). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
10% building 2/2 modules 0 active12 07 2022 11:42:56.289:WARN [karma]: No captured browser, open http://localhost:9876/
12 07 2022 11:42:56.299:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
12 07 2022 11:42:56.299:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
12 07 2022 11:42:56.309:INFO [launcher]: Starting browser Chrome
12 07 2022 11:43:28.578:WARN [karma]: No captured browser, open http://localhost:9876/
12 07 2022 11:43:28.754:INFO [Chrome 103.0.5060 (Windows 10.0.0)]: Connected on socket R1Sdp2DoCDFDRIRYAAAA with id 72319116
Chrome 103.0.5060 (Windows 10.0.0): Executed 26 of 1371 SUCCESS (0 secs / 0.312 secs)
12 07 2022 11:43:34.087:ERROR [karma-server]: UnhandledRejection

What is causing this error and how can I fix it?

The solution is to downgrade to Node v14 - https://nodejs.org/dist/latest-v14.x/

This is because Karma (or at least Karma 4.4.1) is incompatible with Node 15 and above - see https://github.com/karma-runner/karma/issues/3570

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