Skip to content

Commit

Permalink
Make sure all string diff output is red by default (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds authored and Vadim Demedes committed Feb 26, 2017
1 parent 3573896 commit 9f2ff09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/format-assert-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const indentString = require('indent-string');
const stripAnsi = require('strip-ansi');
const chalk = require('chalk');
const diff = require('diff');

Expand Down Expand Up @@ -45,7 +46,7 @@ module.exports = err => {
}

if (err.actualType === 'string' && err.expectedType === 'string') {
const patch = diff.diffChars(err.actual, err.expected);
const patch = diff.diffChars(stripAnsi(err.actual), stripAnsi(err.expected));
const msg = patch
.map(part => {
if (part.added) {
Expand All @@ -56,7 +57,7 @@ module.exports = err => {
return chalk.bgRed.black(part.value);
}

return part.value;
return chalk.red(part.value);
})
.join('');

Expand Down
2 changes: 1 addition & 1 deletion test/format-assert-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('diff strings', t => {

t.is(format(err), [
'Difference:\n',
`ab${chalk.bgRed.black('c')}${chalk.bgGreen.black('d')}\n`
`${chalk.red('ab')}${chalk.bgRed.black('c')}${chalk.bgGreen.black('d')}\n`
].join('\n'));
t.end();
});
Expand Down

0 comments on commit 9f2ff09

Please sign in to comment.