-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Jest does not respect NODE_PATH #102
Comments
I'm also having an issue with this using webpack and defining paths with the "modulesDirectories" parameter (http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories). I'd like to see a similar option to be able to declare (multiple) module directories. |
I updated our project to use a more standard node module setup. As soon as I added a package.json to my packages and started using relative paths within each module, my issue was resolved. So if you have to use a require with ../../../../.., that code should really be split out into another package. |
Thanks for the issue! Re-opening because the original topic still applies: Jest should probably respect the I'm personally strapped on resources at the moment myself, but I'd love to see support for this happen. Hopefully when I can get some time I can dive in to this -- otherwise would be happy to consider a pull request. |
Hit into this issue today - would love to see this addressed soon |
Can't use Jest because of this issue. |
Really need this in order to be able to be a little flexible when it comes to how you organize your projects. NODE_PATH is one thing, but we also have split out common components in another project, referencing this does not resolve either. This should be easy to do right, and add great flexibility. Please prioritize this. |
+1 Here's a function you can call in your jest preprocessor to rewrite the require statements to use absolute paths to work around this issue.
|
There are at least 4 issues that pertain to this problem, and there is a PR that fixes this in #133 that was submitted months ago. Why is it taking so long to test and merge it into the master branch? |
I assume this applies to Example: This is kinda nasty. Since Facebook has been using this for years now - how do you get around relative paths? Or are you using relative paths? If so, why? It doesn't seem that difficult to add into the HasteLoader |
👍 just ran into this issue |
+1 to be consistent with what node does. |
👍 |
2 similar comments
👍 |
👍 |
Hi guys, Any update for this issue? Thanks. |
This is pretty bad. I can't even use aliases in my application if I'm using JEST because the tests will fail - JEST can't resolve the alias. I don't know how you guys can live with this. This issue has been open for ages and there are already several PRs active that aim to solve it. |
I think nobody's home :) |
The person who made the PR that fixes this issue hasn't responded to @jeffmo's feedback. So it's not that nobody is home, but developing open source software with community participation is kind of tricky. If @jeffmo fixes this issue and ignore the pull request, he might catch flak for it, and I think that's why he hasn't taken on this issue. I think for mission critical stuff like this, you hope the maintainer will take the lead to fix the issue himself. There are too many people waiting for this issue to get fixed. Let's hope someone is listening. :) |
@volkanunsal it is true I dropped the ball on this - A few days ago @carrbs opened a new pull though #246 |
Thanks @hojberg, Yes, #246 covers all this, has testing and is not platform specific. Please
|
Can I push the line and ask whether aliases will work? (#246) |
@gbbr - yes, if you mean in package.json, if you do something like: So long as |
Oops... that's a webpack feature. My bad. It's a config option called On 16 February 2015 at 22:24, Benjamin Sanabria Carr <
|
Hey everyone, very sorry. I've been missing out on all the latest updates to this thread but this basically just slipped my radar. I will go commandeer that initial pull request and bring it up to date tomorrow when I get back to the office. Sorry for dropping the ball here everyone, my bad. |
Awesome! thnaks @jeffmo |
woot! thanks @jeffmo |
I cannot use the preprocessor to rewrite the require statements because it seems that an error of a failed required module is thrown before calling the preprocessor. |
Found myself getting resolve.sync('react', {
paths: 'resources',
basedir: 'resources/components/button',
exts: [ '.js', '.json', '.jsx' ]
}); Where
My temporary solution for this was to use |
There is another issue I noticed, after Make sure the paths are consistent everywhere, otherwise dontMock/setMock won't work. e.g.: maybe there is no such feature yet to recognize the same path references? |
I'm running into this bug on my CI server, anyone have a workaround? |
Jest definitely respects the NODE_PATH and has for a year at least. You are probably running into some other issue. |
Sorry, somehow I thought this issue was still open. |
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. |
In our project we do not use any relative paths in require statements. Instead of require('../../../ui/button') from inside a module in the components package, we simply use require('components/ui/button') everywhere. This way if we move the button code around, we can do a simple search and replace in the project to update all of the require statements. To accomplish this we set NODE_PATH="." and we are done (export NODE_PATH="." at the command line or process.env.NODE_PATH='.' in the code). Browserify, Webstorm and node all respect the process.env.NODE_PATH setting. It would be great if Jest's HasteModuleLoader could be updated to check the NODE_PATH for user modules as well. It looks like it is checking to see if it is a IS_PATH_BASED_MODULE_NAME, but it's not so it errors out. It would be nice if it would also check each of the paths in NODE_PATH before giving up.
The text was updated successfully, but these errors were encountered: