node/test/parallel/test-cli-syntax-piped-good.js
Geoffrey Booth 96e46d37c4
esm: replace --entry-type with --input-type
New flag is for string input only

PR-URL: https://github.com/nodejs/node/pull/27184
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-04-16 12:41:59 -04:00

43 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const node = process.execPath;
// Test both sets of arguments that check syntax
const syntaxArgs = [
'-c',
'--check'
];
// Should not execute code piped from stdin with --check.
// Loop each possible option, `-c` or `--check`.
syntaxArgs.forEach(function(arg) {
const stdin = 'throw new Error("should not get run");';
const c = spawnSync(node, [arg], { encoding: 'utf8', input: stdin });
// No stdout or stderr should be produced
assert.strictEqual(c.stdout, '');
assert.strictEqual(c.stderr, '');
assert.strictEqual(c.status, 0);
});
// Check --input-type=module
syntaxArgs.forEach(function(arg) {
const stdin = 'export var p = 5; throw new Error("should not get run");';
const c = spawnSync(
node,
['--experimental-modules', '--no-warnings', '--input-type=module', arg],
{ encoding: 'utf8', input: stdin }
);
// No stdout or stderr should be produced
assert.strictEqual(c.stdout, '');
assert.strictEqual(c.stderr, '');
assert.strictEqual(c.status, 0);
});