Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix(jest-resolve-dependencies): resolve mocks as dependencies #8952
fix(jest-resolve-dependencies): resolve mocks as dependencies #8952
Changes from all commits
6da2875
5cce42e
014d4de
4cebe1b
d7e327c
39cb1ad
651b27c
8137d38
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why it's not
file, dependency
like above? Would be nice if we could justtry
to resolve, ignoring failure, and then look for a mock in a single call regardless of whether the resolution failed, to simplify the logic hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMockModule(file, dependency)
actually does not work as expected.Taking another look at it though, what does work with the tests that I added is this:
Which is definitely better than what I had before.
Unfortunately, this will fail for the case where the dependency is in a different directory from the dependent, and there's still the existing issue of mocks of the same name from different directories.
If this isn't good enough, I'm thinking we'll have to introduce a new method into
jest-resolve
which mirrors the functionality resolveModule, or expand the functionality ofresolveModule
, or change what information is collected about mocks to handle these cases. This would also serve to avoid some of the hackyness of the rest of my solution.I do feel as though I'm slightly out of my depth here since it seems like some fairly important changes need to happen to pick up those cases, so if anyone has any guidance that would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, sorry. I would expect that
getMockModule
does no more than look for a__mocks__/file.js
next to thefile.js
. Why does it matter where the dependent is, it's not being passed togetMockModule
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably also
resolve
this like the one it's being compared with, in case of symlinks or something