IntelliJ IDEA 2017.3 Help

Testing Node.js

This feature is only supported in the Ultimate edition.

The following is only valid when Node.js Plugin is installed and enabled!

IntelliJ IDEA integrates with the nodeunit framework and makes it easier to test Node.js applications.

Creating and running unit tests for Node.js applications

  1. Enable nodeunit support.
  2. Write the unit tests.
  3. Mark the folder where the unit tests are stored as a test source folder, see Configuring projects.
  4. Create a run configuration of the type Nodeunit.
  5. Launch unit tests and monitor test results in the Run tool window.

Before you start

  1. Download, install, and enable the Node.js plugin. The plugin is not bundled with IntelliJ IDEA, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
  2. Download and install the Node.js runtime environment.
  3. Download and install the nodeunit testing framework.

Creating Nodeunit tests

  1. Create a folder called test at the same level as the src folder
  2. Populate the test folder. For each production file, create a separate test file.
  3. Mark the folder where the unit tests are stored as a test source folder, see Configuring projects.

Creating a Nodeunit run configuration

  1. Open the Run/Debug Configuration dialog box by choosing Run | Edit Configurations on the main menu.
  2. Click the Add button new on the toolbar and select the Nodeunit configuration type.
  3. In the dialog box that opens, specify the following:
    1. The name to identify the configuration.
    2. The path to the Node.js installation to use.

      If you have appointed one of the installations as default, the field displays the path to its executable file.

    3. The working directory. This can be the project root folder or the parent directory for the test folder.
    4. The scope of tests to run.
      • To have IntelliJ IDEA 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.
  4. Apply the changes and close the dialog box.
Last modified: 16 December 2017

See Also