Running JS unit tests in Visual Studio and on TeamCity

Getting set up to run JS unit tests locally (via Visual Studio with Resharper):

  1. Download and install PhantomJS http://phantomjs.org/download.html
  2. Stick the contents of the zip somewhere
  3. Configure Resharper: Options -> Tools -> Unit Testing -> JavaScript Tests Run Tests With: PhantomJS Set path to PhantomJs executable (to bin/phantomjs.exe under wherever you put PhantomJS)
  4. You can now right-click and run unit tests as you would for C# ones.

Configuration info

chutzpah.json configures running the tests on TeamCity and code coverage reporting. Any libraries (e.g. JQuery) you reference should be excluded from code coverage. All the test files in the tests project should also be excluded (the configured wildcard should be enough to do this).

TeamCity configuration

Tests are run via Chutzpah, this is configured as a nuget package for the solution and should be pulled down automatically.

Command line build step, Executable with parameters:

Command executable:
%teamcity.build.checkoutDir%\Source\packages\Chutzpah.4.0.3\tools\chutzpah.console.exe

Command parameters:
%teamcity.build.checkoutDir%\Source\Tests\UnitTests\UI\Website.JavaScript.Unit.Tests\ /teamcity /coverage

Test results show up in the normal way under the Tests tab. Code coverage report Under general settings add an artifact path for _Chutzpah.coverage.html – this will then show up under the build page as a tab called “JS Code Coverage”