Testing Node.js
PhpStorm integrates with the nodeunit framework and makes it easier to test Node.js applications.
Creating and running unit tests for Node.js applications
- 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 a test folder.
- Create a run configuration of the type Nodeunit.
- Launch unit tests and monitor test results in the Run tool window.
Before you start
- Install Node.js and configure it as a local Node.js interpreter.
- Download and install the nodeunit testing framework.
Creating Nodeunit tests
- Create a folder called
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
- 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.
- Specify the Node.js interpreter to use, see Configuring a local Node.js interpreter for details.
- 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 field, provide 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 field, provide the path to the file relative to the working directory.
- Apply the changes and close the dialog box.
Last modified: 27 July 2018