title: How would I test Typescript code that uses namespaces in Node.js?
body: <p>I'm writing some Typescript code within a framework that uses namespaces extensively.</p>
  
  <p>I'd like to add some unit tests, that involves using a test runner like <code>mocha</code>, which I'd include as a module.  Because all the existing files are written with namespaces, I can't import them into my test as modules.</p>
  
  <p>I can use <code>/// &lt;reference path=.../&gt;</code>, but the referenced classes aren't actually defined in the compiled js file.</p>
  
  <p>I tried using <code>--outFile</code>, which forces me to use systemjs as the module loader.  I tried doing this, but when I run:</p>
  
  <pre><code>mocha --compilers ts:ts-node/register api-test.ts
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>ReferenceError: System is not defined
  </code></pre>
  
  <p>When I manually run <code>tsc</code> to compile the test code, I do see the call to <code>System.register</code> but System isn't actually imported/required in the file.</p>
  
  <p>The closest example I've found is this repo: <a href="https://github.com/curran/jspm-mocha-example" rel="nofollow noreferrer">https://github.com/curran/jspm-mocha-example</a></p>
  
  <p>It's using Babel instead of Typescript, but it seems to be able to succesfully use systemjs with mocha, and I don't see explicit code that loads the System library.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>From @martin I tried adding the <code>-r systemjs</code> option to mocha.  This added <code>System</code> and solved the reference error.  However, the next problem is that the code generated by the Typescript compiler <code>tsc</code> ends up wrapping the test code within the module loading code.  Mocha seems unable to find the tests now.</p>
  
  <pre><code>System.register("tests/foo-test", ["config.js", "assert"], function (exports_1, context_1) {
      "use strict";
      var __moduleName = context_1 &amp;&amp; context_1.id;
      var assert;
      return {
          setters: [
              function (_1) {
              },
              function (assert_1) {
                  assert = assert_1;
              }
          ],
          execute: function () {
              describe('testCase', function () {
                  it('type test', function () {
                      assert(false);
                  });
              });
          }
      };
  });
  </code></pre>