7

I'm trying to run tests over bitbucket platform with the following configuration:

image: node:6.8.0

pipelines:
  default:
    - step:
        script:
          - echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/chrome.list
          - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
          - set -x && apt-get update && apt-get install -y xvfb google-chrome-stable
          - ln -sf /usr/bin/xvfb-chrome /usr/bin/google-chrome
          - npm --version
          - npm install
          - npm test

And that's the output:

> ng test

Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
13 10 2016 15:26:57.937:WARN [karma]: No captured browser, open http://localhost:9876/

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
45:15 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
57:15 Critical dependency: the request of a dependency is an expression
13 10 2016 15:26:57.945:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
13 10 2016 15:26:57.946:INFO [launcher]: Launching browser Chrome with unlimited concurrency
13 10 2016 15:26:58.033:INFO [launcher]: Starting browser Chrome
13 10 2016 15:26:58.421:ERROR [launcher]: Cannot start Chrome

13 10 2016 15:26:58.532:INFO [launcher]: Trying to start Chrome again (1/2).
13 10 2016 15:26:58.813:ERROR [launcher]: Cannot start Chrome

13 10 2016 15:26:58.814:INFO [launcher]: Trying to start Chrome again (2/2).
13 10 2016 15:26:59.049:ERROR [launcher]: Cannot start Chrome

13 10 2016 15:26:59.050:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.

The problem is that karma is not able to start chrome browser. I think the problem happens with any docker enviroment. How can I run tests in bitbucket pipelines?

Serginho
  • 7,291
  • 2
  • 27
  • 52
  • Use a headless browser like PhantomJS instead? – jonrsharpe Oct 13 '16 at 18:50
  • No, use angular cli default configuration of karma and proactor. Is there any posibility to use chrome, or I have to use phantom? – Serginho Oct 19 '16 at 08:45
  • Do you particularly *want* to use a non-headless browser? Chrome is the default for Angular CLI projects, but switching to Phantom is trivial (see e.g. my project https://github.com/textbook/known-for-web). Alternatively, have you looked into something like Sauce Labs or installation e.g. Xvfb? This doesn't seem unique to bitbucket pipelines, I'd suggest some broader research. – jonrsharpe Oct 19 '16 at 08:54
  • @jonrsharpe I can use phantom, but I saw in any site that travisCI has chromium installed and users use it to execute tests. Even if you go to angular-cli project, you will see in their travis.yml that tests are run over chromium. Back to your answer, your tests are working properly with these config? – Serginho Oct 19 '16 at 11:19
  • what problem are you actually trying to solve? Do you just want to get the tests running, or get them running *in Chrome*. Yes, my tests are working, but in TravisCI not a bitbucket pipeline. – jonrsharpe Oct 19 '16 at 11:20
  • I want to run tests in general, and then in chrome. So both. – Serginho Oct 19 '16 at 12:21
  • Can you post the karma config you're using? I'm using a nearly identical pipelines config and it's working for me. – majinnaibu Jun 14 '17 at 20:03

2 Answers2

5

Try switching your tests over to PhantomJS.

Install PhantomJS Runner https://github.com/karma-runner/karma-phantomjs-launcher

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

Edit your karma.conf.js to use PhantomJS

// /karma.conf.js
module.exports = function (config) {
  config.set({
    // ...
    plugins: [
      // ...
      require('karma-phantomjs-launcher'),
      // ...  
    ],
    // ...  
    // browsers: ['Chrome'],
    browsers: ['PhantomJS'],
    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered 
      // (useful if karma exits without killing phantom)
      exitOnResourceError: true // Could require proxy if tests access images without /base path
    },
    //...
  });
};

This should now run your tests in PhantomJS instead of Chrome.

The default test script also runs watch so you might want to modify your package.json test script to be "test": "ng test --watch=false". If you want to have watch run for local development just launch with ng test instead of npm test.

Morgan O'Neal
  • 1,108
  • 1
  • 12
  • 20
0

Try relying on this image instead:

https://github.com/mark-adams/docker-chromium-xvfb

Meligy
  • 35,654
  • 11
  • 85
  • 109