title: How to use at modules imports (@) in Jest's globalSetup function with TypeScript?
body: <p>Using JS hook to invoke TS setupGlobal function (which is using at modules imports, e.g <code>@app/blablabla.ts</code>), I'm getting an error <code>Cannot find module '@config/config'</code>. I've described <code>moduleNameMapper</code> and it's working in tests, but seems it is not in <code>setupGlobal</code> function. How can I fix that?</p>
  
  <p>As I wrote, the <code>moduleNameMapper</code> is described and Jest can understand those (at modules) imports in tests.</p>
  
  <p>jest.config.js</p>
  
  <pre><code>module.exports = {
    roots: ['&lt;rootDir&gt;/src'],
    transform: {
      '^.+\\.tsx?$': 'ts-jest',
    },
    testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    moduleDirectories: ['node_modules', 'src'],
    moduleNameMapper: {
      '@tests-suite/(.*)': '&lt;rootDir&gt;/src/tests/tests-suite/$1',
      '@config/(.*)': '&lt;rootDir&gt;/config/$1',
      '@tests/(.*)': '&lt;rootDir&gt;/src/tests/$1',
      '@src/(.*)': '&lt;rootDir&gt;/src/$1',
    },
    globalSetup: "&lt;rootDir&gt;/src/tests/unit/jestGlobalSetup.js"
  }
  
  </code></pre>
  
  <p>jestGlobalSetup.js</p>
  
  <pre><code>require("ts-node/register");
  module.exports = require('./setupTestEnvironment').default;
  </code></pre>
  
  <p>setupTestEnvironment.ts</p>
  
  <pre class="lang-js prettyprint-override"><code>import { dbConnectionManager } from '@src/dbConnectionManager'
  
  // tslint:disable-next-line:no-default-export
  export default async () =&gt; {
    if (process.env.NODE_ENV === 'test') {
      setupTestEnvironment()
    }
  }
  
  const setupTestEnvironment = async () =&gt; {
    await dbConnectionManager.awaitConnection()
  }
  </code></pre>
  
  <p>I'm expecting that "at module" imports would be executed in <code>setupGlobal</code> function, but it throws the error.</p>