Skip to content

Base reporter, add unified diff separator #2295

Closed

Description

Right now the unified diff output has no separators. Resulting in output similar to this:

no-diff-seperator

Having not used mocha in some time, I had completely forgotten it splits before/after 4 lines from the affected text and spent a while trying to figure out how "PD" could possibly be having values of "15/30" or "50/100".

I don't know what kind of separator to add, but a blank line or two should suffice for majority of cases. I'd have to check to see if other libraries have tackled this problem how they went about it.

The code to modify would be this:

mocha/lib/reporters/base.js

Lines 161 to 207 in 7493bca

failures.forEach(function(test, i){
// format
var fmt = color('error title', ' %s) %s:\n')
+ color('error message', ' %s')
+ color('error stack', '\n%s\n');
// msg
var err = test.err
, message = err.message || ''
, stack = err.stack || message
, index = stack.indexOf(message)
, actual = err.actual
, expected = err.expected
, escape = true;
if (index === -1) {
msg = message;
} else {
index += message.length;
msg = stack.slice(0, index);
// remove msg from stack
stack = stack.slice(index + 1);
}
// uncaught
if (err.uncaught) {
msg = 'Uncaught ' + msg;
}
// explicitly show diff
if (err.showDiff !== false && sameType(actual, expected)
&& expected !== undefined) {
escape = false;
if (!(utils.isString(actual) && utils.isString(expected))) {
err.actual = actual = utils.stringify(actual);
err.expected = expected = utils.stringify(expected);
}
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
msg = '\n ' + color('error message', match ? match[1] : msg);
if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
} else {
msg += unifiedDiff(err, escape);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: usabilityconcerning user experience or interfacesemver-majorimplementation requires increase of "major" version number; "breaking changes"status: accepting prsMocha can use your help with this one!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions