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// Match on the name of the `Error` but not the message as it is different
111cb0ef41Sopenharmony_ci// depending on the JavaScript engine.
121cb0ef41Sopenharmony_ciconst syntaxErrorRE = /^SyntaxError: \b/m;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// Should work with -r flags
151cb0ef41Sopenharmony_ci['-c', '--check'].forEach(function(checkFlag) {
161cb0ef41Sopenharmony_ci  ['-r', '--require'].forEach(function(requireFlag) {
171cb0ef41Sopenharmony_ci    const preloadFile = fixtures.path('no-wrapper.js');
181cb0ef41Sopenharmony_ci    const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js');
191cb0ef41Sopenharmony_ci    const args = [requireFlag, preloadFile, checkFlag, file];
201cb0ef41Sopenharmony_ci    const cmd = [node, ...args].join(' ');
211cb0ef41Sopenharmony_ci    exec(cmd, common.mustCall((err, stdout, stderr) => {
221cb0ef41Sopenharmony_ci      assert.strictEqual(err instanceof Error, true);
231cb0ef41Sopenharmony_ci      assert.strictEqual(err.code, 1,
241cb0ef41Sopenharmony_ci                         `code ${err.code} !== 1 for error:\n\n${err}`);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci      // No stdout should be produced
271cb0ef41Sopenharmony_ci      assert.strictEqual(stdout, '');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci      // stderr should have a syntax error message
301cb0ef41Sopenharmony_ci      assert.match(stderr, syntaxErrorRE);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci      // stderr should include the filename
331cb0ef41Sopenharmony_ci      assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
341cb0ef41Sopenharmony_ci    }));
351cb0ef41Sopenharmony_ci  });
361cb0ef41Sopenharmony_ci});
37