• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const { exec } = require('child_process');
6const fixtures = require('../common/fixtures');
7
8const node = process.execPath;
9
10// Match on the name of the `Error` but not the message as it is different
11// depending on the JavaScript engine.
12const syntaxErrorRE = /^SyntaxError: \b/m;
13
14// Should work with -r flags
15['-c', '--check'].forEach(function(checkFlag) {
16  ['-r', '--require'].forEach(function(requireFlag) {
17    const preloadFile = fixtures.path('no-wrapper.js');
18    const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js');
19    const args = [requireFlag, preloadFile, checkFlag, file];
20    const cmd = [node, ...args].join(' ');
21    exec(cmd, common.mustCall((err, stdout, stderr) => {
22      assert.strictEqual(err instanceof Error, true);
23      assert.strictEqual(err.code, 1,
24                         `code ${err.code} !== 1 for error:\n\n${err}`);
25
26      // No stdout should be produced
27      assert.strictEqual(stdout, '');
28
29      // stderr should have a syntax error message
30      assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`);
31
32      // stderr should include the filename
33      assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
34    }));
35  });
36});
37