-
Notifications
You must be signed in to change notification settings - Fork 1.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
Support loading ESM test files #2382
Conversation
You need to |
the try catch is there to prevent the unknown import() function error (node < 10?) |
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.
Nice! Big picture the current error message needs to be updated for when ESM is not available, cause with this PR AVA does support loading ESM test files.
It'd be good to have a test for when ESM does work, too.
The XO output should contain the failing rule. Then after that line add |
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 for the updates @arlac77!
@arlac77 great find with the path vs URL stuff! I think there's two remaining issues:
|
Where can I find CJS module error code ? |
No, the issue is the Instead I think the safest way to deal with this is to explicitly detect ESM support by importing a known |
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.
We should also update https://github.com/avajs/ava/blob/8fa28254dbebef32cbde05c0c9a49061d0ef82f8/docs/recipes/es-modules.md which currently states that ESM files cannot be loaded.
Thanks @arlac77. This looks good at first glance, but it'll probably take until the weekend before I can take a closer look. |
Rename to supportsESM.
@arlac77 this is great! I've made some tweaks and updated the documentation. Will merge when CI passes 🎊 |
let requireFn = require; | ||
const load = async ref => { | ||
for (const extension of extensionsToLoadAsModules) { | ||
if (ref.endsWith(`.${extension}`)) { | ||
ipc.send({type: 'internal-error', err: serializeError('Internal runner error', false, new Error('AVA cannot yet load ESM files.'))}); | ||
if (await supportsESM()) { // eslint-disable-line no-await-in-loop |
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.
I think
if (cachedSupportsESMResult || await supportsESM())
can make this loop faster.
Fixes #2344.
Brute force try import(ref)
at least works for me
How to make xo not complain about fully qualified imports ?