lundi 28 décembre 2020

How to find aliases in Global Jest setup?

I want to run some stuff only once before all test cases. Therefore, I have created a global function and specified the globalSetup field in the jest configuration:

globalSetup: path.resolve(srcPath, 'TestUtils', 'globalSetup.ts'),

However, within globalSetup, I use some aliases @ and Jest complains it does not find them.

How can I run globalSetup once the aliases have been sorted out?

My Jest configuration is as follows:

module.exports = {
  rootDir: rootPath,
  coveragePathIgnorePatterns: ['/node_modules/'],
  preset: 'ts-jest',
  setupFiles: [path.resolve(__dirname, 'env.testing.ts')],
  setupFilesAfterEnv: [path.resolve(srcPath, 'TestUtils', 'testSetup.ts')],
  globalSetup: path.resolve(srcPath, 'TestUtils', 'globalSetup.ts'),
  globals: {},
  testEnvironment: 'node',
  moduleFileExtensions: ['js', 'ts', 'json'],
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' })
};

When I run testSetup before every test, it runs ok the aliases, but this does not happen with globalSetup.

Any clue what could I do?

Aucun commentaire:

Enregistrer un commentaire