Skip to content

Commit

Permalink
Respect err.showDiff, add Base reporter test (close mochajs#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Olson committed Nov 8, 2013
1 parent b43cb7f commit a5d7240
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ 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]) : '';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"glob": "3.2.3"
},
"devDependencies": {
"rewire": "2.0.0",
"should": ">= 2.0.x",
"coffee-script": "1.2"
},
Expand Down
42 changes: 42 additions & 0 deletions test/reporters/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var rewire = require('rewire'),
util = require('util');

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('does not show diffs when showDiff property set', function () {
var err = new Error('test');
err.actual = "a1";
err.expected = "e1";
err.showDiff = false;
var test = {
err: err,
fullTitle: function() { return 'title'; }
};

Base.list([test]);

var errOut = output.error.map(function(lineArgs) {
return util.format.apply(null, lineArgs);
}).join('\n');

errOut.should.include('test');
errOut.should.not.include('actual');
errOut.should.not.include('expected');
});
});

0 comments on commit a5d7240

Please sign in to comment.