Skip to content
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

test: add eval ESM module tests #27956

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,36 @@ 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';
const esmWarning = 'ExperimentalWarning: ' +
'The ESM module loader is experimental.\n';
child.exec(
zeckson marked this conversation as resolved.
Show resolved Hide resolved
`${nodejs} ${execOptions} --eval "console.log(42)"`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
assert.strictEqual(stdout, '42\n');
assert.ok(stderr.endsWith(esmWarning));
}));

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

// 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);
}));