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
--- 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);
+ });
+}