inf3rno
inf3rno

Reputation: 26139

Run travis - karma tests on multiple browsers?

Normally it is possible with Karma to run my tests on multiple browsers. Is it possible somehow to run the same tests on Travis?

As far as I know Chrome needs some modifications on the travis config file. https://stackoverflow.com/a/25661593/607033

Do these modifications interfere with other browsers (e.g. Firefox, Opera, Msie, PhantomJS, etc.) I want to run on travis?

Upvotes: 1

Views: 622

Answers (1)

inf3rno
inf3rno

Reputation: 26139

I have come up with the following karma.conf.js file:

module.exports = function (config) {
    var options = {
        plugins: [
            "karma-browserify",
            "karma-chrome-launcher",
            "karma-firefox-launcher",
            "karma-ie-launcher",
            //"karma-opera-launcher",
            "karma-phantomjs-launcher",
            "karma-mocha"
        ],
        ...
        browsers: [
            "Chrome",
            "Firefox",
            "IE",
            //"Opera",
            "PhantomJS"
        ]
    };

    if (process.env.TRAVIS) {
        options.customLaunchers = {
            Chrome_travis_ci: {
                base: 'Chrome',
                flags: ['--no-sandbox']
            }
        };
        options.browsers = [
            "Chrome_travis_ci",
            "Firefox",
            //"IE",
            //"Opera",
            "PhantomJS"
        ];
    }

    config.set(options);
};

and the following .travis.yml:

language: node_js
node_js:
  - "5"
before_install:
  - export CHROME_BIN=chromium-browser
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start

The Internet Explorer is working only by Windows environments, so it is not supported by Travis (because it uses Linux). The karma-opera-launcher has serious bugs, so I wasn't able to use it by Travis and on Windows. According to the github page of the plugin it should work on Linux, but I did not want to spend more time on it.

So the modifications don't interfere with each other, because only Chrome requires modifications and those are contained by a custom launcher. All of the non-PhantomJS browsers require display and xvfb in the .travis.yml.

Another possible solution would be to use SauceLabs, but this testing is not critical to me, so I don't want to pay 250$/y for it.

Upvotes: 2

Related Questions