-
-
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
Add support for webpack.config.js resolve.alias (symlinks) #237
Conversation
Add note about webpack.config.js resolve.alias Check for webpack alias before trying to resolve with it Add specs for webpack config alias support
Thanks for sending this! A thought: I know others have wanted the ability to intervene with the module name -> module path lookup process as well; Would it be possible to generalize the module-alias-lookup code into a configurable plugin (rather than building webpack-specific support directly into the module loader)? We've done this in Jest in a few other places and its worked out pretty well. For example: https://github.com/facebook/jest/blob/master/src/TestRunner.js#L139 Specifically if we could move the existing logic in Although we should probably keep the current lookup algorithm as the default, I'd be happy to take the webpack plugin you've essentially written here and include it so it ships with Jest such that webpack alias support is only a minor config-entry away. |
Your idea is sound, that should be the end goal here. For now, I do think that many would be happy to have even basic webpack support. |
Ya ya ya ya ya... news? 👍 💯 |
does this help with #134 ? |
@kellyrmilligan It works fine on my end, I use webpack aliases, tests run perfectly without any additional configuration |
Is that recent? I'm having issues as mentioned in 134, I have a non-common js module from a third party lib that I'm aliasing into a component and I get a require error saying it can't reuire it in. |
I haven't tested non-common js modules. Feel free to try that out @kellyrmilligan. All the code does is allow Jest to replace |
@matrinox curious why the setting of hasWebpackAliases is done within the catch? I have used this to allow for use of aliases with Jest (thank you for this btw), but the catch is never hit. hasWebpackAliases is always undefined. |
var aliases = Object.keys(aliasesMap); | ||
for (var i = 0; i < aliases.length; i++) { | ||
var alias = aliases[i]; | ||
if (moduleName.indexOf(alias + '/') === 0) { |
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.
What if the require of the alias does not have a / at the end?
// in the webpack.config.js (resolve.alias)
'some-alias-module': '/absolute/path/to/module'
// somewhere in your code require'n the above alias'd module
var some = require('some-alias-module');
I changed this line to:
if (moduleName.indexOf(alias + '/') === 0 || moduleName === alias) {
@codegoat It's been a while now but I think I did that because some people don't have a webpack config path and I didn't bother adding in a way to specify that you want webpack support so it had to be flexible. |
We now have documentation on how to integrate jest with webpack. For aliases, there is a See #599 for the work tracking node-haste2. There'll be more features to better integrate jest with webpack in the near future. |
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. |
No description provided.