Home / Blog / Running JS Test Driver in Team City /

JS Test Driver is a great new Javascript Testing Framework from the guys at Google. It provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this introduction to JS Test Driver by Miško Hevery for a great overview.

Getting JS Test Driver up and running on your development workstation is easy enough. But how about on a continuous integration server such as TeamCity?

It’s easy, just follow the instructions below!

Install Java and the JS Test Driver jar on all the build agents

JS Test Driver is packaged as a Java jar, and therefore all the TeamCity build agents will need a copy of Java and the JS Test Driver jar in order to run the tests.

Configure JS Test Driver

This guide assumes you already have JS Test Driver and some tests set up on your local machine. If not see this introduction to JS Test Driver by Miško Hevery.

Just make sure that the JS Test Driver config file is set to connect to the local machine, on port 9876 (on another port of your choice). E.g.

server: http://localhost:9876
 
load:
  # list of files to load here...

Configure your build process to call JS Test Driver

Now that we have JS Test Driver installed on our build machines, and configured correctly, let’s call it from our build process. At 7digital we are using MSBuild, so we can create a JSTestDriver Target as so:

<Target Name="JSTestDriver">
  <Message Text="##teamcity[progressMessage 'Running JS Test Driver']" Importance="high" />
  <Message Text="-------- Running JS Test Driver --------" Importance="high" />
 
  <PropertyGroup>
    <JSTestDriverJar>&quot;$(BuildToolsPath)\JSTestDriver\jsTestDriver.jar&quot;</JSTestDriverJar>
    <ConfigFile>&quot;$(SolutionFolder)\jsTestDriver.conf&quot;</ConfigFile>
    <IEPath>&quot;C:\Program Files\Internet Explorer\iexplore.exe&quot;</IEPath>
    <OutputDir>&quot;$(SolutionFolder)\output\JSTestDriver&quot;</OutputDir>
  </PropertyGroup>
 
  <Exec Command="java -jar $(JSTestDriverJar) --port 9876 --browser $(IEPath) --config $(ConfigFile) --tests all --testOutput $(OutputDir)" />
 
</Target>

The important points here are that you have the properties configured correctly (JSTestDriverJar, ConfigFile, etc) for your individual setup.

The Exec command will automatically create a JS Test Driver server, launch IE, and run all the tests. The test results will be output to the OutputDir in a JUnit compatible xml format. See the JS Test Driver continuous integration page for more information.

Once you have created this Target, ensure it is called by your standard bulid Target by adding it as a dependancy:

<Target Name="BuildAndUnitTest" DependsOnTargets="Compile;JSLint;JSTestDriver;NUnit" />

Have TeamCity pick up the test results

If you run your build through TeamCity now, you will see that it runs all your Javascript tests using JS Test Driver. But it doesn’t report any results. And test failures don’t stop the build.

Luckily TeamCity can import the JS Test Driver output xml, because it is JUnit compatible.

  • Select the build which is running the JS Test Driver tests
  • Click Edit Configuration Settings
  • Click on build step 3 (e.g. Runner: MSBuild)
  • Under the XML Report Processing section, choose Ant JUnit from the Import data from dropdown
  • In the Report paths text area add the relative path the the JS Test Driver output file (e.g. output\JSTestDriver\TEST-com.google.jstestdriver.1.xml)
  • Click save!

Now when you run your build again you will see your JS Test Driver tests showing up in the Tests tab, and test failures now stop the build.

Your Javascript unit tests now sit as first class citizens within TeamCity!

JSTestDriverFailedTest

5 Responses to “Running JS Test Driver in Team City”

  1. Mat Roberts Says:

    Just what I needed, thanks.

  2. Benjamin Arroyo Says:

    Hi Karl,

    Thanks for your post. It’s been very helpful to decide to use JsTestDriver instead of other javascript test runners.

    Now I have an issue which occurs sometimes when JsTestDriver is executed, it throws exceptions and no tests are loaded nor run. The MsBuild Exec task is not aware about it therefore the build doesn’t break and TeamCity shows 0 tests passed, which is not very nice :) .
    I think in that case the build should break.

    Did you manage to capture errors coming out from calling JSTestDriver?

    Regards.

  3. Karl O'Keeffe Says:

    Hi Benjamin,

    I haven’t yet looked into how the MsBuild task deals with errors. If it is failing to pick up a failed JS Test Driver run you could look into to checking the return code from running the Java task, it may indicate the failure and allow you to report it.

  4. King Conte Says:

    Good write up, I will be sure to save this in my Reddit account. Have a good day.

  5. Benjamin Arroyo Says:

    Hi Karl,

    They have fixed it in version 1.2.2

    Regards.

Leave a Reply