Bug 1379119 - Add a mozilla specific reporter for mocha when used with eslint-plugin-mozilla to be compatible with treeherder. r?ahal draft
authorMark Banner <standard8@mozilla.com>
Mon, 10 Jul 2017 17:08:53 +0100
changeset 607580 76ac689b2fcb0e70565759666966162d6aa9a452
parent 607503 09a4282d1172ac255038e7ccacfd772140b219e2
child 607581 8f36347bf0f43da5e27c5e71febe977aabd91f75
push id68025
push userbmo:standard8@mozilla.com
push dateWed, 12 Jul 2017 12:17:01 +0000
reviewersahal
bugs1379119
milestone56.0a1
Bug 1379119 - Add a mozilla specific reporter for mocha when used with eslint-plugin-mozilla to be compatible with treeherder. r?ahal MozReview-Commit-ID: 3QVaSXAfa1F
tools/lint/eslint/eslint-plugin-mozilla/package.json
tools/lint/eslint/eslint-plugin-mozilla/reporters/mozilla-format.js
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -23,24 +23,25 @@
     "escope": "^3.6.0",
     "espree": "^3.4.0",
     "estraverse": "^4.2.0",
     "globals": "^9.14.0",
     "ini-parser": "^0.0.2",
     "sax": "^1.2.2"
   },
   "devDependencies": {
+    "eslint": "^4.2.0",
     "mocha": "3.2.0"
   },
   "peerDependencies": {
     "eslint": "^3.0.0 || ^4.0.0",
     "eslint-plugin-no-unsanitized": "^2.0.1"
   },
   "engines": {
     "node": ">=6.9.1"
   },
   "scripts": {
     "prepack": "node scripts/createExports.js",
-    "test": "mocha -R dot tests",
+    "test": "mocha -R dot --reporter 'reporters/mozilla-format.js' tests",
     "postpublish": "rm -f lib/modules.json lib/environments/saved-globals.json"
   },
   "license": "MPL-2.0"
 }
new file mode 100644
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/reporters/mozilla-format.js
@@ -0,0 +1,42 @@
+/**
+ * This file outputs the format that treeherder requires. If we integrate
+ * these tests with ./mach, then we may replace this with a json handler within
+ * mach itself.
+ */
+
+"use strict";
+
+var mocha = require("mocha");
+var path = require("path");
+module.exports = MozillaFormatter;
+
+function MozillaFormatter(runner) {
+  mocha.reporters.Base.call(this, runner);
+  var passes = 0;
+  var failures = 0;
+
+  runner.on("start", () => {
+    console.log("SUITE-START | eslint-plugin-mozilla");
+  });
+
+  runner.on("pass", function(test) {
+    passes++;
+    let title = test.title.replace(/\n/g, "|");
+    console.log(`TEST-PASS | ${path.basename(test.file)} | ${title}`);
+  });
+
+  runner.on("fail", function(test, err) {
+    failures++;
+    // Replace any newlines in the title.
+    let title = test.title.replace(/\n/g, "|");
+    console.log(`TEST-UNEXPECTED-FAIL | ${path.basename(test.file)} | ${title} | ${err.message}`);
+  });
+
+  runner.on("end", function() {
+    console.log("INFO | Result summary:");
+    console.log(`INFO | Passed: ${passes}`);
+    console.log(`INFO | Failed: ${failures}`);
+    console.log("SUITE-END");
+    process.exit(failures);
+  });
+}