Jeroen Jeroen - 10 months ago 64
TypeScript Question

Running QUnit (TypeScript) tests with Chutzpah gives "Called start() outside of a test context while already started"

I've got a fairly simple repro with an outcome I don't understand.

Make sure you have the Chutpah Test Adapter 4.0.3 installed. Using Visual Studio 2013 take the following steps:

  1. Create a new .NET 4.5.1 class library project;

  2. Add the NuGet package

  3. Add a TypeScript file
    to the project with this content:

    /// <reference path="./Scripts/typings/qunit/qunit.d.ts"/>
    QUnit.test("QUnit is working", assert => assert.ok(true));

  4. Right-click inside that file and pick "Run JS Tests" from the context menu.

I can confirm that
is generated as expected.

The result is that no tests are run, the test explorer shows no tests, and the Test output shows:

Error: Error: Called start() outside of a test context while already started
at start in file:///C:/Users/username/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/abcxyz/TestFiles/QUnit/qunit.js (line 287)
at startQUnit in phantomjs://webpage.evaluate() (line 12)
at onPageLoaded in phantomjs://webpage.evaluate() (line 16)
in phantomjs://webpage.evaluate() (line 18)
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
------ Test started: File: c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts ------
Error: Error: Called start() outside of a test context while already started
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
0 passed, 0 failed, 0 total (chutzpah).

========== Total Tests: 0 passed, 0 failed, 0 total ==========

If I choose the "Open In Browser" Chutzpah context menu item I get a regular QUnit test page, nicely formatted, showing zero tests run.

Obviously the expected result was that one test was successfully run.

What am I missing here?

Answer Source

D'oh! The Chutzpah + TypeScript documentation is actually pretty clear about this:

You need to tell Chutzpah how to compile your files into JavaScript using the compile setting in the chutzpah.json file.

For the scenario from the question take e.g. these steps to get it to work:

  1. Add a chutzpah.json file to the root of your project.
  2. Enter the following code:

        "Compile": {
            "Mode": "External",
            "Extensions": [".ts"],
            "ExtensionsWithNoOutput":  [".d.ts"]

    After this the right-click run will already improve, showing:

    ========== Total Tests: 1 passed, 0 failed, 1 total ==========

    If this doesn't work right away close and re-open the solution.

  3. To get the tests to show up in the Test Explorer you need to group them into modules, e.g. by adding this to file1.ts:


For more info, see the Compile Setting documentation.

Leaving this up here should others fall in the same trap I did.