Bug 2067148 - Add jest at the top-level and switch eslint-plugin-mozilla to use it. r=frontend-codestyle-reviewers,mossop

Differential Revision: https://phabricator.services.mozilla.com/D321861
This commit is contained in:
Mark Banner
2026-09-01 14:01:14 +00:00
committed by mbanner@mozilla.com
parent c918afd7dc
commit 63154aa768
7 changed files with 3169 additions and 1335 deletions
+3093 -408
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -26,6 +26,7 @@
"eslint-plugin-sdl": "file:tools/lint/eslint/eslint-plugin-sdl-vendored",
"eslint-plugin-spidermonkey-js": "file:tools/lint/eslint/eslint-plugin-spidermonkey-js",
"globals": "17.9.0",
"jest": "30.4.2",
"jsdoc": "4.0.5",
"license-checker-rseidelsohn": "4.4.2",
"lit": "3.3.3",
+2
View File
@@ -218,6 +218,7 @@ eslint-plugin-mozilla:
docker-image: {in-tree: "lint"}
run:
command: >
cp -r $MOZ_FETCHES_DIR/node_modules node_modules &&
cp -r $MOZ_FETCHES_DIR/eslint-plugin-mozilla/node_modules tools/lint/eslint/eslint-plugin-mozilla/node_modules &&
./mach configure --disable-compile-environment &&
PATH=$PATH:$MOZ_FETCHES_DIR/node/bin ./mach npm test --prefix tools/lint/eslint/eslint-plugin-mozilla
@@ -227,6 +228,7 @@ eslint-plugin-mozilla:
fetches:
toolchain:
- linux64-node
- node-modules
- eslint-plugin-mozilla
stylelint-plugin-mozilla:
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
export default {
testEnvironment: "node",
transform: {},
testMatch: ["<rootDir>/tests/*.mjs"],
reporters: ["<rootDir>/reporters/mozilla-format.js"],
};
File diff suppressed because it is too large Load Diff
@@ -29,8 +29,7 @@
"toml-eslint-parser": "1.0.3"
},
"devDependencies": {
"eslint": "9.39.1",
"mocha": "11.8.0"
"eslint": "9.39.1"
},
"peerDependencies": {
"eslint": "^9.0.0 || ^10.0.0",
@@ -48,7 +47,7 @@
},
"scripts": {
"prepack": "node scripts/createExports.mjs",
"test": "mocha --reporter 'reporters/mozilla-format.js' tests",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" NODE_NO_WARNINGS=1 npx jest",
"postpublish": "rm -f lib/environments/saved-globals.json",
"update-tooltool": "./update.sh"
},
@@ -8,53 +8,75 @@
* mach itself.
*/
/**
* @import { Reporter } from "@jest/reporters"
* @import { AggregatedResult, Test, TestCaseResult, TestContext } from "@jest/test-result"
*/
// This is a non-production file that needs to log.
/* eslint-disable no-console */
"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 = [];
runner.on("start", () => {
/**
* A reporter for Jest that outputs results in the format Treeherder expects.
*
* @implements {Reporter}
*/
class MozillaFormatter {
onRunStart() {
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}`);
});
/**
* @param {Test} test
* @param {TestCaseResult} testCaseResult
*/
onTestCaseResult(test, testCaseResult) {
let title = testCaseResult.fullName.replace(/\n/g, "|");
let fileName = path.basename(test.path);
runner.on("fail", function (test, err) {
failures.push(test);
// 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
}`
);
mocha.reporters.Base.list([test]);
});
if (testCaseResult.status == "passed") {
console.log(`TEST-PASS | ${fileName} | ${title}`);
} else if (testCaseResult.status == "failed") {
let message = testCaseResult.failureMessages[0]?.split("\n")[0];
console.log(`TEST-UNEXPECTED-FAIL | ${fileName} | ${title} | ${message}`);
}
}
runner.on("end", function () {
/**
* @param {Set<TestContext>} testContexts
* @param {AggregatedResult} results
*/
onRunComplete(testContexts, results) {
// Space the results out visually with an additional blank line.
console.log("");
console.log("INFO | Result summary:");
console.log(`INFO | Passed: ${passes}`);
console.log(`INFO | Failed: ${failures.length}`);
console.log(`INFO | Passed: ${results.numPassedTests}`);
console.log(`INFO | Failed: ${results.numFailedTests}`);
console.log("SUITE-END");
// Space the failures out visually with an additional blank line.
console.log("");
console.log("Failure summary:");
mocha.reporters.Base.list(failures);
process.exit(failures.length);
});
for (let result of results.testResults) {
if (result.numFailingTests) {
let fileName = path.basename(result.testFilePath);
for (let fileResult of result.testResults) {
if (fileResult.status == "failed") {
console.log("");
let title = fileResult.fullName.replace(/\n/g, "|");
console.log(
`TEST-UNEXPECTED-FAIL | ${fileName} | ${title} | ${fileResult.failureDetails[0]?.message}`
);
}
}
}
}
}
}
module.exports = MozillaFormatter;