File tree 2 files changed +9
-6
lines changed
2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const indentString = require('indent-string');
3
3
const stripAnsi = require ( 'strip-ansi' ) ;
4
4
const chalk = require ( 'chalk' ) ;
5
5
const diff = require ( 'diff' ) ;
6
+ const DiffMatchPatch = require ( 'diff-match-patch' ) ;
6
7
7
8
const cleanUp = line => {
8
9
if ( line [ 0 ] === '+' ) {
@@ -46,18 +47,19 @@ module.exports = err => {
46
47
}
47
48
48
49
if ( err . actualType === 'string' && err . expectedType === 'string' ) {
49
- const patch = diff . diffChars ( stripAnsi ( err . actual ) , stripAnsi ( err . expected ) ) ;
50
+ const diffMatchPatch = new DiffMatchPatch ( ) ;
51
+ const patch = diffMatchPatch . diff_main ( stripAnsi ( err . actual ) , stripAnsi ( err . expected ) ) ;
50
52
const msg = patch
51
53
. map ( part => {
52
- if ( part . added ) {
53
- return chalk . bgGreen . black ( part . value ) ;
54
+ if ( part [ 0 ] === 1 ) {
55
+ return chalk . bgGreen . black ( part [ 1 ] ) ;
54
56
}
55
57
56
- if ( part . removed ) {
57
- return chalk . bgRed . black ( part . value ) ;
58
+ if ( part [ 0 ] === - 1 ) {
59
+ return chalk . bgRed . black ( part [ 1 ] ) ;
58
60
}
59
61
60
- return chalk . red ( part . value ) ;
62
+ return chalk . red ( part [ 1 ] ) ;
61
63
} )
62
64
. join ( '' ) ;
63
65
Original file line number Diff line number Diff line change 115
115
"currently-unhandled" : " ^0.4.1" ,
116
116
"debug" : " ^2.2.0" ,
117
117
"diff" : " ^3.0.1" ,
118
+ "diff-match-patch" : " ^1.0.0" ,
118
119
"dot-prop" : " ^4.1.0" ,
119
120
"empower-core" : " ^0.6.1" ,
120
121
"equal-length" : " ^1.0.0" ,
You can’t perform that action at this time.
0 commit comments