使用 Angular CLI:1.6.6 和 Angular 5,我无法让单元测试在 headless Ubuntu 服务器上运行。
我不断得到:
20 03 2018 16:51:19.719:WARN [karma]: No captured browser, open http://localhost:9876/
在我的 karma 配置中,我有:
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--headless',
'--disable-gpu',
// Without a remote debugging port, Google Chrome exits immediately.
'--remote-debugging-port=9222',
],
}
},
对于安装在 headless 服务器上的我的浏览器:
one@work:~/github$ which google-chrome-stable
/usr/bin/google-chrome-stable
我也在全局范围内安装了 karma-chrome-launcher,但不确定是否需要它。
难道 Karma 正在寻找错误的浏览器文件名?我没有找到任何为浏览器指定文件名的指令。
有什么问题吗?
最佳答案
您缺少浏览器配置。为了使其工作,您需要将“browsers”设置为“Chromeheadless”,如下所示:
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--headless',
'--disable-gpu',
'--no-sandbox',
'--remote-debugging-port=9222',
]
}
},
browsers: ['ChromeHeadless'],
singleRun: false
希望这对您有帮助!
胡安
关于angular - Karma 不会 headless 运行 ng 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49391060/