Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure Karma to open a browser with command line arguments?

Tags:

karma-runner

I'm using the Karma Test Runner and I've configured it to use Chrome and PhantomJS like this:

browsers = ['Chrome', 'PhantomJS'];

How can I configure Karma to open these browsers with certain command line arguments, like --diable-web-security in the case of Chrome, and --web-security=no in the case of PhantomJS?

I suppose one option would be to write a custom browser script, but that seems like overkill if there is some feature in Karma I don't know about that handles this case.

like image 618
Anonymous Avatar asked Jul 15 '13 19:07

Anonymous


People also ask

How do I create a karma config file?

In order to serve you well, Karma needs to know about your project in order to test it and this is done via a configuration file. The easiest way to generate an initial configuration file is by using the karma init command. This page lists all of the available configuration options.

How do I run a karma test without a browser?

Correct - Karma requires a browser to run. BUT - you can run Chrome in Headless mode, which means although you do need the browser installed, it will not open it's UI, and you can therefore run the tests purely through an SSH session for example.

What is karma config js file?

Most of the framework adapters, reporters, preprocessors and launchers needs to be loaded as plugins. The Karma configuration file can be written in JavaScript or CoffeeScript and is loaded as a regular Node. js module. Within the configuration file, the configuration code is put together by setting module.

What does it mean to set the single run attribute to true located in the Karma Conf js file?

Setting singleRun: false assumes that you are explicitly start the karma-client manually. This means that you start karma (technically the karma-server), then go to another terminal and type karma run . Setting singleRun: true in your karma configuration will call karma run for you.


1 Answers

Something like this should work:

// karma.conf.js
module.exports = function(config) {
  config.set({
    browsers: ['Chrome_without_security','PhantomJS_without_security'],

    // you can define custom flags
    customLaunchers: {
      Chrome_without_security: {
        base: 'Chrome',
        flags: ['--disable-web-security']
      },
      PhantomJS_without_security: {
        base: 'PhantomJS',
        flags: ['--web-security=no']
      }
    }
  });
};

More information here: https://github.com/karma-runner/karma-chrome-launcher#configuration

like image 103
glyphobet Avatar answered Sep 25 '22 11:09

glyphobet