-
-
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
Allow for imports when path includes a query string. Fixes #4181 #4549
Allow for imports when path includes a query string. Fixes #4181 #4549
Conversation
What happens when I want to do: With this change to Jest, what is the behavior and how does it diverge or match those bundlers? |
10f255c
to
c4726a7
Compare
Codecov Report
@@ Coverage Diff @@
## master #4549 +/- ##
==========================================
+ Coverage 56.04% 56.82% +0.78%
==========================================
Files 185 186 +1
Lines 6268 6305 +37
Branches 3 3
==========================================
+ Hits 3513 3583 +70
+ Misses 2754 2721 -33
Partials 1 1
Continue to review full report at Codecov.
|
@cpojer At a high-level, my primary goal was to circumvent the error thrown by Jest's resolver for module paths that included query string. For my specific use-case, I do not necessarily care about the resulting imported module. I am mocking the image file entirely. However, I do believe you raise good questions. Unfortunately, I'm not confident on the best answers to them nor the approach to resolving them. If you have a desired outcome for your scenarios or recommendations on implementing the changes, it'd be appreciated if you provide some guidance. I am happy to explore executing your recommendations. Thank you in advance. I greatly appreciate your time and the investments your team has made in Jest. Our team loves Jest! |
I'm going to close this PR because of the unanswered questions but I am not opposed to merging this if somebody takes the time to fully think this through. For now, I recommend using |
@cpojer, do you know if anybody is working on this? I'm ready to start 💪 I've got a nice use case for queries described in #4181 (comment) and also some compatibility analysis in #4181 (comment). Thanks! |
Is this something we can otherwise solve with a custom resolver so that we don't have to ship this within Jest by default? |
This was my first try too. As far as I understand Jest's internals, the resolver is used for only mapping from a module name to a module filesystem path. And this mapping is 1:1 and also cached. The file content loaded from the mapped path is also cached in two layers of caching. All this happens outside of the resolver's code. |
Maybe we can make some adjustments to enable use of a custom resolver for this. |
This would be the right modular way to go. Shell I try creating a proof of concept PR then? |
Go for it! |
Here it comes with more text than code 😂 |
@cpojer btw, if the resource queries topic is not so well fitting into Jest, maybe there is another way to hook into and get dynamic mocking possible? I'm super excited with what's new in Jest 23 and I'd be happy to see even more test automation (like we've done in Introscope) built into Jest 24 ;) |
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. |
Fixes #4181
Summary
Jest fails to apply a transform to a file if the import path includes query parameters. A detailed description can be found here.
Test plan
Added tests to ensure this is functioning properly.