With everything installed and configured, you are now ready run your tasks.

Visual Studio Code

In the previous step, you configured your VS Code tasks.  To run them, there are two options:

  1. Ctrl+Shift+B – runs your build task which, in this case, starts a Node.js Express server and runs Karma in the background
  2. Ctrl+Shift+T – runs your test task which only runs your Karma tests in the background

Visual Studio

There’s not much to do in Visual Studio except for binding your Karma task to your debugging execution pipeline.  In the Task Runner Explorer (NOTE: this is installed by default in Visual Studio 2015, but is an extension that must be installed for Visual Studio 2012 and Visual Studio 2013), you should see your three tasks listed.

  1. Right-Click on “karma”
  2. Under “Bindings”, choose “After Build”

Technically, because we are testing JavaScript, you could choose “Before Build,” but in larger projects you may have additional tasks in your build process (e.g. minification, bundling, jshint, etc.)  Now, every time you build your application, the “karma” task will run.  And, theoretically, if you are actively developing JavaScript, you’ll only need to build your project once and keep it running, while modifying your JavaScript and refreshing your browser.

Sample Application

In the attached .zip file, you’ll find a sample AngularJS application.

IMPORTANT: If you are wanting to open this in VS Code or run the Express web server, you will need to make sure you have Node.js installed on your local machine.

If you are running this in VS Code, you will need to go the folder in which you unzipped this file and run the two commands in a command prompt:

This will download and install all dependencies.

If you open the folder in Visual Studio, then the dependencies will be downloaded for you automatically.

Also, if you choose to run the “server” task in VS Code, you can navigate to http://localhost:45000 to see the sample default.html page (provided that nothing else is running on port 45000).

The attached project will show 4 passing tests and 1 failing test (3+10=13, not 15).


Like What You See?

Subscribe to receive new posts in your inbox.