Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Respect err.showDiff, add Base reporter test (close #810)

Michael Olsona5d7240a83f9
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 370aba22..5b9993ab 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -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]) : '';
diff --git a/package.json b/package.json
index 11eb6ad0..84503764 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,7 @@
"glob": "3.2.3"
},
"devDependencies": {
+ "rewire": "2.0.0",
"should": ">= 2.0.x",
"coffee-script": "1.2"
},
diff --git a/test/reporters/base.js b/test/reporters/base.js
new file mode 100644
index 00000000..0854cbd2
--- /dev/null
+++ b/test/reporters/base.js
@@ -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');
+ });
+});