简体   繁体   English

Karma 服务器在 Angular 单元测试中产生 UNKNOWN -4094 错误

[英]Karma Server spawn UNKNOWN -4094 Error in Angular Unit Tests

For no understandable reason, I am no longer able to run unit tests in my Angular project because the Karma Server is throwing the odd error shown below.由于无法理解的原因,我不再能够在我的 Angular 项目中运行单元测试,因为 Karma 服务器抛出了如下所示的奇怪错误。

I am simply running npm test to trigger the unit tests, which should launch a web browser to start the Karma server and then Jasmine to show the test execution.我只是运行npm test来触发单元测试,它应该启动 web 浏览器来启动 Karma 服务器,然后 Jasmine 来显示测试执行。

This is on a Windows 10 PC using VS Code.这是在 Windows 10 PC 上使用 VS Code。

PS C:\Code\my-project> npm test
> my-project@1.0.0 test
> ng test
05 04 2022 13:45:19.898:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
⠙ Generating browser application bundles (phase: building)...05 04 2022 13:45:30.857:WARN [karma]: No captured browser, open http://localhost:9876/
05 04 2022 13:45:30.864:INFO [karma-server]: Karma v6.3.12 server started at http://localhost:9876/
05 04 2022 13:45:30.865:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
05 04 2022 13:45:30.872:INFO [launcher]: Starting browser Chrome
05 04 2022 13:45:30.945:ERROR [karma-server]: UncaughtException: Error: spawn UNKNOWN
    at ChildProcess.spawn (internal/child_process.js:403:11)
    at spawn (child_process.js:667:9)
    at spawnWithSignal (child_process.js:871:17)
    at spawnWithoutOutput (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:174:26)
    at Object.ProcessLauncher._execCommand (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:75:21)
    at Object.ProcessLauncher._start (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:33:10)
    at Object.<anonymous> (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:19:10)
    at Object.emit (events.js:412:35)
    at Object.BaseLauncher.start (C:\Code\my-project\node_modules\karma\lib\launchers\base.js:52:10)
    at Object.j (C:\Code\my-project\node_modules\karma\lib\launcher.js:108:17)
    at Object.setTimeout.bind.j (C:\Code\my-project\node_modules\qjobs\qjobs.js:143:18)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)
05 04 2022 13:45:30.949:ERROR [karma-server]: Error: spawn UNKNOWN
    at ChildProcess.spawn (internal/child_process.js:403:11)
    at spawnWithSignal (child_process.js:871:17)
    at spawnWithoutOutput (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:174:26)
    at Object.ProcessLauncher._execCommand (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:75:21)
    at Object.ProcessLauncher._start (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:33:10)
    at Object.<anonymous> (C:\Code\my-project\node_modules\karma\lib\launchers\process.js:19:10)
    at Object.emit (events.js:412:35)
    at Object.BaseLauncher.start (C:\Code\my-project\node_modules\karma\lib\launchers\base.js:52:10)
    at Object.j (C:\Code\my-project\node_modules\karma\lib\launcher.js:108:17)
    at Object.setTimeout.bind.j (C:\Code\my-project\node_modules\qjobs\qjobs.js:143:18)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'spawn'
}

The solution for me was to uninstall and reinstall Google Chrome on my corporate laptop.我的解决方案是在我的公司笔记本电脑上卸载并重新安装 Google Chrome。

The possible solution could be(point no. 2 worked for me)可能的解决方案可能是(第 2 点对我有用)

  1. Re-installing google chrome.(This might help users who uses local chrome.exe file)重新安装谷歌浏览器。(这可能有助于使用本地 chrome.exe 文件的用户)
  2. My project was using chromium to run ChromeHeadless, I had to comment CHROME_BIN in karma-conf file which was pointing to chromium path.我的项目使用 chromium 来运行 ChromeHeadless,我不得不在指向 chromium 路径的 karma-conf 文件中注释 CHROME_BIN。 By doing so, Karma will take the local chrome.exe file(C:Program File\Google\Chrome\Application\chrome.exe) instead of chromium path.通过这样做,Karma 将采用本地 chrome.exe 文件(C:Program File\Google\Chrome\Application\chrome.exe)而不是 chromium 路径。 This solution resolved my issue and I could run the test cases locally.这个解决方案解决了我的问题,我可以在本地运行测试用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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