Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Merge #1029

Christopher Hiller1f9c1bbb4028
diff --cc lib/reporters/base.js
index 2690fa10,5b9993ab..00c94def
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@@ -185,10 -184,10 +185,10 @@@ exports.list = function(failures)
}
// actual / expected diff
- if ('string' == typeof actual && 'string' == typeof expected) {
+ if (err.showDiff && 'string' == typeof actual && 'string' == typeof expected) {
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
- msg = match ? '\n ' + color('error message', match[1]) : '';
+ msg = '\n ' + color('error message', match ? match[1] : msg);
if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
diff --cc mocha.js
index eb8ce7c0,9b7c1fa5..5814b15d
--- a/mocha.js
+++ b/mocha.js
@@@ -2118,10 -2005,10 +2118,10 @@@ exports.list = function(failures)
}
// actual / expected diff
-- if ('string' == typeof actual && 'string' == typeof expected) {
++ if (err.showDiff && 'string' == typeof actual && 'string' == typeof expected) {
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
- msg = match ? '\n ' + color('error message', match[1]) : '';
+ msg = '\n ' + color('error message', match ? match[1] : msg);
if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
diff --cc test/reporters/base.js
index 00000000,0854cbd2..e8fe1e63
mode 000000,100644..100644
--- a/test/reporters/base.js
+++ b/test/reporters/base.js
@@@ -1,0 -1,42 +1,68 @@@
-var rewire = require('rewire'),
- util = require('util');
++var Base = require('../../lib/reporters/base');
+
+ describe('Base reporter', function () {
- var Base, output;
-
- beforeEach(function() {
- Base = rewire('../../lib/reporters/base');
- output = { log: [], error: [] };
- Base.__set__('console', {
- error: function() {
- output.error.push(arguments);
- },
- log: function() {
- output.log.push(arguments);
- },
- // allow info to be passed to original 'console' for debugging purposes
- info: console.info
- });
++
++ it('should show diffs with showDiff property set', function () {
++ var err = new Error('test'),
++ stderr = [],
++ stderrWrite = process.stderr.write,
++ errOut;
++
++ err.actual = "a1";
++ err.expected = "e1";
++ err.showDiff = true;
++ var test = {
++ err: err,
++ fullTitle: function () {
++ return 'title';
++ }
++ };
++
++ process.stderr.write = function (string) {
++ stderr.push(string);
++ };
++
++ Base.list([test]);
++
++ process.stderr.write = stderrWrite;
++
++ errOut = stderr.join('\n');
++
++ errOut.should.match(/test/);
++ errOut.should.match(/actual/);
++ errOut.should.match(/expected/);
++
+ });
+
- it('does not show diffs when showDiff property set', function () {
- var err = new Error('test');
++ it('should not show diffs when showDiff property set', function () {
++ var err = new Error('test'),
++ stderr = [],
++ stderrWrite = process.stderr.write,
++ errOut;
++
+ err.actual = "a1";
+ err.expected = "e1";
+ err.showDiff = false;
+ var test = {
+ err: err,
- fullTitle: function() { return 'title'; }
++ fullTitle: function () {
++ return 'title';
++ }
++ };
++
++ process.stderr.write = function (string) {
++ stderr.push(string);
+ };
+
+ Base.list([test]);
+
- var errOut = output.error.map(function(lineArgs) {
- return util.format.apply(null, lineArgs);
- }).join('\n');
++ process.stderr.write = stderrWrite;
++
++ errOut = stderr.join('\n');
++
++ errOut.should.match(/test/);
++ errOut.should.not.match(/actual/);
++ errOut.should.not.match(/expected/);
+
- errOut.should.include('test');
- errOut.should.not.include('actual');
- errOut.should.not.include('expected');
+ });
+ });