Monday, August 24, 2015

Setup VS for "Integrated" Karma Testing

If you're at all interested in unit testing your JavaScript, specifically your AngularJS areas, you may be using Karma and Jasmine.  If you're like me and you do most of your coding in Visual Studio you might wish there was some integration to be had between VS and your Karma tests.  Good news, there is!  Sort of.

There's an extension you can install that will reroute the output from Karma to your Output window in Visual Studio.  It's not the best way to integrate, but it definitely works as long as you get it all set up properly.  Hopefully these instructions get you there.
  1. Download the extension from here and install it
  2. Make sure your Karma config file is named karma.unit.conf.js (or karma.e2e.conf.js) and is saved at the root of your project (seriously, you can't put it anywhere else or name it anything else or it won't work)
  3. Everything else is standard for Karma so there shouldn't be any other setup necessary specifically for this extension
The extension will run your tests every time you launch the solution, and you can toggle it on and off by going to Tools > Enable/disable Karma unit testing...

The only other caveat is that in your Output window you'll need to make sure the "Show output from:" dropdown is set to Karma.

No comments:

Post a Comment