angulargitlab-ciangular10

ng test for Angular 10 hangs out in gitlab ci


I'm configuring gitlab ci to run Angular 10 tests.
But they hang out (run longer than 10 minutes).
Why does it happen? How could it be fixed?

Application used has been created by ng new <app-name>.

.gitlab-ci.yml

image: node:14.13.1-alpine3.12

before_script:
  - npm install @angular/cli

build:
  stage: build
  script: npm test --watch=false
  only:
    - master
    - merge_requests

Last logs from ci

Compiling @angular/router/testing : es2015 as esm2015
09 10 2020 09:32:21.905:WARN [karma]: No captured browser, open http://localhost:9876/
09 10 2020 09:32:21.911:INFO [karma-server]: Karma v5.0.9 server started at http://0.0.0.0:9876/
09 10 2020 09:32:21.912:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
09 10 2020 09:32:21.917:INFO [launcher]: Starting browser Chrome
09 10 2020 09:32:21.919:ERROR [launcher]: No binary for Chrome browser on your platform.
  Please, set "CHROME_BIN" env variable.
09 10 2020 09:32:26.975:WARN [karma]: No captured browser, open http://localhost:9876/

Solution

  • it does not work and it's normal because In a CI environment like gitlab-ci, there is no graphical user interface available to run a browser in it like your do it in your local env, you have to configure PhantomJS or other solutions, you have to update your karma.conf.js:

    browsers: ['ChromeHeadless'],
    

    in case you use PhantomJS

    npm install --save-dev phantomjs-prebuilt karma-phantomjs-launcher
    

    add this line to your plugins

    plugins: [
      require('karma-jasmine'),
      require('karma-phantomjs-launcher'),  // add this line 
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    ...
    browsers: ['PhantomJS'],
    

    maybe you need to add some polyfills for that

    you can test it locally

    ng test --watch=false