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 2
2
const indentString = require ( 'indent-string' ) ;
3
3
const chalk = require ( 'chalk' ) ;
4
4
const diff = require ( 'diff' ) ;
5
+ const DiffMatchPatch = require ( 'diff-match-patch' ) ;
5
6
6
7
const cleanUp = line => {
7
8
if ( line [ 0 ] === '+' ) {
@@ -45,18 +46,19 @@ module.exports = err => {
45
46
}
46
47
47
48
if ( err . actualType === 'string' && err . expectedType === 'string' ) {
48
- const patch = diff . diffChars ( err . actual , err . expected ) ;
49
+ const diffMatchPatch = new DiffMatchPatch ( ) ;
50
+ const patch = diffMatchPatch . diff_main ( err . actual , err . expected ) ;
49
51
const msg = patch
50
52
. map ( part => {
51
- if ( part . added ) {
52
- return chalk . bgGreen . black ( part . value ) ;
53
+ if ( part [ 0 ] === 1 ) {
54
+ return chalk . bgGreen . black ( part [ 1 ] ) ;
53
55
}
54
56
55
- if ( part . removed ) {
56
- return chalk . bgRed . black ( part . value ) ;
57
+ if ( part [ 0 ] === - 1 ) {
58
+ return chalk . bgRed . black ( part [ 1 ] ) ;
57
59
}
58
60
59
- return part . value ;
61
+ return part [ 1 ] ;
60
62
} )
61
63
. join ( '' ) ;
62
64
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