This tutorial describes how to use the Karma test runner in the WebStorm IDE.

Karma integration in WebStorm

Starting with WebStorm 7.0, you can use the Karma test runner to run JavaScript tests for your project.
Karma integration in WebStorm:

Installing Karma

First, make sure that Node.js is installed on your computer.

Install Karma using npm:

The recommended approach is to install Karma (and all the plugins your project needs) locally in the project's directory.

Use WebStorm’ built-in npm ( Settings | JavaScript | Node.js and NPM) search and install Karma for your project.

Or install it in the current directory using Terminal:

npm install karma

Install karma-cli globally:

Use WebStorm’ built-in npm and search for karma-cli, add -g option before hitting Install for global installation.
Or use built-in Terminal to install karma-cli with:

npm install -g karma-cli

Karma configuration

To run new tests with Karma, you need to have a Karma configuration file (learn more about it).

To generate new configuration file, for example, karma.conf.js in the project directory run in built-in Terminal:

karma init karma.conf.js

Follow the suggested steps in the configuration dialog.

Note: Most of the framework adapters, reporters, preprocessors and launchers need to be loaded as plugins.

Create a WebStorm Karma Run Configuration:

Running tests


A new Karma Configuration will be added to the list of Run/Debug Configurations.
To start running your tests, click Run in the toolbar or in the context menu of Karma configuration file.

Note: WebStorm disables autoWatch in Karma configuration.
You can rerun your tests with the shortcut Alt+Shift+R on Win/Linux or ctrl-cmd-R on Mac.
Click auto-test in the WebStorm Test Run window to enable automatic test rerun: The test will be run 10 seconds after your code was changed, if there are no syntax errors.

Run with coverage

WebStorm Karma integration allows you to run tests with code coverage provided by the istanbul code coverage engine.

To use Run with coverage feature, a karma-coverage module should be installed via npm.

Make the required changes in the Karma configuration file, for example:

reporters: ["coverage"],
    preprocessors: {
        "**/*.js": "coverage"

You can navigate through test results in the Run window, check statistics for the tests execution, and make HTML reports from it. Code coverage report will be also available.