Running karma tests with chrome and gitlab ci

Hi. I’m trying to use karma tests on shared runners, but I ended up with:

$ ./node_modules/.bin/ng test --watch=false --code-coverage=true --single-run=true --browser=ChromeHeadless
27 02 2018 15:44:22.805:INFO [karma]: Front-end scripts not present. Compiling...
27 02 2018 15:44:37.536:INFO [karma]: Karma v2.0.0 server started at
27 02 2018 15:44:37.537:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
27 02 2018 15:44:37.541:INFO [launcher]: Starting browser ChromeHeadless
27 02 2018 15:44:37.543:ERROR [launcher]: No binary for ChromeHeadless browser on your platform.
  Please, set "CHROME_BIN" env variable.

This is my .gitlab-ci.yml setup:

image: node:8.9.4

  - npm install

  - node_modules/

  - test

  stage: test
    - linux
    - ./node_modules/.bin/ng test --watch=false --code-coverage=true --single-run=true --browser=ChromeHeadless
      - coverage/*
  coverage: '/(\d*.?\d+)%/'

And I have included ChromeHeadless within my karma.conf.js file. Why does a runner still asks for chrome, even though it should support headless chrome by default? I’ve tried using CHROME_BIN=$( which google-chrome ) to set env variable, but it didn’t help.

I have resolved issue. One must install chrome manually and then call ChromeHeadless with --no-sandbox flax. I.e. use the combination of these two following links:

Chrome installation:

Look at the workaround for chrome flag:

I did face same issue, test stage was failing in gitlab ci with “No binary for ChromeHeadless browser on your platform. Please, set “CHROME_BIN” env variable.” error.

I tried @nerds-and-company approach and it works like champ.

But my only concern is that, I had only 5 tests to run, but it took 9 minutes 9 seconds to complete test stage. It is because I had to install chrome manually.

Is there a faster way to achieve this?

Yes, the solution is really slow, because chrome is installed before any test. I ran jasmine unit tests and e2e tests in parallel, and each job installs chrome individually. I haven’t found an easier way to do it than this. Maybe building a docker image with preinstalled Chrome and setting your own runner. But that’s an overkill, and may not be an option if you do not have money or infrastructure or time to build your own runner. On a shared runner, it seems that this is the optimal solution. I’ve seen gitlab using this image in their CI:

  image: ""

I haven’t tested to include it. But you could give it a go.

I am currently using to run my builds it is usable and does not give errors in chrome headless

1 Like

@webmutation How can I include it in the .gitlab-ci.yml? Will it work if I include it as: image: weltn24/up-docker-node-chrome-headless?

yes. that was all I had to do. Just include that in the yml file it will download the image from docker hub and then run your application build there. I am using it to build and unit test Karma - Angular 5.x applications.

Thanks, will try it out!

No problem. Another one I am using is atlassianlabs/docker-node-jdk-chrome-firefox it has chrome and firefox and jdk+maven I sometimes need to pakcage dist into war files to deploy to weblogic and use that image for that reason. But it’s bigger (size) than the other one.

Sounds awesome. But I do not need jdk. But chrome+firefox would be neat, I haven’t really tried my jasmine tests on firefox, and I should.

1 Like