-
-
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
require.main
undefined with createRequire()
#10479
Comments
Happy to take a PR fixing this! Might be just a matter of adding a |
hey @jeysal, Can I try to fill a PR for this ? |
@mohamedsgap sure! |
@jeysal I'd love to give it a shot! May I go ahead? |
Yep! |
I'm trying to add a parent key to the object you suggested here however I get this message saying parent is deprecated: |
@flozender Is that a TypeScript warning? If so, that should be fine. |
@jeysal Yes, it is a TypeScript error. My approach is to create a parent module, assign the keys manually, and attach it to the object since the only parameter available to me is |
Hmm, looking at it again, it doesn't seem so simple anymore. |
@jeysal I will try to find out, but if you come across something please let me know. :) |
It seems they are 'cheating' with an effectively global variable |
How do you suggest I go about this? Should I try to emulate what they're doing? |
So for us that would mean dropping the current |
The currently executing test file is in the environment options, but the environment doesn't expose it. None of those seem like great options. @SimenB ideas? |
I'm down with passing it in in
We should probably populate |
I'd like to help with this, what would be a good starting point? |
Other than the |
You wanna pass the path fo the test file (https://github.com/facebook/jest/blob/c808901f5ddfcbf8be924c850bd757d3ae720876/packages/jest-runner/src/runTest.ts#L79) into the then store it on the instance of the runtime, and use that as |
Thanks! |
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
The
require.main
of modules that are required from within a test file is undefined, when:createRequire
createRequire
was given another module than the current one (observe howparent2.js
works as expected)Tested with Jest 26.4.2, Node v12.4.0
Why it's an issue
require.main.filename
to get the name of the requiring file, as it would work in a node context.Link to repl or repo (highly encouraged)
https://github.com/sguillia/jest-createRequire-repro
Expected behavior
All files are in the demo repo
child.js
parent2.js
parent3.js
Actual behavior
envinfo
The text was updated successfully, but these errors were encountered: