title: Configuring Jest with Typescript
body: <p>I am pretty new to TypeScript and I was experimenting with <a href="https://jestjs.io/" rel="nofollow noreferrer">Jest</a> (unit test framework).
  I was trying to make just a little and simple test, but I got a <em>strange</em> error.</p>
  <h3>Setup</h3>
  <p>I created a file <code>position.ts</code> in folder <code>/src</code> with the following code:</p>
  <pre><code>export class Position {
    constructor(public x: number, public y: number) {}
  }
  </code></pre>
  <p>Then in folder <code>/tests</code> I put a file called <code>position.test.ts</code>:</p>
  <pre><code>import {Position} from './position';
  
  test('basic', () =&gt; {
    let p = new Position(1, 2);
    expect(p.x).toBe(1);
    expect(p.y).toBe(2);
  });
  </code></pre>
  <p>And I have created a file in the project root called <code>jest.config.ts</code> with the following content:</p>
  <pre><code>module.exports = {
    'roots': ['&lt;rootDir&gt;/src'],
    'transform': {'^.+\\.tsx?$': 'ts-jest'},
  }
  </code></pre>
  <p>My <code>tsconfig.json</code> contains:</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;es5&quot;,
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;outDir&quot;: &quot;./dist&quot;, 
      &quot;rootDir&quot;: &quot;./&quot;,
      &quot;strict&quot;: true,
      &quot;esModuleInterop&quot;: true
    }
  }
  </code></pre>
  <h3>Issue</h3>
  <p>When I run: <code>tsc</code> no errors are reported.
  When I run: <code>npx jest</code> I get the following error:</p>
  <pre><code> FAIL  tests/position.test.ts
    ● Test suite failed to run
  
      /home/killkrt/developer/Atomts/tests/position.test.ts:1
      ({&quot;Object.&lt;anonymous&gt;&quot;:function(module,exports,require,__dirname,__filename,global,jest){import { Position } from '../src/position';
                                                                                               ^^^^^^
  SyntaxError: Cannot use import statement outside a module
  </code></pre>
  <p>How can I solve it?</p>
  <p>I would like to keep my source code in <code>/src</code> folder, tests in <code>/tests</code> and <em>compiled</em> js in <code>/dist</code></p>