☕️ Classic, reliable, trusted test framework for Node.js and the browser
Add --no-diff option (fixes mochajs/mocha#2514)
Capacitor Set7ceaaf22c934
diff --git a/bin/_mocha b/bin/_mochaindex cb7b5e63..b3c14242 100755--- a/bin/_mocha+++ b/bin/_mocha@@ -90,6 +90,7 @@ program.option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules').option('--icu-data-dir', 'include ICU data').option('--inline-diffs', 'display actual/expected differences inline within each string')+ .option('--no-diff', 'do not show a diff on failure').option('--inspect', 'activate devtools in chrome').option('--inspect-brk', 'activate devtools in chrome and break on the first line').option('--interfaces', 'display available interfaces')@@ -250,6 +251,12 @@ if (program.inlineDiffs) {mocha.useInlineDiffs(true);}+// --no-diff++if (process.argv.indexOf('--no-diff') !== -1) {+ mocha.hideDiff(true);+}+// --slow <ms>if (program.slow) {diff --git a/lib/mocha.js b/lib/mocha.jsindex 5d2ab9ac..2484ea5b 100644--- a/lib/mocha.js+++ b/lib/mocha.js@@ -389,6 +389,20 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {return this;};+/**+ * Do not show diffs at all.+ *+ * @param {Boolean} hideDiff+ * @return {Mocha}+ * @api public+ * @param {boolean} hideDiff+ * @return {Mocha}+ */+Mocha.prototype.hideDiff = function (hideDiff) {+ this.options.hideDiff = hideDiff !== undefined && hideDiff;+ return this;+};+/*** Set the timeout in milliseconds.*@@ -545,6 +559,7 @@ Mocha.prototype.run = function (fn) {exports.reporters.Base.useColors = options.useColors;}exports.reporters.Base.inlineDiffs = options.useInlineDiffs;+ exports.reporters.Base.hideDiff = options.hideDiff;function done (failures) {if (reporter.done) {diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex 0ebc5e7d..94339f34 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -208,7 +208,10 @@ exports.list = function (failures) {if (err.uncaught) {msg = 'Uncaught ' + msg;}+// explicitly show diff+ if (exports.hideDiff !== true && err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {+ escape = false;if (showDiff(err)) {stringifyDiffObjs(err);fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');diff --git a/test/integration/fixtures/no-diff.fixture.js b/test/integration/fixtures/no-diff.fixture.jsnew file mode 100644index 00000000..22b80ae8--- /dev/null+++ b/test/integration/fixtures/no-diff.fixture.js@@ -0,0 +1,8 @@+'use strict';+var assert = require('assert');++describe('Example test', function () {+ it('should fail', function () {+ assert.deepEqual([1, 2, 3], ['foo', 'bar', 'baz']);+ });+});diff --git a/test/integration/no-diff.spec.js b/test/integration/no-diff.spec.jsnew file mode 100644index 00000000..5766abce--- /dev/null+++ b/test/integration/no-diff.spec.js@@ -0,0 +1,14 @@+'use strict';++var helpers = require('./helpers');+var run = helpers.runMocha;++describe('no-diff', function () {+ it('should be honoured', function (done) {+ run('no-diff.fixture.js', ['--no-diff'], function (err, res) {+ res.output.should.not.match(/\+ expected/);+ res.output.should.not.match(/- actual/);+ done(err);+ });+ });+});diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.jsindex e38bdb9f..e9118186 100644--- a/test/reporters/base.spec.js+++ b/test/reporters/base.spec.js@@ -96,6 +96,21 @@ describe('Base reporter', function () {expect(errOut).to.not.match(/- actual/);expect(errOut).to.not.match(/\+ expected/);});++ it('should not show diffs when hideDiff is set', function () {+ var err = new Assert({ actual: 'foo', expected: 'bar' });+ var errOut;++ var test = makeTest(err);++ Base.hideDiff = true;+ Base.list([test]);+ Base.hideDiff = false; // Revert to original value++ errOut = stdout.join('\n');+ errOut.should.not.match(/\- actual/);+ errOut.should.not.match(/\+ expected/);+ });});describe('Getting two strings', function () {