-
-
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
Enable manual mocks with nested folders #2483
Enable manual mocks with nested folders #2483
Conversation
49bdeca
to
45dfbab
Compare
45dfbab
to
38994cf
Compare
Current coverage is 87.74% (diff: 85.71%)@@ master #2483 diff @@
==========================================
Files 40 40
Lines 1653 1657 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1447 1454 +7
+ Misses 206 203 -3
Partials 0 0
|
38994cf
to
cca8cc8
Compare
This looks good. Thanks @MicheleBertoli. Instead of exporting it on |
6129227
to
1322f56
Compare
Generated by 🚫 dangerJS |
Alright, would you mind adding the copyright header to all files and @flow to all non-test files? Ignore the ones in |
|
||
const extractMockName = new RegExp( | ||
`^\\${path.sep}?(.*?)(\\${path.sep}index)?\\${path.extname(modulePath)}$` | ||
); |
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'm really worried about performance here. Right now, mocksPattern is a config option but it isn't really configurable and I'm ok making it non-configurable just like the snapshots folder because it causes trouble.
Can you change this either by:
- Optimize this code for performance. Think running this on 50k files, it should be less than 100ms or at least not slower than what we do here currently.
- Change the mocksPattern option to be hard-coded, so splitting at
__mocks__
and looking at the right-hand side of this should work and be fast.
Thank you very much for your feedback, @cpojer. |
This is great. We'll deprecate mocksPattern with Jest 19. #2600 |
* Enable manual mocks with nested folders * extract getMockName into a separate module * avoid using regex * add file headers
* Enable manual mocks with nested folders * extract getMockName into a separate module * avoid using regex * add file headers
Cool! Glad to see this is supported. 👍 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Following #2475 this PR enables manual mocks with nested folders.
You can now mock dependencies with nested folders like:
jest.mock('react-styleguidist/src/rsg-components/Playground/PlaygroundRenderer')
Where the manual mock directory structure is the following:
This PR exists mostly to get an early feedback from the team and it could be improved.
For example, I attached the
getMockName
function to theHasteMap
class to make testing easier but we can find a better solution (transforming it to an instance method?).Test plan
I tried it on a project where I actually need it, and it worked.
Before (Jest loads the actual package):
After (It works):