-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
esm: improve fetch_module test coverage and remove hack
#41947
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
Conversation
|
Review requested:
|
|
/cc @nodejs/loaders |
GeoffreyBooth
left a comment
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.
FYI I think this conflicts with #41950; this seems much simpler, and I would recommend that this one land first. cc @benjamingr @JakobJingleheimer
|
@GeoffreyBooth why would they conflict they change a different function don’t they? |
JakobJingleheimer
left a comment
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 improved test coverage! LGTM aside from a couple small non-blockers.
| let parent = parentURL; | ||
| const parentName = path.basename(parent.pathname); | ||
| if ( | ||
| parentName === '[eval]' || | ||
| parentName === '[stdin]' | ||
| ) parent = 'command-line'; | ||
| throw new ERR_NETWORK_IMPORT_DISALLOWED( | ||
| href, | ||
| parent, | ||
| parentURL, |
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.
The reason I added this was because the output without it seemed likely to confuse (the file path is irrelevant and makes it took like it's coming from a file, but it's not). Aside from consistency with CJS, I think this is not an improvement (I don't feel strongly though).
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 added this was because the output without it seemed likely to confuse (the file path is irrelevant and makes it took like it's coming from a file, but it's not)
If the URL is confusing, we should fix the URL itself, not try to hide it in this specific error message imo. I disagree that command-line is less confusing – what if the user didn't start the process via the command-line?
I think this is not an improvement
Note that the condition can never be true: parentName is never equals to [eval] nor [stdin] (it could be [eval1] though, but we're not testing that).
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.
If the URL is confusing, we should fix the URL itself, not try to hide it in this specific error message imo.
Sure! That works for me (and should also better support consistency).
what if the user didn't start the process via the command-line?
Is that possible?
Note that the condition can never be true: parentName is never equals to [eval] nor [stdin] (it could be [eval1] though, but we're not testing that).
If it doesn't now, it did at the time—I specifically tested CLI via -e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?
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.
Is that possible?
Sure, why not? I don't have a deep enough knowledge of the various OSs Node.js supports to list them all, but I know that CLI is just an option among others (from the GUI, as a service, from a parent process, etc.).
If it doesn't now, it did at the time—I specifically tested CLI via
-e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?
Maybe you forgot to add --input-type=module?
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.
Is that possible?
Sure, why not? I don't have a deep enough knowledge of the various OSs Node.js supports to list them all, but I know that CLI is just an option among others (from the GUI, as a service, from a parent process, etc.).
No, I mean, is there a route that exists that leads to [eval*]/[stdin] that did not originate from CLI?
If it doesn't now, it did at the time—I specifically tested CLI via
-e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?Maybe you forgot to add
--input-type=module?
I did not 🙂
| // [ERR_NETWORK_IMPORT_DISALLOWED]: import of 'http://example.com/' by | ||
| // …/[eval1] is not supported: http can only be used to load local | ||
| // resources (use https instead). | ||
| match(stderr, /[ERR_NETWORK_IMPORT_DISALLOWED]/); |
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.
Nit: I prefer the err.code & err.message.includes() used in other ESM error tests. I think consistency would be favourable.
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 don't have access to err.code not err.message, we're reading the stderr of a subprocess. FYI this test was inspired from
node/test/es-module/test-esm-import-json-named-export.mjs
Lines 7 to 24 in 15f1a45
| const child = spawn(execPath, [ | |
| path('es-modules', 'import-json-named-export.mjs'), | |
| ]); | |
| let stderr = ''; | |
| child.stderr.setEncoding('utf8'); | |
| child.stderr.on('data', (data) => { | |
| stderr += data; | |
| }); | |
| child.on('close', mustCall((code, _signal) => { | |
| notStrictEqual(code, 0); | |
| // SyntaxError: The requested module '../experimental.json' | |
| // does not provide an export named 'ofLife' | |
| match(stderr, /SyntaxError:/); | |
| match(stderr, /'\.\.\/experimental\.json'/); | |
| match(stderr, /'ofLife'/); | |
| })); |
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.
gah, yes indeed (and aligns with #41352)
I thought they did, but if they don't then feel free to ignore me. |
|
Landed in 3a1a440 |
No description provided.