-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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: ability to decorate esm module name before importing it #4945
Conversation
|
@giltayar could you have a look a this PR, please? |
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.
Besides the comment I added, I am not sure why we need this. What is the use case behind it? Who will use this additional parameter and for what use case.
Until we understand this, I'm not sure we should merge this PR.
Any who has problems with esm modules caching while using mocha by API:
node.js doc suggests only one whay to deal with it - different queries. There are not too many such cases for now because most of the existing community uses CJS modules for tests for now. But there will be more. |
@j0tunn Ah. I didn't know that Note though that the sub-dependencies of the test files will not be loaded. You will probably need an ESM loader for that. So if you change the small change that I requested, and add appropriate tests, this PR will be approved by me. But don't forget those tests... |
@giltayar done |
@juergba from my point of view, we're good to go on this PR, which makes a lot of sense for developers using the API in an ESM setting. |
@j0tunn Mocha has its own Could you provide a short sample for me to do some testing, please? @fvictorio would you mind reviewing this PR? Does it fix your issue? |
As far as I understand
There is a short sample in PR description. In case of using mocha.loadFilesAsync({
esmDecorator: file => `${file}?foo=${new Date()}`
}); |
Thanks a lot for working on this @j0tunn! I can confirm this seems to fix my issue if I do something like this: await (mocha as any).loadFilesAsync({
esmDecorator: (file) => `${file}?invalidateCache=${Math.random()}`
}); Notice the |
I don't know,
I won't merge this PR without any testing, this could take some time though.
@j0tunn could you add this statement to this PR's description, please? |
Done. |
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.
@j0tunn thank you
Description of the Change
This PR adds ability to decorate ESM-module name right before it will be imported by passing
esmDecorator
function toloadFilesAsync
method.Why should this be in core?
It helps to deal with ESM cashing issues just by adding some query parameters to modue name:
And it backwards compatible.
Note though that the sub-dependencies of the test files will not be reloaded.
Applicable issues
It is an enhancement (minor release).