
If a launch.json file doesn’t already exist within the. Take note of that port number, as you’ll need to reference the same number in VS Code. An informative message will appear in the console stating that a debugger is listening on a certain port (see the screenshot below). For now, open a command shell and run this command from there. Unfortunately, NPM scripts aren’t yet discoverable by VS Code’s Command Palette however, it is a highly requested feature which is under consideration for a future release. Run it like this in the command shell: npm testĪt the time of writing, I’m using VS Code 0.9.1. I stress “reserved” because that means the run keyword isn’t required to execute the script. Specifically, the reserved test script may be a great fit for this.

Stash that command away in a package.json script, and you’ll never have to remember or type it again: In the command shell, this looks as follows: mocha -debug-brk As an aside, note that this argument will cause Node to halt execution on the first line of the JavaScript file, even without a breakpoint at that location. Show Me the Steps!Īs described in the “Usage” section of Mocha’s Getting Started page, there’s a -debug-brk CLI argument which can be passed to enable a Node debugging session. What follows is a summary of steps required to setup the desired debugging experience. Having never debugged Mocha unit tests in VS Code, I was reluctantly venturing into uncharted territory. Unfortunately, one of the pre-existing tests was failing on Windows with the latest version of Node (v4.0+) and, I wanted to dig deeper to understand the root cause. While working on a recent GitHub pull request for OmniSharp’s ASP.NET 5 Yeoman generator, I needed to test my changes prior to submitting. Thankfully, VS Code provides first-class Node.js debugging, which makes this type of development experience virtually pain-free.


If you’re anything like me, Mocha has become your framework of choice, and Visual Studio Code is your JavaScript editor of choice. To support that testing need, there are several popular unit testing frameworks available, including QUnit, Jasmine, and Mocha. It isn’t always the case in the real world, but the two should move in lockstep. As your JavaScript code base grows and evolves, the need for a solid unit testing story becomes paramount.
