title: How to setup an npm test via mocha?
body: <p>I use <strong>Angular</strong> + <strong>TypeScript</strong> + <strong>Electron</strong> and I try to add tests to my application. I installed <code>mocha</code> and added the following line to <code>package.json</code>:</p>
  <pre><code>&quot;test&quot;: &quot;mocha './**/*.spec.ts'&quot;,
  </code></pre>
  <p>I have a <code>app.component.spec.ts</code> file in my source directory but executing <code>npm run test</code> fails with the following exception:</p>
  <pre><code>&gt; mocha './**/*.spec.ts'
  src\app\app.component.spec.ts:1
  import { TestBed, waitForAsync } from '@angular/core/testing';
  ^^^^^^
  
  SyntaxError: Cannot use import statement outside a module
      at wrapSafe (internal/modules/cjs/loader.js:931:16)
      at Module._compile (internal/modules/cjs/loader.js:979:27)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
      at Module.load (internal/modules/cjs/loader.js:879:32)
  </code></pre>
  <p>Can anyone explain me the context, and how I could fix this issue?</p>
  <p>P.S. In similar posts the <code>module</code> in <code>tsconfig.json</code> needed to be set to <code>commonjs</code> which I did, but that didn't solve the issue:</p>
  <pre><code>{
    &quot;compileOnSave&quot;: false,
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      ...
  }
  </code></pre>