Heads Up! You're viewing the docs for v0.13, an old version of Karma. v6.4 is the newest.

Developing Plugins

Karma can be extended through plugins. A plugin is essentially an NPM module. Typically, there are four kinds of plugins: frameworks, reporters, launchers and preprocessors. The best way to understand how this works is to take a look at some of the existing plugins. Following sections list some of the plugins that you might use as a reference.

Frameworks #

Reporters #

Launchers #

Preprocessors #

Crazier stuff #

Karma is assembled by Dependency Injection and a plugin is just an additional DI module (see node-di for more), that can be loaded by Karma. Therefore it can ask for pretty much any Karma component and interact with it. There are couple of plugins that do more interesting stuff like this, check out karma-closure, karma-intellij, karma-dart.

Karma Framework API #

Karma Framework connect existing testing libraries to Karma's API, so that their results can be displayed in a browser and sent back to the server.

Karma frameworks must implement a window.__karma__.start method that Karma will call to start test execution. This function is called with an object that has methods to send results back to karma:

  • .result a single test has finished
  • .complete the client completed execution of all the tests
  • .error an error happened in the client
  • .info other data (eg. number of tests or debugging messages)

Most commonly you'll use the result method to send individual test success or failure statuses. The method takes an object of the form:

{
    // test id
    id: String,

     // test description
    description: String,

    // the suite to which this test belongs. potentially nested.
    suite: Array[String],

    // an array of string error messages that might explain a failure.
    // this is required if success is false.
    log: Array[String],

    success: Boolean, // pass / fail

    skipped: Boolean // skipped / ran
}