Skip to content
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

HasteModuleLoader should use realpath instead of moduleName as cache key #616

Closed
b-smets opened this issue Nov 18, 2015 · 3 comments
Closed

Comments

@b-smets
Copy link

b-smets commented Nov 18, 2015

The HasteModuleLoader currently maintains a sort-of cache of which modules to mock / not mock in _configShouldMockModuleNames. The cache is indexed by module name, however when a module is included using a relative path, this path is used instead. When requiring a module, the mocking system calls Loader.prototype._shouldMock() which checks (amongst others) this cache, and based on this result a mock or the actual implementation is returned.

Problem:
We are using react-bootstrap which in turn uses uncontrollable which includes a module './utils' in its createUncontrollable.js. Let's call this externalUtils for clarity.
We also have our own utils module which is also included as './utils' in some other modules. Let's call this internalUtils for clarity.

Our tests should mock our internalUtils but not the externalUtils. Depending on the order of which both requires pass through the HasteLoader, either both of them are mocked or both return the real implementation.

A suggested solution would be to use the realPath, which is resolved later in the method as index for the cache.

@cpojer
Copy link
Member

cpojer commented Dec 2, 2015

I agree this sucks. I'll fix it with all the work in node-haste2, follow along in #599.

@cpojer
Copy link
Member

cpojer commented Mar 25, 2016

This should definitely be fixed in the next version of Jest and might already work properly in 0.9.2.

@cpojer cpojer closed this as completed Mar 25, 2016
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants