In moduleNameWrapper if I try to use "constants" as an alias I receive an error when I try to run my tests
Steps to reproduce the behavior:
module.exports = {
transform: {
"^.+\\.jsx?$": '<rootDir>/jest-preprocess.js',
},
moduleNameMapper: {
".+\\.(css|styl|less|sass|scss)$": 'identity-obj-proxy',
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"^constants(.*)$": "<rootDir>/src/shared/constants$1",
},
testPathIgnorePatterns: ['node_modules', '\\.cache', '<rootDir>.*/public'],
transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'],
globals: {
__PATH_PREFIX__: '',
},
testURL: 'http://localhost',
setupFiles: ['<rootDir>/loadershim.js'],
};
src/shared/constantsyarn run v1.17.3
$ jest
FAIL src/components/Plans/useBehavior.test.js
โ Test suite failed to run
Configuration error:
Could not locate module constants mapped as:
/Users/cliente/Development/w.dental-pj/src/shared/constants$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^constants(.*)$/": "/Users/cliente/Development/w.dental-pj/src/shared/constants$1"
},
"resolver": undefined
}
at createNoMappedModuleFoundError (node_modules/jest-resolve/build/index.js:553:17)
at Object.<anonymous> (node_modules/graceful-fs/polyfills.js:1:17)
When I use "^constants/(.*)$": "<rootDir>/src/shared/constants/$1", instead its fine. I don't know why ๐
System:
OS: macOS 10.15.4
CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
Binaries:
Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
Yarn: 1.17.3 - ~/.yarn/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
npmPackages:
jest: ^26.0.1 => 26.0.1
Possibly related https://github.com/facebook/jest/issues/8610
sure ๐ but in the tests we just have a check with this pattern /^constants$/ and none for something like /^constants(.*)$/ ๐ค
i've changed the current test to this pattern and it has been passed ๐ค ๐
Folders with the name "core" might also cause a similar error. @mathvaleriano's workaround fixed it.
Could not locate module core-js-pure/stable/object/define-property mapped as:
C:\Code\my-project\src\core\$1.
^core(.*)$ -> /^core(.*)$/
I did something like this at the same day, but thank you for this example
We're now getting the same error with "^constants(.*)$": "<rootDir>/constants$1" as of this PR: https://github.com/amido/stacks-webapp-template/pull/445
It seems to have been introduced between 25.4.0 which we're on and 26.2.2, which is what the PR is upgrading to.
EDIT: @mathvaleriano's workaround works for us, but hopefully the information above helps with getting an actual fix for this.
Most helpful comment
We're now getting the same error with
"^constants(.*)$": "<rootDir>/constants$1"as of this PR: https://github.com/amido/stacks-webapp-template/pull/445It seems to have been introduced between
25.4.0which we're on and26.2.2, which is what the PR is upgrading to.EDIT: @mathvaleriano's workaround works for us, but hopefully the information above helps with getting an actual fix for this.