Skip to content

Commit 9f2ff09

Browse files
lukechildsVadim Demedes
authored andcommitted
Make sure all string diff output is red by default (#1287)
1 parent 3573896 commit 9f2ff09

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/format-assert-error.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const indentString = require('indent-string');
3+
const stripAnsi = require('strip-ansi');
34
const chalk = require('chalk');
45
const diff = require('diff');
56

@@ -45,7 +46,7 @@ module.exports = err => {
4546
}
4647

4748
if (err.actualType === 'string' && err.expectedType === 'string') {
48-
const patch = diff.diffChars(err.actual, err.expected);
49+
const patch = diff.diffChars(stripAnsi(err.actual), stripAnsi(err.expected));
4950
const msg = patch
5051
.map(part => {
5152
if (part.added) {
@@ -56,7 +57,7 @@ module.exports = err => {
5657
return chalk.bgRed.black(part.value);
5758
}
5859

59-
return part.value;
60+
return chalk.red(part.value);
6061
})
6162
.join('');
6263

test/format-assert-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test('diff strings', t => {
7272

7373
t.is(format(err), [
7474
'Difference:\n',
75-
`ab${chalk.bgRed.black('c')}${chalk.bgGreen.black('d')}\n`
75+
`${chalk.red('ab')}${chalk.bgRed.black('c')}${chalk.bgGreen.black('d')}\n`
7676
].join('\n'));
7777
t.end();
7878
});

0 commit comments

Comments
 (0)