From 6a83525f3c3275c47d7b56cb37906eb7ac98b697 Mon Sep 17 00:00:00 2001 From: Evgenii Shchepotev Date: Wed, 29 May 2019 19:45:26 +0300 Subject: [PATCH 1/3] test: add eval ESM module tests --- test/parallel/test-cli-eval.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 3fd00e7cdb4581..f83de22c0db0eb 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -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( + `${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); + })); From 72e8ac24896f8cf22cbfcde392c1a00dc15c4e72 Mon Sep 17 00:00:00 2001 From: Evgenii Shchepotev Date: Tue, 4 Jun 2019 12:47:18 +0300 Subject: [PATCH 2/3] test: do not validate ESM warning --- test/parallel/test-cli-eval.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index f83de22c0db0eb..6b99495acec394 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -235,14 +235,11 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`, // 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( `${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. @@ -251,7 +248,6 @@ child.exec( 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. From bed5887b72a2d11c446ef94b1693737987e110ea Mon Sep 17 00:00:00 2001 From: Evgenii Shchepotev Date: Tue, 4 Jun 2019 12:50:43 +0300 Subject: [PATCH 3/3] test: validate import.meta and require --- test/parallel/test-cli-eval.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 6b99495acec394..acf20bb77fc9d1 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -237,7 +237,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`, const execOptions = '--experimental-modules --input-type module'; child.exec( `${nodejs} ${execOptions} --eval "console.log(42)"`, - common.mustCall((err, stdout, stderr) => { + common.mustCall((err, stdout) => { assert.ifError(err); assert.strictEqual(stdout, '42\n'); })); @@ -245,7 +245,7 @@ child.exec( // Assert that "42\n" is written to stdout with print option. child.exec( `${nodejs} ${execOptions} --print --eval "42"`, - common.mustCall((err, stdout, stderr) => { + common.mustCall((err, stdout) => { assert.ifError(err); assert.strictEqual(stdout, '42\n'); })); @@ -258,3 +258,19 @@ child.exec( 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'); + }));