Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 qunit.TypeScript.DefinitelyTyped 0.1.7;
  3. Add a TypeScript file file1.ts 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 file1.js 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?

like image 356
Jeroen Avatar asked Jul 21 '15 13:07

Jeroen


1 Answers

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:

    QUnit.module("Qu.Testing");
    

For more info, see the Compile Setting documentation.

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

like image 101
Jeroen Avatar answered Oct 18 '22 19:10

Jeroen