Search code examples
typescriptchutzpah

Can't get TypeScript reference to work with Chutzpah


I have the following files in my project folder:

  • chai.d.ts
  • chai.js
  • mocha.d.ts
  • mocha.js
  • appTest.ts
  • appTest.js
  • chutzpah.json

The chai and mocha files have been downloaded using bower and tsd

Here is what is in the other files:

appTest.ts:

/// <chutzpah_reference path="mocha.js" />
/// <chutzpah_reference path="chai.js" />
/// <reference path="mocha.d.ts" />
/// <reference path="chai.d.ts" />
var assert = chai.assert;

test("test test", function () {
    assert.equal(1, 3, "One equals three");
});

appTest.js: (compiled by external process)

var assert = chai.assert;
test("test test", function () {
    assert.equal(1, 3, "One equals three");
});

chutzpah.json:

{
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ]
  },
  "Tests": [
    {
      "Includes": [ "*Test.ts" ]
    }
  ]
}

I run this command in the folder:

chutzpah.console appTest.ts

And I get the following error:

Chutzpah console test runner  (64-bit .NET 4.0.30319.42000)
Version 4.1.0.0
Copyright (C) 2015 Matthew Manela (http://matthewmanela.com).


Error: ReferenceError: Can't find variable: chai
at global code in file:///C:/***/appTest.js (line 1)

While Running:C:\***\appTest.ts

File: C:\***\appTest.ts
     0 total, 0 failed, took 0.00 seconds

Tests complete: 0
=== 0 total, 0 failed, took 1.65 seconds ===

What am I missing?


Solution

  • I think you are hitting a breaking change that was introduced in version 4.1 with regards to how Chutzpah parses file references when using the Cutzpah.json file. As a performance imrpovement Chutzpah makes scanning references inside of your test files an optional feature and prefers you listing them explicitly in the Chutzpah.json file.

    See this page for more info.

    But basically, either you need to reference the files you need in the chutzpah.json file:

     "References": [
        {
          "Path": "chai.js"
        }
      ]
    

    or mark your test file to allow scanning references:

      "Tests": [
            { "Includes": [ "*Test.ts" ], "ExpandReferenceComments":  "true" }
        ]