Created
September 3, 2020 10:02
-
-
Save latipun7/c0d1bdc5ed10911a57b7879c9460a24b to your computer and use it in GitHub Desktop.
Jest Config to Resolve Typescript Paths Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/no-var-requires */ | |
const { readFileSync } = require('fs'); | |
const { resolve } = require('path'); | |
const stripJSON = require('strip-json-comments'); | |
const { pathsToModuleNameMapper } = require('ts-jest/utils'); | |
function readAndStripJSON(...path) { | |
const rawJSONString = readFileSync(resolve(process.cwd(), ...path), { | |
encoding: 'utf8', | |
}); | |
const strippedComments = stripJSON(rawJSONString); | |
return JSON.parse(strippedComments); | |
} | |
/** | |
* @type {import('./tsconfig.json')} | |
*/ | |
const { compilerOptions } = readAndStripJSON('tsconfig.json'); | |
module.exports = { | |
bail: true, | |
preset: 'ts-jest', | |
testEnvironment: 'node', | |
moduleDirectories: ['node_modules', '<rootDir>'], | |
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { | |
prefix: '<rootDir>/', | |
}), | |
testPathIgnorePatterns: [ | |
'<rootDir>/node_modules', | |
'<rootDir>/config', | |
'<rootDir>/dist', | |
], | |
globals: { | |
'ts-jest': { | |
diagnostics: false, | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment