-
-
Notifications
You must be signed in to change notification settings - Fork 32k
esm: syncify default path of ModuleLoader.load
#57419
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
esm: syncify default path of ModuleLoader.load
#57419
Conversation
Review requested:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57419 +/- ##
==========================================
- Coverage 90.18% 90.17% -0.01%
==========================================
Files 636 636
Lines 188057 188032 -25
Branches 36900 36889 -11
==========================================
- Hits 169596 169556 -40
- Misses 11224 11231 +7
- Partials 7237 7245 +8
🚀 New features to boost your workflow:
|
I investigated a bit on the weird failure and apparently there is some scheduling issue. |
Sweet, thanks! I was gonna take a look this evening. I'll apply it as soon as I finish work 🙂 |
0bcfae3
to
e7941fe
Compare
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 this test's setup is the actual issue (I'm not sure why it was ever working 🤔):
global-hooks.js
contains a non-await
ed dynamic import at the root:import('node:test').then((test) => …)
, which left a dangling promise (so node can't guarantee the global file has finished executing before starting with the entry-point). It was probably done that way because TLA is not available in CJS, and the file is shared by both test cases.- The global hooks setup file
--import
/--require
'd itself is indeed run before the test files (addedconsole.log('\n==global hooks==\n')
at line 1, and it prints first).
I suspect it was set up this way in order to re-use for both cjs and esm. @avivkeller it looks like you authored this test ~6 months ago. Would you perchance remember whether there was another reason? I can't think of one, but if there is, my change could inadvertently cause something to no-longer be covered.
Splitting global-hooks.js
into global-hooks.cjs
+ require & global-hooks.mjs
+ static import, the sequence issue appears to be fixed.
However, a few of the global test hooks are now just not printing at all for the --require
case (red lines are missing in actual vs expected):
before(): global
before one: <root>
suite one
before two: <root>
suite two
- beforeEach(): global
beforeEach one: suite one - test
beforeEach two: suite one - test
suite one - test
- afterEach(): global
afterEach one: suite one - test
afterEach two: suite one - test
before suite two: suite two
- beforeEach(): global
beforeEach one: suite two - test
beforeEach two: suite two - test
suite two - test
- afterEach(): global
afterEach one: suite two - test
afterEach two: suite two - test
- after(): global
after one: <root>
after two: <root>
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.
Sorry I didn't see this earlier!
I suspect it was set up this way in order to re-use for both cjs and esm.
Exactly—using a single test file for both ESM and CJS helped keep things simpler, as I could simply flip-flop the --import
vs --require
call.
That’s definitely an odd issue you’re encountering. I have a few theories (though no concrete evidence to back them up):
- It’s possible that an error occurs in the chain for all but
before
, though that seems unlikely. - Another possibility is a race condition. Could it be that
before
runs successfully simply because it’s the first one executed in the file?
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!
Race condition seems the most likely candidate since this PR is affecting a/sync behaviour. Strange that only this test is failing though—I would have expected a bunch of failures.
PTAL @nodejs/test_runner We're encountering an issue where a global hook script loaded via @JakobJingleheimer and I investigated the root cause, but since I haven’t worked on the test runner in a while, we could use some help. We've determined that the issue stems from the test runner's loading of CJS files. When modifying the following code in const userImports = getOptionValue('--import').concat(getOptionValue('--require'));
for (let i = 0; i < userImports.length; i++) {
await cascadedLoader.import(userImports[i], parentURL, kEmptyObject);
} (This would need primordials, but we are only testing right now) If I run a test with a
This suggests that the initial CJS load (which we haven’t yet pinpointed) runs and executes only the first We need help identifying where the CJS load originally happens and whether we can remove it in favor of the snippet above or modify it to use the ESM loader. |
thanks @avivkeller! The issue actually is actually present is a simpler change (merely the dangling promise fix) #57595 So that means it's unrelated to this change 😁 Let's move the discussion over to that PR. |
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.
lgtm
a2d0fcc
to
f60650f
Compare
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - esm: syncify default path of `ModuleLoader.load` ⚠ - !fixup: don't force `ModuleLoader.load` to be async (can via hooks) ⚠ - !fixup: remove obsolete `getSource` in favour of `getSourceSync` ⚠ - !fixup: account for `node:internal` in `isMain` check ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/14236594120 |
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.
lgtm
Co-Authored-By: Marco Ippolito <[email protected]>
This reverts commit f60650f.
This reverts commit 76c93d5.
ab09afb
to
a31d408
Compare
Could I get a re-approval to unlock CI? |
@@ -806,9 +806,9 @@ class ModuleLoader { | |||
* if any. | |||
* @param {string} url The URL of the module to be loaded. | |||
* @param {object} context Metadata about the module | |||
* @returns {Promise<{ format: ModuleFormat, source: ModuleSource }>} | |||
* @returns {Promise<{ format: ModuleFormat, source: ModuleSource }> | { format: ModuleFormat, source: ModuleSource }} |
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 that this can be fully synchronous if it uses this.#customizations.loadSync
below. But I am fine with leaving that to another PR.
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.
Actually, isn't it only sync now?
Ack, nvmd. No.
This comment has been minimized.
This comment has been minimized.
Landed in 5e1537c |
PR-URL: #57419 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
In #57390 I somehow inadvertently created a branch on the node repo instead of my fork, and then got stuck.
Parent issue: #55782