I’ve been doing a lot of Node development lately, after doing mostly Java the past 10 years. There are lots of comparisons between the two, and I’ve come away with a better understanding of where one is better than the other and what I wish I could take from each one.
One thing I miss about doing Java development is being able to right-click in a single test, run it, and be able to easily debug it. You can get close to this in Node-land, but it is nowhere near as simple or seamless. You can, however, get kind of close with VS Code (which I’m loving more and more every day) by creating a custom launch configuration that lets you debug a single mocha file.
1. Create a launch configuration that only runs the current file
This creates a launch configuration that passes the current file to the mocha command.
2. If you have a mocha.opts, you may need to override it
A lot of projects have a mocha.opts file that has something like this ‘–recursive test/.’
Command-line args should override options in mocha.opts, but it looks like the file specification part does not get overridden. So, what I did was create a dummy mocha-debug.opts that is empty, then point to it in the config:
3. You can now run and debug a single Mocha file.