Evan Cordulack

Configuring IntelliJ to Run Mocha Tests

February 25, 2020

Create a New Configuration

IntelliJ Mocha Configuration Example

Options

  • Node Interpreter: This should autofill
  • Working Directory: I have this set up to the same place as my package.json. This may or may not be the root of your project.
  • Mocha Package: This should autofill to the mocha directory in node_modules
  • User Interface: select whatever style you use in your tests: https://mochajs.org/#interfaces
  • Test File Patterns: This is the same pattern that I would use if I ran the tests from the command line mocha ./src/**/*.test.js

How To See Your Tests After Running Them

Click "Show Passed" and "Expand All." You can double-click on a test to view the test in your editor.

IntelliJ Mocha Configuration Example

Other Tips

If you have a project with more than one set of tests, create a compound Run/Debug Configuration so you can run multiple test suites at once. https://www.jetbrains.com/help/idea/creating-compound-run-debug-configuration.html