我有一个angular(5)项目,使用karma和chrome headless运行茉莉花单元测试。在本地可以正常运行,但在我们的VSTS CI服务器(安装了节点和Chrome [69]的自定义Windows 10 VM)上无法运行。
安装在VSTS VM上的build-agent作为Windows服务运行,导致chrome无头测试失败并带有超时:
2018-10-03T12:28:51.8716712Z [32m03 10 2018 12:28:04.336:INFO [karma]: [39mKarma v1.7.1 server started at http://0.0.0.0:9876/
2018-10-03T12:28:51.8717001Z [32m03 10 2018 12:28:04.336:INFO [launcher]: [39mLaunching browser ChromeHeadless with unlimited concurrency
2018-10-03T12:28:51.8717325Z [32m03 10 2018 12:28:04.351:INFO [launcher]: [39mStarting browser Chrome
2018-10-03T12:28:51.8717666Z [32m03 10 2018 12:28:40.937:INFO [HeadlessChrome 69.0.3497 (Windows 10.0.0)]: [39mConnected on socket vcUeG8L1qWsAFV7LAAAA with id 91653372
2018-10-03T12:28:51.8717989Z [33m03 10 2018 12:28:50.945:WARN [HeadlessChrome 69.0.3497 (Windows 10.0.0)]: [39mDisconnected (1 times), because no message in 10000 ms.
2018-10-03T12:28:51.8718289Z [31mHeadlessChrome 69.0.3497 (Windows 10.0.0) ERROR[39m
2018-10-03T12:28:51.8718600Z Disconnected, because no message in 10000 ms.
2018-10-03T12:28:51.8718863Z
2018-10-03T12:28:51.8719156Z HeadlessChrome 69.0.3497 (Windows 10.0.0) ERROR
2018-10-03T12:28:51.8719433Z Disconnected, because no message in 10000 ms.
2018-10-03T12:28:51.8719704Z HeadlessChrome 69.0.3497 (Windows 10.0.0) ERROR
2018-10-03T12:28:51.8720051Z Disconnected, because no message in 10000 ms.
如果我将构建代理更改为以交互方式运行,则测试将再次开始工作。但这不是一个理想的情况,因为在交互模式下,我们需要在服务器重新启动时手动重新启动build-agent。
使用以下命令运行测试
ng test --code-coverage --browsers ChromeHeadless --single-run
karma.conf.js启用了自定义启动器标志:
--headless
--disable-gpu
--remote-debugging-port=9222