• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const { spawnSync } = require('child_process');
6
7const node = process.execPath;
8
9// Test both sets of arguments that check syntax
10const syntaxArgs = [
11  '-c',
12  '--check',
13];
14
15// Should not execute code piped from stdin with --check.
16// Loop each possible option, `-c` or `--check`.
17syntaxArgs.forEach(function(arg) {
18  const stdin = 'throw new Error("should not get run");';
19  const c = spawnSync(node, [arg], { encoding: 'utf8', input: stdin });
20
21  // No stdout or stderr should be produced
22  assert.strictEqual(c.stdout, '');
23  assert.strictEqual(c.stderr, '');
24
25  assert.strictEqual(c.status, 0);
26});
27
28// Check --input-type=module
29syntaxArgs.forEach(function(arg) {
30  const stdin = 'export var p = 5; throw new Error("should not get run");';
31  const c = spawnSync(
32    node,
33    ['--no-warnings', '--input-type=module', arg],
34    { encoding: 'utf8', input: stdin }
35  );
36
37  // No stdout or stderr should be produced
38  assert.strictEqual(c.stdout, '');
39  assert.strictEqual(c.stderr, '');
40
41  assert.strictEqual(c.status, 0);
42});
43