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:
- Ctrl+Shift+B – runs your build task which, in this case, starts a Node.js Express server and runs Karma in the background
- Ctrl+Shift+T – runs your test task which only runs your Karma tests in the background
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.
- Right-Click on “karma”
- Under “Bindings”, choose “After Build”
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).