The configuration file karma.conf.js can be generated using karma init from console.
This file can be modified from console with an editor, for example nano karma.conf.js.

The file karma.conf.js is easy to understand:

//Karma configuration
module.exports = function(config) {
 config.set({

 //base path, that will be used to resolve files and exclude
 basePath: '',

 //frameworks to use
 frameworks: ['jasmine'],

 //list of files / patterns to load in the browser
 files: ['**/*.js'],

 //list of files to exclude
 exclude: [ ],

 //web server port
 port: 9876,

 //enable/disable colors in the output (reporters and logs)
 colors: true,

 //level of logging
 //possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
 logLevel: config.LOG_INFO,

 //enable/disable watching file and executing tests whenever any file changes
 autoWatch: true,

 //Start these browsers, currently available:
 //- Chrome
 //- ChromeCanary
 //- Firefox
 //- Opera (has to be installed with `npm install karma-opera-launcher`)
 //- Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
 //- PhantomJS
 //- IE (only Windows; has to be installed with `npm install karma-ie-launcher`)

 browsers: ['Chrome','Firefox'],

 //If browser does not capture in given timeout [ms], kill it
 captureTimeout: 60000,

 //Continuous Integration mode
 //if true, it capture browsers, run tests and exit
 singleRun: true,

 //allure reports
 reporters: ['progress','junit'],

 junitReporter: {
 outputFile: 'testjs/test-results.xml'
 }
 });
};

…and modify (my karma.conf.js):

module.exports = function(config) {
 config.set({ 
  basePath: '', 
  frameworks: ['jasmine'], 
  files: ['testjs/**/*.js'], 
  exclude: [ ], 
  port: 9876, 
  colors: true, 
  logLevel: config.LOG_INFO, 
  autoWatch: true, 
  browsers: ['Chrome','Firefox','Safari','PhantomJS'], 
  captureTimeout: 60000, 
  singleRun: true, 
  reporters: ['progress','junit','coverage'], 
  junitReporter: { 
   outputFile: 'testjs/test-results.xml' 
  }, 
  coverageReporter: { 
   type: 'cobertura', 
   dir: 'coverage/', 
   file: 'coverage.xml' 
  } 
 }); 
};

When starting Karma, the configuration file path can be passed in as the first argument.
By default, Karma will look for karma.conf.js in the current directory.

From console: karma start my.conf.js

Karma configuration and start site

karma browsers

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page