Issue :
I'm having trouble configuring jest to resolve modules when using multiple paths in my tsconfig. It seems ts-jest will only resolve a single path- is this the case?
Expected behavior :
I would expect to find some solution to resolve paths when my tsconfig.json paths array has more than one path listed. After all, it is an array ¯_(ツ)_/¯
File structure is as follows
.
├── tsconfig.json
├── jest.config.js
├── src-common
| └── components
| └── Button.tsx
├── src-admin
| └── components
| └── Login.tsx
└── src-main
└── components
└── Share.tsx
relevant parts of tsconfig.json
{
"baseUrl": ".",
"paths": {
"@components/*": ["src-common/components/ui/*", "src-admin/components/ui/*", "src-main/components/*],
}
}
jest.config.js
module.exports = {
setupFilesAfterEnv: ["react-testing-library/cleanup-after-each"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
// Resolves a single path as expected 👍
"^@components/(.*)$": "<rootDir>/src-common/components/$1",
// No regex in path 😢
"^@components/(.*)$": "<rootDir>/src-{common,admin,main}/components/$1",
// No array in path 😢
"^@components/(.*)$": [
"<rootDir>/src-common/components/$1"
"<rootDir>/src-admin/components/$1"
"<rootDir>/src-main/components/$1"
],
},
};
Debug log:
log file content
# content of ts-jest.log :
# Project is more complex than this example, and the output doesn't exactly match ☝️
Minimal repo :
Unfortunately Codesandbox doesn't support tsconfig.json paths :(
Issue :
I'm having trouble configuring jest to resolve modules when using multiple
pathsin my tsconfig. It seemsts-jestwill only resolve a single path- is this the case?Expected behavior :
I would expect to find some solution to resolve paths when my
tsconfig.jsonpaths array has more than one path listed. After all, it is an array ¯_(ツ)_/¯File structure is as follows
relevant parts of
tsconfig.json{ "baseUrl": ".", "paths": { "@components/*": ["src-common/components/ui/*", "src-admin/components/ui/*", "src-main/components/*], } }jest.config.jsDebug log:
log file content
Minimal repo :
Unfortunately Codesandbox doesn't support
tsconfig.jsonpaths :(