-
-
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
require('./')
broken if parent directory has file with the same name
#8910
Comments
Would you be able to provide a PR fixing this? The error is probably in https://github.com/facebook/jest/blob/master/packages/jest-resolve/src/defaultResolver.ts |
I don't think I have the time to put in a PR. I already worked around this in Mongoose so nothing more to do on my end. Why does Jest monkey patch require() anyway? Seems very dubious |
It's not really monkey patched, it's a full custom implementation. Used e.g. for the mocking features. |
That's alright, thanks for the great reproduction case!
There's no monkey patching involved - we inject a function into the module scope just like node does. The reason we do it is for JIT transpilation and mocking/module mapping. It also allows full isolation between tests without leaking state between them. Granted, it's imperfect, but it's way better nothing |
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. |
🐛 Bug Report
Suppose you have a file
dir/fn.js
that requires the current directory usingconst x = require('./')
, and the parent directory has a filedir.js
. In Node.js 8,x
will contain the exported value fromdir/index.js
. In Jest,x
will contain the exported value fromdir.js
To Reproduce
Steps to reproduce the behavior:
https://github.com/vkarpov15/jest-bug
Expected behavior
require()
in Jest should behave the same asrequire()
in vanilla Node.js, especially if using the Node test environment.Link to repl or repo (highly encouraged)
https://github.com/vkarpov15/jest-bug
envinfo
Re: Automattic/mongoose#8053
The text was updated successfully, but these errors were encountered: