-
-
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
feat(jest-util): add requireOrImportModule util for importing CJS or ESM #11199
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Can you update all usage of import
after require
fails to use this?
Sure, in this pr or open another one? |
This one I think - then we "prove" the abstraction works |
if (innerError.message === 'Not supported') { | ||
throw new Error( | ||
`Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${configPath}`, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All LTS Node should support dynamic import after Node 10 EOL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Jest 27 will support Node 10, but 28 will drop it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we should keep the warning for now
I encounter some problem when writing e2e test. |
You don't have to write a new e2e test for this, the existing e2e tests for the modules that are written in ESM are enough as long as they use this new util 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
According to #11167, we will support ESM of pluggable modules.
We may use the same logic to import them, so I extract it into an util function.
I think it should be useful in later work!
Cons:
Will lose information of which module type importing in error message
But I think it is ok, user can find out by file path.
Test plan
TODO