RubyMine 2017.2 Help

Testing JavaScript with Jest

You can run and debug tests with Jest right in RubyMine. You can see the test results in a treeview and easily navigate to the test source from there. Test status is shown next to the test in the editor with an option to quickly run it or debug it.

Before you start

  1. Make sure the Node.js runtime environment is installed on your computer.
  2. Install and enable the NodeJS repository plugin on the Plugins page as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

Installing Jest

Open the built-in RubyMine Terminal (press Alt+F12 or choose View | Tool Windows | Terminal on the main menu) and type npm install --save-dev jest at the command line prompt.
See also Getting Started on the Jest official website.

Running tests

With RubyMine, you can quickly run a single Jest test right from the editor or create a run/debug configuration to execute some or all of your tests.

To run a single test from the editor:
Click run.png or rerun.png in the left gutter and choose Run <test_name> from the pop-up list. You can also see whether a test has passed or failed right in the editor, thanks to the test status icons ws_icon_test_status.png in the left gutter.

To create a Jest run configuration:

  1. Open the Run/Debug Configuration dialog box (Run | Edit Configurations on the main menu).
  2. Click /help/img/idea/2017.2/new.png on the toolbar and select Jest from the list. The Run/Debug Configuration: Jest dialog box opens.
  3. Specify the Node interpreter to use, the location of the jest package, and the working directory of the application. All references in test scripts will be resolved relative to this folder, unless such references use full paths.

    By default, the Working directory field shows the project root folder. To change this predefined setting, specify the path to the desired folder or choose a previously used folder from the list.

  4. Optionally specify the jest.config file to use. If the field is empty, RubyMine looks for a package.json file with a jest key. The search is performed in the file system upwards from the working directory. If no appropriate package.json file is found, then the Jest default configuration is used.

To run tests via a run configuration:

  1. Select the Jest run/debug configuration from the list on the main toolbar and click /help/img/idea/2017.2/run.png to the right of the list.
  2. The test server starts automatically without any steps from your side. View and analyze messages from the test server in the Run tool window.
  3. Monitor test execution in the Test Runner tab of the Run tool window as described in Monitoring and Managing Tests.

Navigation

With RubyMine, you can jump between a file and the related test file. Navigation from a test result in the Test Runner Tab to the test is also supported.

To jump between a file and the related test file:
Open the file in the editor and choose Go To | Test or Go To | Test Subject on the context menu, or just press Ctrl+Shift+T.

To jump from a test result to the test:
Select the test name in the Test Runner tab and choose Jump to Source on the context menu.

ws_test_jump_to_test
The test file opens in the editor with the cursor placed at the test definition.

Debugging tests

With RubyMine, you can quickly start debugging a single Jest test right from the editor or create a run/debug configuration to debug some or all of your tests.

To start debugging a single test from the editor:
Click run.png or rerun.png in the left gutter and choose Debug <test_name> from the pop-up list.

To launch test debugging via a run/debug configuration:

  1. Create a Jest run/debug configuration as described above.
  2. Select the Jest run/debug configuration from the list on the main toolbar and click /help/img/idea/2017.2/debug.png to the right of the list.
  3. In the Debug tool window that opens, proceed as usual: step through the tests, stop and resume test execution, examine the test when suspended, etc.

See Also

Last modified: 21 July 2017