-
-
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
fix(esm): allow import
from mocha in parallel
#4574
Conversation
Of course, my new test is failing on node 10 😇 Will have a look at that soon (probably need to enable |
I ended up skipping the tests on node 10. Importing esm style from a cjs module is supported from node 12. |
@nicojs Are
|
@juergba Oh, I didn't notice. You're right! This is rich! What happened is interesting. Node.js has this mechanism when you What happened was that previously, that parser chocked on the mocha entry point, and defaulted to only default exports. But @nicojs's changes are making that parser very happy, so suddenly it's OK, and mocha is doing named exports from CJS. Note that my PR is still better because each of the entry points ('/tdd But it's definitely progress! |
Yeah, I think what was happening is that when you This PR fixes that, because it allows |
@giltayar can you build your ESM entry points on top of this PR? Or does it prevent it in anyway?
Do we have any negative implications on that? @nicojs could you have a short look on our watcher, please? I remember difficulties with the UI loading. Maybe we can simplify some coding? |
@juergba of course. Once this lands, my PR will return to what it was initially: making Mocha a dual-mode library with real ESM entry points that align with the stamdard interfaces. I will remove all the crud from there that pertains to fixing the problem that this PR fixed (much more elegantly). But that PR now becomes less urgent, and is now a PR that just fine tunes the entry points to be more "correct" and not exposes all test functions of all the interfaces, but exposes entry points for each interface that expose only the functions for that entry point. The main entry point will still expose everything, for backward compatibility. |
It would be awesome to get some feedback regarding the watcher and especially lib/browser-entry.js . |
Hi @juergba 👋, I've taken a look.
|
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.
Don't merge this PR yet! edit: since then fixed
Ok, I think I've added proxying of Looking at https://mochajs.org/#retry-tests I can only find |
@nicojs thank you for your comments. I try to answer some of your questions. I understand now that we are only talking about the require interface. lib/cli/watch-run.js: yes, our watcher is limited to CJS, we have documented that somewhere. Nevertheless some users run ESM in parallel mode, which seems to work. The ESM cache is "cleared" by killing the worker processes on each re-run.
I will need more time to review/test your recent additions. The topic is still fuzzy to me. Where does this |
Thanks for your explanation @juergba I've tried to add
What do you mean by I agree that not every alias needs exporting. Users who are using the One thing we could do is export |
@nicojs when I test: const ste = require('mocha').describe;
ste('test suite', () => {
it('test', () => {
console.log('running the test');
});
}); In Mocha v.8.3.0 the test passes, with this branch the result is Am I doing something wrong? Or do your test use the global keywords, not the required/imported ones? |
Some additional information:
|
I suggest adding Exporting named functions eg. |
@juergba the error in context.run = mocha.options.delay && common.runWithSuite(suite); If I remove the This could be something that was introduced because there was no proxy? As a hack? Something that maybe isn't needed anymore? |
The reason why I've added
I did that now. Note that this is technically a new feature since it wasn't exported before. |
Requirements
Description of the Change
Fixes the issue where
import { describe, it } from 'mocha'
doesn't work with--parallel
when using es modules by proxyingdescribe
,it
and friends to their actual contextual counterpart.Alternate Designs
There is not much else we can do I think, other than going full blown esm (for example, using package exports).
Why should this be in core?
Its imported from core (bare
'mocha'
).Benefits
Allows
import {...} from 'mocha'
in an es module setting withparallel
Possible Drawbacks
More code to maintain
Applicable issues
Closes #4559, should be a patch release.