2018-12-09 09:44:44 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Test both sets of arguments that check syntax
|
2018-12-09 09:44:44 -08:00
|
|
|
const syntaxArgs = [
|
2024-09-22 15:03:30 +02:00
|
|
|
'-c',
|
|
|
|
'--check',
|
2018-12-09 09:44:44 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
const notFoundRE = /^Error: Cannot find module/m;
|
|
|
|
|
|
|
|
// test file not found
|
|
|
|
[
|
|
|
|
'syntax/file_not_found.js',
|
2021-03-26 08:51:08 -07:00
|
|
|
'syntax/file_not_found',
|
2018-12-09 09:44:44 -08:00
|
|
|
].forEach(function(file) {
|
|
|
|
file = fixtures.path(file);
|
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Loop each possible option, `-c` or `--check`
|
2024-09-22 15:03:30 +02:00
|
|
|
syntaxArgs.forEach(function(flag) {
|
2024-09-29 22:44:52 +02:00
|
|
|
exec(...common.escapePOSIXShell`"${process.execPath}" ${flag} "${file}"`, common.mustCall((err, stdout, stderr) => {
|
2019-03-22 03:44:26 +01:00
|
|
|
// No stdout should be produced
|
2018-12-09 09:44:44 -08:00
|
|
|
assert.strictEqual(stdout, '');
|
|
|
|
|
2018-12-10 13:27:32 +01:00
|
|
|
// `stderr` should have a module not found error message.
|
2021-08-29 10:14:22 +02:00
|
|
|
assert.match(stderr, notFoundRE);
|
2018-12-09 09:44:44 -08:00
|
|
|
|
2018-12-13 09:17:35 -08:00
|
|
|
assert.strictEqual(err.code, 1,
|
|
|
|
`code ${err.code} !== 1 for error:\n\n${err}`);
|
2018-12-09 09:44:44 -08:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|