Karma - Chrome failed 2 times (cannot start). Giving up

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 00:41:16

I had the same problem and tried a lot of the suggested solutions I found, but what finally solved it for me was to delete the node_modules folder and getting everything new via npm install

Had the same issue with my build environment.

What i did is to follow the advice of Rafael Cichocki to enable the debugging:

logLevel: config.LOG_DEBUG

Then tried to launch the chrome-browser with exactly the same line that was visible int he debug output.

Turned out that chrome browser was crashing due to missing ttf fonts. So running:

apt-get install ttf-freefont

Solved that issue for me and karma started to launch chrome.

I noticed when I had this error that when I changed the spec file and saved it, it seemed to work again. I had a few errors in typescript that didn't break the tests (passing in null arguments to a virtual component instance constructor). I don't know if it was resolving the errors since they existed before when it was working, or if changing the file and saving it updated the cache.

So this could mean that clearing the cache in Chrome could also potentially resolve it. It's working now again for me so I can't check to verify.

Solution for us with angular cli was setting the following properties in the karma.conf.js

 autoWatch: false,
 singleRun: true
Rafael Emshoff

I got my inspiration partially from here: https://stackoverflow.com/a/33802985/1534823

Also use logLevel: config.LOG_DEBUG - it can help you get good information on what is causing your error`

Check following settings in karma.conf:

captureTimeout: 60000,
browserNoActivityTimeout: 360000
browser: ["Firefox"]
  • captureTimeout - your browser may take some time to start. LOG_DEBUG should show some error related to capturing your browser
  • browserNoActivityTimeout - PhantomJS is really slow(x10) on my machine, in comparison to Firefox and Chrome. Karma may timeout before your tests complete.
  • browser - our jenkins server runs on linux, where we had no binaries for chrome, so we had to switch to firefox

If any of these three settings were not set correctly, we would get the error you described above.

Brian

I was able to resolve this by remove the absolute path (src/examplePath) and changing it to a relative path (../../examplePath).

Example change in spec:

import { myPackage } from 'src/myPath'; (seems to be the issues)

import { myPackage } from '../../../myPath'; (seems to resolve it)

Note I had tried deleting the node modules and npm installing but that didn't work. I'm so not sure why this matters.

Just in case you are running this behind a corporate proxy. Make sure you include your 0.0.0.0 in your NO_PROXY Environment variable.

Otherwise your test will first go out through your firewall where it will most likely not be able to reach 0.0.0.0. So just to be sure I include the following in my

NO_PROXY=127.0.0.1,localhost,0.0.0.0

Especially if you are running your tests in a container environment (e.g. your build pipeline) non set environment variables might be a common reason for ng test working fine on your local machine but failing to connect to google-chrome in the container.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!