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.
- In the command line mode, switch to your project directory.
Type the following command at the command line prompt:
If Karma does not start, check the installation: the parent folder or the Karma executable file should be specified in the PATH variable.
Answer the questions to specify the following basic settings:
- The testing framework to use.
- The browsers to be captured automatically.
- The patterns that define the location of test files to be involved in testing or excluded from it, for example, src/*.js and test/*.js. For more details, see http://karma-runner.github.io/0.10/config/files.html.
Open the Run/Debug Configuration dialog box by doing one of the following:
- On the main menu, choose .
- Press RunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfigurationRunConfiguration and choose Edit Configuration on the context menu.
- Open the test file in the editor, and then choose Create <file name> on the context menu.
- Select the test file in the Project tool window, and then choose Create <file name> on the context menu of the selection.
- Click the Add button on the toolbar and select the Karma configuration type.
- In the dialog box that opens, specify the location of the Node.js and Karma executable files and the path to the karma.conf.js configuration file.
- Apply the changes and close the dialog box.
To launch the tests according to a run configuration, select the Karma run/debug configuration from the list on the main toolbar.
Then click the Run button to the right of the list.
To launch a single test, open the test file in the editor and click the blue arrow icon in the gutter area next to the text to run.
The arrows appear only if the test framework used in your tests is associated with the project, so WebStorm can recognize the tests.
- The Karma test server starts automatically without any steps from your side. View and analyze messages from the test server in the Karma Server tab of the Run tool window.
- Monitor test execution in the Test Runner tab of the Run tool window as described in Monitoring and Managing Tests.