☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix: show built-in reporters in --list-reporters (#6361)
Mostafa Nazari202bfe18f154
diff --git a/lib/cli/one-and-dones.js b/lib/cli/one-and-dones.jsindex aba3ee99..1c82a021 100644--- a/lib/cli/one-and-dones.js+++ b/lib/cli/one-and-dones.js@@ -22,7 +22,9 @@ const showKeys = (obj) => {keys.filter((key) =>- /^[a-z]/.test(key) && !obj[key].browserOnly && !obj[key].abstract,+ /^[a-z]/.test(key) &&+ !obj[key].browserOnly &&+ !Object.hasOwn(obj[key], "abstract"),).sort().forEach((key) => {diff --git a/test/integration/options/listReporters.spec.cjs b/test/integration/options/listReporters.spec.cjsindex 8056e97f..ea2e8a5d 100644--- a/test/integration/options/listReporters.spec.cjs+++ b/test/integration/options/listReporters.spec.cjs@@ -5,33 +5,49 @@ var invokeMocha = helpers.invokeMocha;var escapeRegExp = helpers.escapeRegExp;var reporters = require("../../../lib/mocha.cjs").reporters;+var NOT_LISTED = ["base", "html"];+describe("--list-reporters", function () {+ var expected = Object.keys(reporters).filter(function (name) {+ return /^[a-z]/.test(name) && !NOT_LISTED.includes(name);+ });+it("should dump a list of all reporters with descriptions", function (done) {- var expected = Object.keys(reporters)- .filter(function (name) {- return (- /^[a-z]/.test(name) &&- !(reporters[name].abstract || reporters[name].browserOnly)+ expect(expected.length, "to be greater than", 0);++ invokeMocha(["--list-reporters"], function (err, result) {+ if (err) {+ return done(err);+ }++ expect(result.code, "to be", 0);+ expected.forEach(function (name) {+ expect(+ result.output,+ "to match",+ new RegExp(+ escapeRegExp(name) ++ "\\s*-\\s*" ++ escapeRegExp(reporters[name].description),+ ),);- })- .map(function (name) {- return {- name: escapeRegExp(name),- description: escapeRegExp(reporters[name].description),- };});+ done();+ });+ });+ it("should not dump reporters unavailable on the command line", function (done) {invokeMocha(["--list-reporters"], function (err, result) {if (err) {return done(err);}expect(result.code, "to be", 0);- expected.forEach(function (reporter) {+ NOT_LISTED.forEach(function (name) {expect(result.output,- "to match",- new RegExp(reporter.name + "\\s*-\\s*" + reporter.description),+ "not to match",+ new RegExp("^\\s*" + escapeRegExp(name) + "\\s", "m"),);});done();