-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moduleNameMapper does not work with constants
#8610
Comments
constants
constants
I am facing this issue too. The alias 'constants' does not work with Jest. Jest: 23.6.0 |
Woah, this issue is super weird! The reason is that $ node -p "require('module').builtinModules.includes('constants')"
true In that case, we give you that instead of the mapped module: https://github.com/facebook/jest/blob/94067089dd25c77463e24e981fe979fb6cc0b2fb/packages/jest-runtime/src/index.ts#L313-L315 I'm not sure how we should deal with this. We currently match node's behavior (even if you install e.g. /cc @thymikee @jeysal thoughts? semi-related: nodejs/node#26012 |
I think that the main confusion point, at least for me, was that I can normally use |
Intuitively, I'd assume |
I suggest to add new field in the config with name is |
I don't think we need config for this, I think it should just be changed (fixed IMO). It should apply to module names like |
If the core modules are outside constants we will have many other names (os, util,...), this seems to be reasonable for this feature request! https://nodejs.org/api/index.html |
I didn't quite understand your last message, I think you understood me, but just to confirm: IMO we should resolve this issue by changing from (pseudocode) isCoreModule ? getCoreModule : (isMappedModule ? getMappedModule : getModule) to isMappedModule ? getMappedModule : (isCoreModule ? getCoreModule : getModule) |
Thanks, I will be create PR for it! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
When I'm trying to use
moduleNameMapper
to resolve import fromconstants
local folder, it does not work. It works fine, when I use singular form:constant
.I think it might happen because
constants
is sort of reserved module in node.js. However, plural form (constants
) works fine with web packaliases
, so they find a workaround somehow.To Reproduce
In one of the files import variable from
constants
module:Set up an alias with
moduleNameMapper
:Run tests
Expected behavior
The variable should be defined. Instead it is undefined
Link to repl or repo (highly encouraged)
https://github.com/maksimsemenov/jest-module-name-mapper
Run
npx envinfo --preset jest
System: OS: macOS 10.14.5 CPU: (4) x64 Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz Binaries: Node: 10.15.3 - /opt/local/bin/node Yarn: 1.15.2 - /opt/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm npmPackages: jest: ^24.8.0 => 24.8.0
The text was updated successfully, but these errors were encountered: