Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.31 KB

05-plugins.md

File metadata and controls

46 lines (35 loc) · 1.31 KB

Karma can be easily extended through plugins. In fact, all the existing preprocessors, reporters, browser launchers and frameworks are also plugins.

Installation

Karma plugins are NPM modules, so the recommended way is to keep all the plugins your project requires in package.json:

{
  "devDependencies": {
    "karma": "~0.10",
    "karma-mocha": "~0.0.1",
    "karma-growl-reporter": "~0.0.1",
    "karma-firefox-launcher": "~0.0.1"
  }
}

Therefore, a simple way how to install a plugin is

npm install karma-<plugin name> --save-dev

Loading Plugins

By default, Karma loads all NPM modules that are siblinks to it and their name matches karma-*.

You can also explicitly list plugins you want to load via the plugins configuration setting. The configuration value can either be a string (module name), which will be required by Karma, or an object (inlined plugin).

plugins: [
  // these plugins will be require() by Karma
  'karma-jasmine',
  'karma-chrome-launcher'

  // inlined plugins
  {'framework:xyz', ['factory', factoryFn]},
  require('./plugin-required-from-config')
]

There are already many existing plugins. Of course, you write your own plugins too!