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// Test both sets of arguments that check syntax 11const syntaxArgs = [ 12 ['-c'], 13 ['--check'], 14]; 15 16const notFoundRE = /^Error: Cannot find module/m; 17 18// test file not found 19[ 20 'syntax/file_not_found.js', 21 'syntax/file_not_found', 22].forEach(function(file) { 23 file = fixtures.path(file); 24 25 // Loop each possible option, `-c` or `--check` 26 syntaxArgs.forEach(function(args) { 27 const _args = args.concat(file); 28 const cmd = [node, ..._args].join(' '); 29 exec(cmd, common.mustCall((err, stdout, stderr) => { 30 // No stdout should be produced 31 assert.strictEqual(stdout, ''); 32 33 // `stderr` should have a module not found error message. 34 assert(notFoundRE.test(stderr), `${notFoundRE} === ${stderr}`); 35 36 assert.strictEqual(err.code, 1, 37 `code ${err.code} !== 1 for error:\n\n${err}`); 38 })); 39 }); 40}); 41