Running Nodeunit Tests
In this section:
- Introduction
- Creating and running unit tests for Node.js applications
- Enabling unit testing for Node.js applications
- Creating Nodeunit tests
- Creating a Nodeunit run configuration
Introduction
PhpStorm supports integration with the nodeunit framework thus enabling running unit test for Node.js applications.
This topic provides guidelines in Node.js-specific unit testing procedures. For general information on testing in PhpStorm, see the section Testing.
Creating and running unit tests for Node.js applications
To create and run unit tests for a Node.js application, perform these general steps
- Enable nodeunit support.
- Write the unit tests.
- To have PhpStorm recognize the unit tests and detect the corresponding production source code, mark the folder where the unit tests are stored as test folder.
- Create a run configuration of the type Nodeunit.
- Launch unit tests and monitor test results in the Run tool window.
Enabling unit testing for Node.js applications
To enable unit testing for Node.js applications
- Download, install, and enable the Node.js plugin. The plugin is not bundled with PhpStorm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- Download and install the Node.js runtime environment.
- Download and install the nodeunit testing framework
Creating Nodeunit tests
To create Nodeunit tests
- Create a folder
test
at the same level as thesrc
folder - Populate the
test
folder. For each production file, create a separate test file. - Mark the folder where the tests are stored as test folder.
Creating a Nodeunit run configuration
To create a Nodeunit run configuration
- Open the Run/Debug Configuration dialog box by choosing on the main menu.
- Click the Add button on the toolbar and select the Nodeunit configuration type.
- In the dialog box that opens, specify the following:
- The name to identify the configuration.
- The path to the NodeJS installation to use.
If you have appointed one of the installations as default, the field displays the path to its executable file.
- The working directory. This can be the project root folder or the parent directory for the
test
folder. - The scope of tests to run.
- To have PhpStorm run all the test files in a folder, choose All JavaScript test files in the directory from the Run drop-down list. In the Directory text box, type the path to the test folder relative to the working directory.
- To have a specific test executed, choose JavaScript test file from the Run drop-down list. In the JavaScript test file text box, type the path to the file relative to the working directory.
- Apply the changes and close the dialog box.
See Also
Last modified: 19 July 2017