Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set config's 'browsers' property in the command line in karma runner

I usually use browsers=['PhantomJS'] for running my specs with karma because it's faster than chrome and I find a bit annoying when chrome opens the browser in front of the window on every boot.

But when I have a bug and I need to debug, I change karma.conf.js browsers to ['Chrome'].

I would like to set this property when I start karma, something like: 'karma start --browsers=[Chrome]'.

Is this posible?

like image 386
Tomas Romero Avatar asked May 24 '13 03:05

Tomas Romero


People also ask

What does it mean to set the singleRun 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.

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.

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.

What are preprocessors in karma?

Preprocessors in Karma allow you to do some work with your files before they get served to the browser. These are configured in the preprocessors block of the configuration file: preprocessors: { '**/*. coffee': ['coffee'], '**/*.


1 Answers

you just have to use the --browsers parameter and it'll overide your config file browsers part.

$ karma start config/testacular.conf.js --browsers Chrome

where Chrome is the name of the browser or a path to a binary.

For example, I have only a small Qt browser configured. if I use the line above, it runs Chrome instead.

INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 24.0 (Linux)]: Connected on socket id DxbVJNX0jIoe1CbaWf9V
Chrome 24.0 (Linux): Executed 74 of 74 SUCCESS (0.443 secs / 0.232 secs)
...

or, for example, I have firefox beta, aurora and release in my home. I run beta with:

$ karma start config/testacular.conf.js --browsers ~/firefox/firefox
$ karma start --help
Karma - Spectacular Test Runner for JavaScript.

START - Start the server / do a single run.

Usage:
  karma start [<configFile>] [<options>]

Options:
  --port                <integer> Port where the web server is running.                        
  --runner-port         <integer> Port where the server is listening for runner.               
  --auto-watch          Auto watch source files and run on change.                             
  --no-auto-watch       Do not watch source files.                                             
  --log-level           <disable | error | warn | info | debug> Level of logging.              
  --colors              Use colors when reporting and printing logs.                           
  --no-colors           Do not use colors when reporting or printing logs.                     
  --reporters           List of reporters (available: dots, progress, junit).                  
  --browsers            List of browsers to start (eg. --browsers Chrome,ChromeCanary,Firefox).
  --capture-timeout     <integer> Kill browser if does not capture in given time [ms].         
  --single-run          Run the test when browsers captured and exit.                          
  --no-single-run       Disable single-run.                                                    
  --report-slower-than  <integer> Report tests that are slower than given time [ms].           
  --help                Print usage and options.                                               
  --version             Print current version.
like image 182
Eduard Gamonal Avatar answered Sep 17 '22 15:09

Eduard Gamonal