[英]Run ng test (angular-cli karma test) with chrome headless inside docker
We have a docker image based on debian, and we are trying to run our karma unit test. 我们有一个基于debian的docker映像,我们正在尝试运行业力单元测试。 We are using Angular with angular-cli, so we are basically trying to launch our ng test.
我们将Angular与angular-cli一起使用,因此我们基本上是在尝试启动ng测试。
We would like to run them in an headless chrome rather than in phantomJS. 我们想在无头chrome中运行它们,而不是在phantomJS中运行它们。 In order to do that, we installed chrome and we got a dockerFile very similar to this: https://hub.docker.com/r/justinribeiro/chrome-headless/~/dockerfile/ .
为了做到这一点,我们安装了chrome并获得了一个与此非常相似的dockerFile: https ://hub.docker.com/r/justinribeiro/chrome-headless/~/dockerfile/。
We configured our karma launcher to add few options, but we are stuck on a problem. 我们配置了业力启动器以添加一些选项,但是我们遇到了问题。 It is easily reproductible by launche the command:
通过启动命令很容易复制:
google-chrome --headless --no-sandbox --disable-gpu
We got the following error: 我们收到以下错误:
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
Is somebody has an idea ? 有人有主意吗? Have to admit that we are a bit stuck, here :)
必须承认我们有点卡住,这里:)
Okay, I found the problem, wasn't related to docker actually. 好的,我发现了问题,实际上与docker无关。
I've noticed that karma was launching its server on http://0.0.0.0:9876/ , thus I had to add two new flag to my custom karma.conf to launch google-chrome on the correct port: 我注意到业力正在http://0.0.0.0:9876/上启动其服务器,因此我必须在自定义业力karma.conf中添加两个新标志,以在正确的端口上启动google-chrome:
'--remote-debugging-address=0.0.0.0',
'--remote-debugging-port=9876'
Also, I have to run the container with the --privileged attributes (or --cap-add SYS_ADMIN, but privileged is more complete). 另外,我必须使用--privileged属性(或--cap-add SYS_ADMIN,但特权更完整)来运行容器。
Maybe it'll helps somebody ;) 也许会对别人有帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.