|This tutorial describes how to use the Karma test runner in the WebStorm IDE.|
Karma integration in WebStorm:
- Uses local server to run the tests in the selected browsers installed on your computer;
- Allows you to run tests written with the use of Jasmine, QUnit, or Mocha, or to write a simple adapter to use any other framework you like;
- Presents test results and code coverage report by the istanbul code coverage engine right in the IDE.
Open WebStorm’ built-in Terminal (on the main menu, choose Tools | Open Terminal) and runto install Karma into your global node_modules directory and create a symlink to its binary.
Or install it in the current directory using Terminal:
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:
Follow the suggested steps in the configuration dialog.
Create a WebStorm Karma Run Configuration:
- Click Create 'karma.conf.js' in the context menu for karma.conf.js file
- Check the paths in the Create Run/Debug Configuration window
- Click OK.
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.
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:
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.