IntelliJ IDEA 13 has really excellent support for Mocha tests through the Node.js plugin: https://www.jetbrains.com/idea/webhelp/running-mocha-unit-tests.html
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.
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.
Update: There’s a much better way to do this now. See https://github.com/TechnologyAdvice/fake-mocha
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.
- 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/mochaunder your main IntelliJ config folder, which on OSX is
~/Library/Application Support/IntelliJIdea13. Know the absolute path to where you put them.
- Edit your ‘Run Configurations’
- Add a new one using ‘Mocha’
- Set ‘Node interpreter’ to the full path to your ssh executable. On my machine, it’s
- 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" #
#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.
- 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.
- Name it, save, and run!
Fully integrated, remote testing bliss.
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
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 🙂