]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/bin/eslint.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / bin / eslint.js
index 7500d6611cee76f3fbe04284d242a92cb9c62cfa..38f132b583964b1895713942a8cf8241ac732efd 100644 (file)
@@ -5,13 +5,25 @@
 
 "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
@@ -25,7 +37,7 @@ function awaitExit(exitingProcess) {
  * 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 => {
@@ -48,6 +60,10 @@ function getOutput(runningProcess) {
     return awaitExit(runningProcess).then(() => ({ stdout, stderr }));
 }
 
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
 describe("bin/eslint.js", () => {
     const forkedProcesses = new Set();
 
@@ -89,6 +105,7 @@ describe("bin/eslint.js", () => {
                     filePath: "<text>",
                     messages: [],
                     errorCount: 0,
+                    fatalErrorCount: 0,
                     warningCount: 0,
                     fixableErrorCount: 0,
                     fixableWarningCount: 0,
@@ -117,6 +134,14 @@ describe("bin/eslint.js", () => {
             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"]);
 
@@ -366,10 +391,11 @@ describe("bin/eslint.js", () => {
             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]);