Configure Jest to import local modules from src instead of dist

The Jest `moduleNameMapper` option allows us to match module names and transform the path that will be used to import them. If the resulting module is written in TypeScript, it will then be compiled by `ts-jest`, similar to relative imports within the package under test.
This commit is contained in:
Martijn Walraven 2018-10-11 20:23:16 +02:00
parent 68f4e83fb2
commit 6c2f8d7583

View file

@ -16,7 +16,10 @@ module.exports = {
"/dist/"
],
moduleFileExtensions: [...defaults.moduleFileExtensions, "ts", "tsx"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/../../' }),
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/../../' }),
'^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:server|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '<rootDir>/../../packages/$1/src$2',
},
clearMocks: true,
globals: {
"ts-jest": {