My simplified jest.config.js is:
module.exports = {
preset: "ts-jest",
collectCoverage: true,
collectCoverageFrom: [
"src/**/*.ts",
"!**/node_modules/**",
"!src/config/*.ts",
"!build/**/*"
],
coverageReporters: ["text"],
reporters: ["default"],
moduleDirectories: [
"src",
"node_modules"
],
moduleNameMapper: {
"@helpers/(.*)": "<rootDir>/src/helpers/$1", <---- question about this
},
globals: {
'ts-jest': {
diagnostics: {
pathRegex: /\.(spec|test)\.ts$/,
ignoreCodes: [6133]
}
}
},
verbose: true,
roots: ["src"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx"]
};
The moduleNameMapper maps to any level of nested paths:
- @helpers/foo
- @helpers/foo/foo
- etc...
I'm using it in my tests like import foo from "@helpers/foo/foo";
However, I get this error:
Could not locate module
@helpers/foomapped as:/<PATH>/src/helpers/foo
Didn't find anything in the documentation about nested paths. I assumed, since @helpers/(.*) is a regex, this should work out of the box.
What am I doing wrong? Maybe it's a bug?