The first extension allows you to right-click on your tests.js file and click a new “Run JS Tests” menu item to run your QUnit tests without launching a browser.
In order to for this to work, though, you must tell Chutzpah where to find the other JS files that your tests require (as it will not be launching your tests.html in a browser). To do this, add the following lines to the top of our tests.js file:
/// <reference path="../Scripts/jquery-1.9.1.js" /> /// /// <reference path="../Scripts/knockout-2.2.1.debug.js" /> /// /// <reference path="../Scripts/app/namespace.js" /> /// <reference path="webapiclient.stub.js" /> /// /// <reference path="../Scripts/app/model.js" /> /// <reference path="../Scripts/app/viewmodel.js" />
Even cooler, with the Test Adapter installed, you can click CTRL+R, A to run all of the unit tests in your solution, and your QUnit tests will be run too, with their results displayed within the Visual Studio testing UI:
To fix this you need to find and edit the HTML template used by Chutzpah. Search your C: drive for the text “Chutzpah” – under Windows Vista and up this should be located in a subfolder of C:UsersUserNameAppDataLocalMicrosoftVisualStudio. For instance, the path on my system is:
Once you have found the folder, open the TestFilesQUnitqunit.html file:
<!DOCTYPE html> <html> <head> @@TestFrameworkDependencies@@ @@ReferencedCSSFiles@@ @@ReferencedJSFiles@@ @@TestJSFile@@ </head> <body> <h1 id="qunit-header">Unit Tests</h1> <h2 id="qunit-banner"></h2> <h2 id="qunit-userAgent"></h2> <ol id="qunit-tests"></ol> <div id="qunit-fixture"></div> </body> </html>
Move the lines referencing the JS files to the bottom of the body, leaving the CSS reference in the head tag:
<!DOCTYPE html> <html> <head> @@ReferencedCSSFiles@@ </head> <body> <h1 id="qunit-header">Unit Tests</h1> <h2 id="qunit-banner"></h2> <h2 id="qunit-userAgent"></h2> <ol id="qunit-tests"></ol> <div id="qunit-fixture"></div> @@TestFrameworkDependencies@@ @@ReferencedJSFiles@@ @@TestJSFile@@ </body> </html>
Save your changes and that’s it! You can now delete the tests.html file from the project if you’d like and use Chutzpah to run tests both within the Visual Studio IDE and within the browser.