How can I run mocha tests remotely on IntelliJ IDEA 13 (or WebStorm)?

IntelliJ IDEA 13 has really excellent support for Mocha tests through the Node.js plugin:

The problem is, while I edit code on my local machine, I have a VM (vagrant) in which I run and test the code, so it’s as production-like as possible.

I wrote a small bash script to run my tests remotely on this VM whenever I invoke “Run” from within IntelliJ, and the results pop up in the console well enough, however I’d love to use the excellent interface that appears whenever the Mocha test runner is invoked.

Any ideas?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Update: There’s a much better way to do this now. See


Here’s how I did it. This is specific to connecting back to vagrant, but can be tweaked for any remote server to which you have key-based SSH privileges.

  1. Somewhere on your remote machine, or even within your codebase, store the NodeJS plugin’s mocha reporter (6 .js files at the time of this writing). These are found in NodeJS/js/mocha under your main IntelliJ config folder, which on OSX is ~/Library/Application Support/IntelliJIdea13. Know the absolute path to where you put them.
  2. Edit your ‘Run Configurations’
  3. Add a new one using ‘Mocha’
  4. Set ‘Node interpreter’ to the full path to your ssh executable. On my machine, it’s /usr/bin/ssh.
  5. Set the ‘Node options’ to this behemoth, tweaking as necessary for your own configuration:
    -i /Users/USERNAME/.vagrant.d/insecure_private_key [email protected]_IP "cd /vagrant; node_modules/mocha/bin/_mocha --recursive --timeout 2000 --ui bdd --reporter /vagrant/tools/mocha_intellij/mochaIntellijReporter.js test" #

    REMEMBER! The # at the end is IMPORTANT, as it will cancel out everything else the Mocha run config adds to this command. Also, remember to use an absolute path everywhere that I have one.
  6. Set ‘Working directory’, ‘Mocha package’, and ‘Test directory’ to exactly what they should be if you were running mocha tests locally. These will not impact the test execution, but this interface WILL check to make sure these are valid paths.
  7. Name it, save, and run!

Fully integrated, remote testing bliss.

Solution 2

1) In Webstorm, create a “Remote Debug” configuration, using port 5858.
2) Make sure that port is open on your server or VM.
3) On the remote server, execute Mocha with the --debug-brk option: mocha test --debug-brk
4) Back in Webstorm, start the remote-debug you created in Step 1, and and execution should pause on set breakpoints.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply