11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { exec } = require('child_process'); 61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst node = process.execPath; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Test both sets of arguments that check syntax 111cb0ef41Sopenharmony_ciconst syntaxArgs = [ 121cb0ef41Sopenharmony_ci ['-c'], 131cb0ef41Sopenharmony_ci ['--check'], 141cb0ef41Sopenharmony_ci]; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst notFoundRE = /^Error: Cannot find module/m; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// test file not found 191cb0ef41Sopenharmony_ci[ 201cb0ef41Sopenharmony_ci 'syntax/file_not_found.js', 211cb0ef41Sopenharmony_ci 'syntax/file_not_found', 221cb0ef41Sopenharmony_ci].forEach(function(file) { 231cb0ef41Sopenharmony_ci file = fixtures.path(file); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci // Loop each possible option, `-c` or `--check` 261cb0ef41Sopenharmony_ci syntaxArgs.forEach(function(args) { 271cb0ef41Sopenharmony_ci const _args = args.concat(file); 281cb0ef41Sopenharmony_ci const cmd = [node, ..._args].join(' '); 291cb0ef41Sopenharmony_ci exec(cmd, common.mustCall((err, stdout, stderr) => { 301cb0ef41Sopenharmony_ci // No stdout should be produced 311cb0ef41Sopenharmony_ci assert.strictEqual(stdout, ''); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci // `stderr` should have a module not found error message. 341cb0ef41Sopenharmony_ci assert.match(stderr, notFoundRE); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 1, 371cb0ef41Sopenharmony_ci `code ${err.code} !== 1 for error:\n\n${err}`); 381cb0ef41Sopenharmony_ci })); 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci}); 41