Running Unit Tests on Karma

Introduction

JavaScript unit tests are run in a browser against a test server which actually handles the testing
process.

This server allows you to capture a browser to run tests in, loads the test targets to the captured
browser, controls the testing process, and exchanges data between the browser and RubyMine,
so you can view test results without leaving the IDE.

The test server does not necessarily have to be on your machine, it can be launched right from RubyMine
through the Karma test runner.

Karma executes unit tests according to a karma.conf.js configuration file
which is generated semi-automatically in the interactive mode.

Before you start

To prepare working with Karma test runner, follow these steps:

Download and install Node.js. The runtime environment is required for two reasons:

The Karma test runner is started through Node.js.

NPM, which is a part of the runtime environment, is also the easiest way to download the Karma test runner.

If you are going to use the command line mode, make sure the path to the parent folder of the Node.js executable file
and the path to the npm folder are added to the PATH variable.
This enables you to launch the Karma test runner and npm from any folder.

Generating a Karma configuration file

Karma executes unit tests according to a karma.conf.js configuration file
which is generated semi-automatically in the interactive mode. The instruction below ensures successful
creation of a consistent configuration file karma.conf.js which in its turn ensures successful
execution of the tests in your project. For more details, see
http://karma-runner.github.io/0.10/config/configuration-file.html.

To create a Karma configuration file, follow these steps:

In the command line mode, switch to your project directory.

Type the following command at the command line prompt:

karma init

If Karma does not start, check the installation: the parent folder or the Karma executable file
should be specified in the PATH variable.