title: Run Typescript QUnit tests for Typescript source files with Chutzpah
body: <p>I'm trying to author a Typescript file with unit tests for a Typescript source file. My project structure:</p>
  
  <pre class="lang-none prettyprint-override"><code>/js/my-unit.ts
  /js-tests/my-unit.tests.ts
  /Scripts/typings/qunit/qunit.d.ts
  /chutzpah.json
  </code></pre>
  
  <p>Here's the <code>my-unit.ts</code> contents:</p>
  
  <pre><code>function globalFunc() { return { dummy: "object" }; }
  </code></pre>
  
  <p>Here's the <code>my-unit.tests.ts</code> contents:</p>
  
  <pre><code>/// &lt;reference path="../scripts/typings/qunit/qunit.d.ts" /&gt;
  /// &lt;reference path="../js/my-unit.ts" /&gt;
  QUnit.test("Test 1", assert =&gt; assert.ok(!!globalFunc()));
  </code></pre>
  
  <p>Here's the <code>chutzpah.json</code> file:</p>
  
  <pre><code>{
      "Compile": {
          "Mode": "External",
          "Extensions": [ ".ts" ],
          "ExtensionsWithNoOutput": [ ".d.ts" ]
      },
      "Tests": [
          { "Includes": [ "**/*-tests/**.ts" ] }
      ]
  }
  </code></pre>
  
  <p>The test is red, because:</p>
  
  <blockquote>
    <p>Can't find variable: globalFunc</p>
  </blockquote>
  
  <p>Why!? <strong>How do I fix that?</strong> </p>
  
  <hr>
  
  <p>What have I tried:</p>
  
  <ul>
  <li>referencing the <code>.js</code> file in my tests file, but that isn't allowed</li>
  <li>searching for dupes, finding mainly <a href="https://stackoverflow.com/q/19986705/419956">this question</a>, but one answer didn't work, and the other (by Chutzpah's author, no less) seems to be similar to my own setup</li>
  <li>re-reading <a href="https://github.com/mmanela/chutzpah/wiki/Running-Unit-Tests-written-in-TypeScript" rel="nofollow noreferrer">the "Running Unit Tests with Typescript" documenation</a></li>
  <li>changing the <code>reference</code> to the source to a path (with and without slash ending), but that gives me errors in Visual Studio</li>
  <li>adding <code>class Foo {}</code> in the unit file and <code>assert.ok(!!new Foo())</code> test, but this also fails</li>
  <li>adding <code>module My { export class Foo { } }</code> in the unit file and <code>assert.ok(!!new My.Foo())</code> test, but this also fails</li>
  <li><p>using the "Open in browser" feature from the other Chutzpah extension, and check the source for the test file (which presumably is also generated for tests when run from the test explorer), where I see that indeed my source file (<code>my-unit.ts</code> or <code>my-unit.js</code>) is <em>not</em> referenced:</p>
  
    <pre class="lang-html prettyprint-override"><code>  &lt;!DOCTYPE html&gt;
    &lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;QUnit Tests&lt;/title&gt;
        &lt;link rel="stylesheet" type="text/css" href="file:///E:/path/to/TestFiles/QUnit/qunit.css"/&gt;
        &lt;script type="text/javascript" src="file:///E:/path/to/TestFiles/QUnit/qunit.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="file:///E:/path/to/project/js-tests/my-unit.tests.js"&gt;&lt;/script&gt;
        &lt;script&gt;
            var amdTestPaths = [];
            // code ommitted for brevity...
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;    
        &lt;div id="qunit"&gt;&lt;/div&gt;
        &lt;div id="qunit-fixture"&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre></li>
  <li><p>Adding</p>
  
  <pre><code>"References": [{ "Path":  "js", "Includes": [ "**.ts" ], "Excludes": [ "**.d.ts" ] }
  </code></pre>
  
  <p>to my <code>chutzpah.json</code> file. This kind-of works, but is a rather brute-force hack, because now <em>all</em> my source files will be included for <em>each</em> test fixture...</p></li>
  </ul>
  
  <hr>
  
  <p>The above is a (hopefully) minimal repro of my actual scenario. How can I get it to work?</p>