Debug mocha tests with Visual Studio Code easily

This is a really simple tip, but a load of our developers were kicking off a run of their tests by the command line, and then attaching the VSCode debugger to them to step through. VSCode offers a much easier solution to this.

Instead of doing something like this

mocha

then hitting F5 and attaching your debugger to the running process. You can set up a configuration in your launch.json file to debug these by just hitting F5.

mocha

But you don’t have to edit the file manually. VSCode does the work for you.

mocha

If you go to the debug tab in VSCode on the left hand side, then drop down the list beside the “play” button, you will have the option to “Add Configuration” click this and you will get a list of options.

mocha

This will auto populate your launch.json file for you. You can edit the default values here to suit your file structure, and use filters to only run certain files.

mocha
i.e. only files that end with .test.js etc..

This will instantly show up in your “Launch” dropdown beside the play button, and you can add breakpoints and step through your tests easily at the press of a button!

mocha

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: