Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use background color to show colored spaces in an inline diff #4287

Merged
merged 7 commits into from Jun 22, 2020
22 changes: 15 additions & 7 deletions lib/reporters/base.js
Expand Up @@ -69,7 +69,9 @@ exports.colors = {
light: 90,
'diff gutter': 90,
'diff added': 32,
'diff removed': 31
'diff removed': 31,
'diff added inline': '30;42',
'diff removed inline': '30;41'
};

/**
Expand Down Expand Up @@ -189,9 +191,15 @@ var generateDiff = (exports.generateDiff = function(actual, expected) {
} catch (err) {
var msg =
'\n ' +
color('diff added', '+ expected') +
color(
juergba marked this conversation as resolved.
Show resolved Hide resolved
'diff added' + (exports.inlineDiffs ? ' inline' : ''),
'+ expected'
) +
' ' +
color('diff removed', '- actual: failed to generate Mocha diff') +
color(
'diff removed' + (exports.inlineDiffs ? ' inline' : ''),
'- actual: failed to generate Mocha diff'
) +
'\n';
return msg;
}
Expand Down Expand Up @@ -406,9 +414,9 @@ function inlineDiff(actual, expected) {
// legend
msg =
'\n' +
color('diff removed', 'actual') +
color('diff removed inline', 'actual') +
' ' +
color('diff added', 'expected') +
color('diff added inline', 'expected') +
'\n\n' +
msg +
'\n';
Expand Down Expand Up @@ -474,10 +482,10 @@ function errorDiff(actual, expected) {
.diffWordsWithSpace(actual, expected)
.map(function(str) {
if (str.added) {
return colorLines('diff added', str.value);
return colorLines('diff added inline', str.value);
}
if (str.removed) {
return colorLines('diff removed', str.value);
return colorLines('diff removed inline', str.value);
}
return str.value;
})
Expand Down