-
-
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 require.main and require.main.filename properties #2150
Comments
I would really like to see this functionality. |
Please send a PR to jest-runtime in the packages folder, it has the require implementation. |
I'm interested in implementing this feature |
Could I go for this |
@zamotany was first, so let's give him some time to work on. |
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. |
Feature request
What is the current behavior?
Currently, the
require
function does not contain amain
property. When running normally in Node, outside of Jest, that property is set to the initial module, the one that was started.E.g. when running
node ./test.js
in all descendent modules the value ofrequire.main.filename
will be the full path of the initialtest.js
file.NodeJS reference
What is the expected behavior?
It would be great if
require.main
could be set to the module of the originating test file. This way descendent modules could find out the file path to the test that's loading them.My use case is mocking a dynamic loader that resolves files relative to the path of the file that was initially executed. For that, I need to know the path of the test file from within the external module.
Here's an full, working example that would work if this were implemented:
relative-loader.js:
test.js:
some-file.js:
The text was updated successfully, but these errors were encountered: