IntelliJ IDEA 2021.1 Help

Testing Node.js

With IntelliJ IDEA, you can test Node.js applications using numerous frameworks. Since May 2018, Nodeunit is deprecated. See the Nodeunit official website for details.

Before you start

  1. Make sure the Node.js plugin is enabled on the Settings/Preferences | Plugins page, tab Installed, see Managing plugins for details.

  2. Download and install a testing framework.

Creating and running unit tests for Node.js applications

  1. Write the unit tests.

  2. Mark the folder where the unit tests are stored as a test source folder, see Content roots.

  3. Create a run configuration of the type Nodeunit.

  4. Launch unit tests and monitor test results in the Run tool window.

Creating Nodeunit tests

  1. Create a folder 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 Content roots.

Creating a Nodeunit run configuration

  1. Open the Run/Debug Configuration dialog by choosing Run | Edit Configurations from the main menu.

  2. Click the Add button the Add button on the toolbar and select the Nodeunit configuration type.

  3. In the dialog that opens, specify the following:
    1. The name to identify the configuration.

    2. Specify the Node.js interpreter to use. This can be a local Node.js interpreter or a Node.js on Windows Subsystem for Linux.

    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 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 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.

Last modified: 02 June 2021