Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edb1a3c

Browse filesBrowse files
zecksonBridgeAR
authored andcommitted
test: add eval ESM module tests
PR-URL: #27956 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 53cc16c commit edb1a3c
Copy full SHA for edb1a3c

File tree

Expand file treeCollapse file tree

1 file changed

+45
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+45
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,48 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
229229
assert.strictEqual(err, null);
230230
}));
231231
});
232+
233+
// ESModule eval tests
234+
235+
236+
// Assert that "42\n" is written to stdout on module eval.
237+
const execOptions = '--experimental-modules --input-type module';
238+
child.exec(
239+
`${nodejs} ${execOptions} --eval "console.log(42)"`,
240+
common.mustCall((err, stdout) => {
241+
assert.ifError(err);
242+
assert.strictEqual(stdout, '42\n');
243+
}));
244+
245+
// Assert that "42\n" is written to stdout with print option.
246+
child.exec(
247+
`${nodejs} ${execOptions} --print --eval "42"`,
248+
common.mustCall((err, stdout) => {
249+
assert.ifError(err);
250+
assert.strictEqual(stdout, '42\n');
251+
}));
252+
253+
// Assert that error is written to stderr on invalid input.
254+
child.exec(
255+
`${nodejs} ${execOptions} --eval "!!!!"`,
256+
common.mustCall((err, stdout, stderr) => {
257+
assert.ok(err);
258+
assert.strictEqual(stdout, '');
259+
assert.ok(stderr.indexOf('SyntaxError: Unexpected end of input') > 0);
260+
}));
261+
262+
// Assert that require is undefined in ESM support
263+
child.exec(
264+
`${nodejs} ${execOptions} --eval "console.log(typeof require);"`,
265+
common.mustCall((err, stdout) => {
266+
assert.ifError(err);
267+
assert.strictEqual(stdout, 'undefined\n');
268+
}));
269+
270+
// Assert that import.meta is defined in ESM
271+
child.exec(
272+
`${nodejs} ${execOptions} --eval "console.log(typeof import.meta);"`,
273+
common.mustCall((err, stdout) => {
274+
assert.ifError(err);
275+
assert.strictEqual(stdout, 'object\n');
276+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.