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 program attribute to the javascript file to execute. I am not sure how to do this for for Mocha though.
When using TypeScript, the following configuration works for me in Visual Studio Code 0.8.0 (tsc 1.5.3)
tsconfig.json
The important things to note here is that source maps are generated and that the output directory for the js is set to
build
launch.json
Please note that
sourceMaps
is set totrue
and that theoutDir
is set tobuild
to debug
index.ts
any other imported typescript filemocha --debug-brk ./build/test/appTests.js
in the launch.json, add 1 more configuration below
if you need to configure node version, simply add
runtimeExecutable
field like thisFor anyone using Windows. If you have installed mocha globally then setting program to the following path worked for me (swap in your username).
If you add ${file} variable at the end of the args list you can start debugging directly from the file you have open:
Another way is to use the
--debug-brk
command line option of mocha and the defaultAttach
launch setting of the Visual Studio Code debugger.Suggested deeper explanation (from André)
To do this:
Run mocha from the command line using this command:
Now in VS Code click on the Debug icon, then select
Attach
from the option next to the start button. Add breakpoints in VS Code and then click start.For those that are using grunt or gulp, the configuration is pretty simple.
Launch.json
Gruntfile.js