简体   繁体   English

在docker内部使用无头的chrome运行ng测试(angular-cli karma测试)

[英]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.

相关问题 无法使用 chrome-headless 在 docker 中运行 angular-cli karma-tests - Unable to run angular-cli karma-tests in docker with chrome-headless 是否可以使用angular-cli`ng test`运行angularJS单元测试? - is it possible to run angularJS unit tests with angular-cli `ng test`? Ng 测试抛出错误找不到模块 'angular-cli/plugins/karma' - Ng test throws an error Cannot find module 'angular-cli/plugins/karma' 使用Angular-CLI使用Karma和Jasmine设置进行ng测试时出现许多错误 - So many errors on ng test with Karma and Jasmine setup using Angular-CLI ng测试抛出错误:找不到模块'@ angular-cli / plugins / karma' - ng test throws Error: Cannot find module '@angular-cli/plugins/karma' angular-cli简单配置,无需测试和ng服务 - angular-cli simple configuration without test and ng serve Angular-Cli-测试服务 - Angular-cli - Test Service Angular CLI - Karma测试版本没有找到ng2-material - Angular CLI - Karma test build not finding ng2-material 当我使用最新的angular-cli(beta 15 w / webpack)运行测试时,如何提供资产? - How do I serve assets when I run ng test using latest angular-cli (beta 15 w/webpack)? Angular 2 - 具有依赖性的angular-cli管道测试 - Angular 2 - angular-cli pipe test with dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM