Chutzpah – A JavaScript Test Runner Released

I just released to CodePlex and the Visual Studio Gallery a new project called Chutzpah (hutz·pah). Chutzpah is an open source JavaScript unit test runner which helps you integrate JavaScript unit testing into your website. It enables you to run JavaScript unit tests from the command line and from inside of Visual Studio. It also supports running in the TeamCity continuous integration server.

Backstory

About nine months ago I asked a question on StackOverflow about whether there were any tools/extensions which integrated into Visual Studio to run JavaScript unit tests. At that time there were no good solutions provided which led me to investigate creating my own tool. I explored many options but eventually I found the PhantomJS headless browser to help drive the tests.  After a couple weeks of development Chutzpah was born.

What does Chutzpah do?

Chutzpah is both a Visual Studio extension and a command line utility.

As a Visual Studio extension:

It allows you to run your JavaScript tests without leaving the IDE. It adds a context menu option to run tests directly from a source file.

RightMenu

It logs test results to both the Error list and the Output window.

errorWindow

outputWindow

As a command line utility:

It allows you to easily integrate test results into your build

commandLine

It also has support for the TeamCity continuous integration server so that you get detailed test output on every build.

How to use it?

Chutzpah is really easy to use, given QUnit tests (it only supports QUnit for now) you can run Chutzpah on the test harness HTML file and it will output the results. Chutzpah also supports running the tests directly from the JavaScript file as long as you add reference comments to the top of your test file.

For example given two files test.js (QUnit tests file) and code.js (implementation file).

code.js

var mathLib = {
    add5: function (a) {
        return a + 5;
    }
}

test.js

/// <reference path="code.js" />

test("will add 5 to number", function () {
    var res = mathLib.add5(10)

    equals(res, 15, "should add 5");
});

You can run the tests by right clicking and choosing “Run JS Test” if you are using the Visual Studio plugin, otherwise you can execute Chutzpah from the command line:

.\chutzpah.console.exe test.js

Community Support

I am really excited about releasing Chutzpah as an open source project with the hope of garnering support from the community. I would love to get feedback, bug reports, feature requests and code contributions. If you are interested in working on Chutzpah fork the code and get hacking.

Future Plans Ideas

At this stage I have many ideas of what features should come next for Chutzpah but outside of bug fixes I have no solid plans yet. Here are several ideas floating around in my head…

  1. Support other JavaScript unit test frameworks besides QUnit
  2. Expand past only using PhantomJS as the headless browser, possibly working with things like JsTestDriver or EnvJS.
  3. Be able to run individual tests instead of just a whole file.
  4. Add better IDE support like the Resharper 6 QUnit functionality.
  5. Add scanning for test files within a whole project hierarchy
  6. Support proxy servers
  7. Capture more detailed information from each test
  8. Integrate with existing test runners like MSTest or TestDriven.NET
  9. Add NuGet support
  • Pingback: DotNetShoutout

  • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #877

  • http://dan.cx/ Daniel15

    Pretty cool project. Nice work! :D

    • https://www.google.com/accounts/o8/id?id=AItOawlrLeowWytSCscAcNv3ky4tdtP7AcgDAC8 Matthew

      Thanks a lot.

  • Ryan Pays

    Any info on how to get this up and running with Team City?

    • https://www.google.com/accounts/o8/id?id=AItOawlrLeowWytSCscAcNv3ky4tdtP7AcgDAC8 Matthew

      Sure. It is actually really simple. When you execute chutzpah.console.exe it will automatically detect if it is running in TeamCity and output special markup that will let TeamCity parse the results.

      This means all you need to do is run chutzpah.console.exe and point it at your test files. Like:
      chutzpah.console.exe /path someTest.js

  • James

    Can I add a reference to a folder rather than one file? I’m trying to test a javascript framework that dynamically injects Javascript with relative links

    • https://www.google.com/accounts/o8/id?id=AItOawlrLeowWytSCscAcNv3ky4tdtP7AcgDAC8 Matthew

      If you could describe your situation in more detail it can help me understand better but I think Chutzpah will have issue with this scenario. I have plans to try to make this type of dynamic loading work better but currently Chutzpah works by traversing the graph of all dependencies your test file has, flattens the tree and copies to a temp directory. This flattening can make some dynamic loading tricky.

      Once I have some time I am going to look at a better way to do this. I would appreciate if you could give me a sample zip which shows the scenario that is not working. That way I can integrate it as a integration test.

      Thanks

  • http://orchid1software.com Edgar Martinez

    So chutzpah works only in the command line it is a headless testdriver? In other words the tests don’t run a browser? correct? Just curious because I just joined a new team at the company I work for and they are using chutzpah and I want to understand it a bit better in the past I have used JSTestDriver and I am trying to see what the benefits are with chutzpah other than the integration with Visual Studio.
    Looks like a great plugin for VS I’d like to know more about it.
    Thanks for your response.