Skip to content

Commit

Permalink
test: add eval ESM module tests
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zeckson authored and BridgeAR committed Jun 17, 2019
1 parent 53cc16c commit edb1a3c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,48 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
assert.strictEqual(err, null);
}));
});

// ESModule eval tests


// Assert that "42\n" is written to stdout on module eval.
const execOptions = '--experimental-modules --input-type module';
child.exec(
`${nodejs} ${execOptions} --eval "console.log(42)"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
assert.strictEqual(stdout, '42\n');
}));

// Assert that "42\n" is written to stdout with print option.
child.exec(
`${nodejs} ${execOptions} --print --eval "42"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
assert.strictEqual(stdout, '42\n');
}));

// Assert that error is written to stderr on invalid input.
child.exec(
`${nodejs} ${execOptions} --eval "!!!!"`,
common.mustCall((err, stdout, stderr) => {
assert.ok(err);
assert.strictEqual(stdout, '');
assert.ok(stderr.indexOf('SyntaxError: Unexpected end of input') > 0);
}));

// Assert that require is undefined in ESM support
child.exec(
`${nodejs} ${execOptions} --eval "console.log(typeof require);"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
assert.strictEqual(stdout, 'undefined\n');
}));

// Assert that import.meta is defined in ESM
child.exec(
`${nodejs} ${execOptions} --eval "console.log(typeof import.meta);"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
assert.strictEqual(stdout, 'object\n');
}));

0 comments on commit edb1a3c

Please sign in to comment.