"use strict";
+//-----------------------------------------------------------------------------
+// Requirements
+//-----------------------------------------------------------------------------
+
const childProcess = require("child_process");
const fs = require("fs");
const assert = require("chai").assert;
const path = require("path");
+//------------------------------------------------------------------------------
+// Data
+//------------------------------------------------------------------------------
+
const EXECUTABLE_PATH = path.resolve(path.join(__dirname, "../../bin/eslint.js"));
+//-----------------------------------------------------------------------------
+// Helpers
+//-----------------------------------------------------------------------------
+
/**
* Returns a Promise for when a child process exits
* @param {ChildProcess} exitingProcess The child process
* Asserts that the exit code of a given child process will equal the given value.
* @param {ChildProcess} exitingProcess The child process
* @param {number} expectedExitCode The expected exit code of the child process
- * @returns {Promise} A Promise that fulfills if the exit code ends up matching, and rejects otherwise.
+ * @returns {Promise<void>} A Promise that fulfills if the exit code ends up matching, and rejects otherwise.
*/
function assertExitCode(exitingProcess, expectedExitCode) {
return awaitExit(exitingProcess).then(exitCode => {
return awaitExit(runningProcess).then(() => ({ stdout, stderr }));
}
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
describe("bin/eslint.js", () => {
const forkedProcesses = new Set();
filePath: "<text>",
messages: [],
errorCount: 0,
+ fatalErrorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
return assertExitCode(child, 1);
});
+ it("has exit code 2 if a syntax error is thrown when exit-on-fatal-error is true", () => {
+ const child = runESLint(["--stdin", "--no-eslintrc", "--exit-on-fatal-error"]);
+
+ child.stdin.write("This is not valid JS syntax.\n");
+ child.stdin.end();
+ return assertExitCode(child, 2);
+ });
+
it("has exit code 1 if a linting error occurs", () => {
const child = runESLint(["--stdin", "--no-eslintrc", "--rule", "semi:2"]);
const child = runESLint(["--no-ignore", invalidConfig]);
const exitCodeAssertion = assertExitCode(child, 2);
const outputAssertion = getOutput(child).then(output => {
- const expectedSubstring = ": bad indentation of a mapping entry at line";
-
assert.strictEqual(output.stdout, "");
- assert.include(output.stderr, expectedSubstring);
+ assert.match(
+ output.stderr,
+ /: bad indentation of a mapping entry \(\d+:\d+\)/u // a part of the error message from `js-yaml` dependency
+ );
});
return Promise.all([exitCodeAssertion, outputAssertion]);