-
-
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
Jest tests cause require-dir to break in dependencies #4567
Comments
Thanks for the helpful issue link, I am interesting in knowing if While I personally dislike directory require utilities (in favor of |
At this point I'm ok if somebody adds support for module.parent, granted the PR includes tests. We do not support require.cache, so it would only work if you also call |
Cool, do you know roughly how involved it would be to add support? Is it a matter of hooking into module loading in the VMs and adding metadata or is it a more invasive refactor? |
Shouldn't be too much, check out |
@nickmccurdy I've opened a PR for it |
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When a Jest test requires a module in
node_modules
that usesrequire-dir
with a relative path, the path is resolved relatively to the package that has the executed Jest test instead of the package that usesrequire-dir
(what's supposed to happen). This issue does not occur if exactly the same code is executed directly through Node instead of Jest.If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.npm install-test
This issue can also be observed by requiring code that uses
npm-check-updates
(which also usesrequire-dir
) via JavaScript in a Jest test.What is the expected behavior?
Jest's execution environment should allow
require-dir
to function normally, requiring a relative directory with therequireDir('./example')
syntax even in a dependency. Jest should also behave the same as Node itself, or work around this difference in execution environments.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
index.test.js
or__tests__/index.js
naming conventionsrequire-dir
0.3.2The text was updated successfully, but these errors were encountered: