Skip to content

Instantly share code, notes, and snippets.

@jweyrich
Last active February 4, 2023 00:57
Show Gist options
  • Save jweyrich/ae9d5f40e478988c5e8a15391ac6b6ca to your computer and use it in GitHub Desktop.
Save jweyrich/ae9d5f40e478988c5e8a15391ac6b6ca to your computer and use it in GitHub Desktop.
Example of Jest config with support for Path Mapping
const { pathsToModuleNameMapper } = require('ts-jest/utils');
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
// which contains the path mapping (ie the `compilerOptions.paths` option):
const { compilerOptions } = require('./tsconfig');
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tst/**/*.test.ts'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
};
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"declaration": true,
"baseUrl": ".",
"outDir": "build",
"typeRoots": ["node_modules/@types"],
"resolveJsonModule": true,
"paths": {
"@src/*": ["./src/*"],
"@tst/*": ["./tst/*"]
}
},
"exclude": [
"node_modules",
"jest.config.js"
],
"include": [
"src/**/*",
"tst/*.ts",
"tst/**/*.test.ts"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment