-
-
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
support for custom module resolver #2320
Comments
I would recommend option 2; you can specify a JSON value to the |
thanks @cpojer I was hoping to create something that can go to the community (in the shape of npm package) and option 2 is mostly about solving my own problem rather than providing a stable solution that relies on public APIs. as both moduleDirectories and moduleNameMapper are very static in nature they dont provide the kind of API for a run-time package. As I mentioned, this is my first day with Jest so im woefully under-educated about how it works but from what Ive gleaned so far, making moduleNameMapper a callback (so optionally require-ing it rather than always treating it as an object) that can return multiple results could be a useful and relatively simple way to implement a solution. what do you think? |
I'd prefer not to make a breaking change to moduleNameMapper at this point and I'm with people having to maintain two separate configs. We have discussed building a |
In case people get here when looking for a solution to running JSPM and Jest together, |
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. |
Hi,
Im very new to Jest (started today) and had planned to use it with a React app im working on that is using JSPM/SystemJS for module/dependency loading and resolving.
The issue is that Im using a feature of SystemJS that allows for module aliasing, meaning if I have: src/common/utils.js i can alias it as "utils" and then use it like this:
import utils from "utils";
Obviously the Jest resolving mechanism isnt aware of this and immediately stops with module not found error when it reaches this import.
I'd hoped there would be a way (API) for me to easily provide the mapping by reading the SystemJS config file at run time and pass the resolved path to the internal resolving/loading mechanism to do its job.
However, after a short dive into the way the Jest run-time works, how the Haste resolving works it seems like there is no way to do this.
Trying the custom moduleLoader feature (which as far as i can see is completely undocumented 😢 ) also looks like a no-go as the resolving happens outside of it and there is no way to interject in the way the resolver is created or used.
Other less sophisticated ways also seem impossible as the Jest config file is read from FS as a string so i cannot make it into a module with some basic logic.
The moduleNameMapper config parameter is read only as an array so again, cannot be made more dynamic.
I've followed the long correspondence at #599 which at some point discussed allowing something like Im looking for but at the current version (17.0.3) this doesnt seem to be enabled.
Am I missing something?
For now I see only two ways to go about this which I dont like very much:
simply copy the aliases from my SystemJS config to the moduleNameMapper config parameter - dont like this at all as it means maintaining them in two places
write a build step to generate the Jest config with the moduleNameMapper parameter based on the SystemJS config - seems like the best solution for now but feels less than ideal...
Thanks.
The text was updated successfully, but these errors were encountered: