Is it possible to add breakpoints to ones Mocha tests using Visual Studio Code?
Normally when debugging code one need to configure the launch.json, setting the prog
I've figured out a way to do this which I classify as a workaround. I expect the Visual Studio Code team to provide a more definitive solution for this but meanwhile this what I've done:
./settings/mocha.js
file which runs mocha programatically passing arguments as a list of files to be run. You can see the full file here;I've created a launch config which will run the ./settings/mocha.js
as the program
and passes the files/file patterns we need to test as arguments:
{
"name": "Unit tests",
"type": "node",
"program": ".settings/mocha.js",
"stopOnEntry": true,
"args": ["test/unit/*.js", "test/unit/**/*.js"],
"cwd": ".",
"runtimeExecutable": null,
"env": { }
}
Full launch.json example
So this is the equivalent of doing mocha test/unit/*.js test/unit/**/*.js
and now we can use breakpoints in our mocha tests.