Skip to content

Commit 174b3c4

Browse files
zecksontargos
authored andcommitted
test: add eval ESM module tests
PR-URL: #27956 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent faeed80 commit 174b3c4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/parallel/test-cli-eval.js

+45
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)