@@ -122,7 +122,7 @@ function createErrDiff(actual, expected, operator) {
122122 let a = actualLines [ actualLines . length - 1 ] ;
123123 let b = expectedLines [ expectedLines . length - 1 ] ;
124124 while ( a === b ) {
125- if ( i ++ < 2 ) {
125+ if ( i ++ < 3 ) {
126126 end = `\n ${ a } ${ end } ` ;
127127 } else {
128128 other = a ;
@@ -154,7 +154,9 @@ function createErrDiff(actual, expected, operator) {
154154 return `${ kReadableOperator . notIdentical } \n\n${ actualLines . join ( '\n' ) } \n` ;
155155 }
156156
157- if ( i > 3 ) {
157+ // There were at least five identical lines at the end. Mark a couple of
158+ // skipped.
159+ if ( i >= 5 ) {
158160 end = `\n${ blue } ...${ white } ${ end } ` ;
159161 skipped = true ;
160162 }
@@ -169,46 +171,46 @@ function createErrDiff(actual, expected, operator) {
169171 `\n${ green } + actual${ white } ${ red } - expected${ white } ` ;
170172 const skippedMsg = ` ${ blue } ...${ white } Lines skipped` ;
171173
174+ let lines = actualLines ;
175+ let plusMinus = `${ green } +${ white } ` ;
176+ let maxLength = expectedLines . length ;
177+ if ( actualLines . length < maxLines ) {
178+ lines = expectedLines ;
179+ plusMinus = `${ red } -${ white } ` ;
180+ maxLength = actualLines . length ;
181+ }
182+
172183 for ( i = 0 ; i < maxLines ; i ++ ) {
173- if ( actualLines . length < i + 1 ) {
174- // If more than one former line is identical, print that . Collapse those
175- // in case more than three lines before were identical.
176- if ( identical > 1 ) {
184+ if ( maxLength < i + 1 ) {
185+ // If more than two former lines are identical, print them . Collapse them
186+ // in case more than five lines were identical.
187+ if ( identical > 2 ) {
177188 if ( identical > 3 ) {
178- res += `\n${ blue } ...${ white } ` ;
179- skipped = true ;
180- } else if ( identical > 2 ) {
181- res += `\n ${ expectedLines [ i - 2 ] } ` ;
189+ if ( identical > 4 ) {
190+ if ( identical === 5 ) {
191+ res += `\n ${ lines [ i - 3 ] } ` ;
192+ printedLines ++ ;
193+ } else {
194+ res += `\n${ blue } ...${ white } ` ;
195+ skipped = true ;
196+ }
197+ }
198+ res += `\n ${ lines [ i - 2 ] } ` ;
182199 printedLines ++ ;
183200 }
184- res += `\n ${ expectedLines [ i - 1 ] } ` ;
201+ res += `\n ${ lines [ i - 1 ] } ` ;
185202 printedLines ++ ;
186203 }
187204 // No identical lines before.
188205 identical = 0 ;
189206 // Add the expected line to the cache.
190- other += `\n${ red } -${ white } ${ expectedLines [ i ] } ` ;
191- printedLines ++ ;
192- // Only extra actual lines exist
193- } else if ( expectedLines . length < i + 1 ) {
194- // If more than one former line is identical, print that. Collapse those
195- // in case more than three lines before were identical.
196- if ( identical > 1 ) {
197- if ( identical > 3 ) {
198- res += `\n${ blue } ...${ white } ` ;
199- skipped = true ;
200- } else if ( identical > 2 ) {
201- res += `\n ${ actualLines [ i - 2 ] } ` ;
202- printedLines ++ ;
203- }
204- res += `\n ${ actualLines [ i - 1 ] } ` ;
205- printedLines ++ ;
207+ if ( lines === actualLines ) {
208+ res += `\n${ plusMinus } ${ lines [ i ] } ` ;
209+ } else {
210+ other += `\n${ plusMinus } ${ lines [ i ] } ` ;
206211 }
207- // No identical lines before.
208- identical = 0 ;
209- // Add the actual line to the result.
210- res += `\n${ green } +${ white } ${ actualLines [ i ] } ` ;
211212 printedLines ++ ;
213+ // Only extra actual lines exist
212214 // Lines diverge
213215 } else {
214216 const expectedLine = expectedLines [ i ] ;
@@ -235,13 +237,19 @@ function createErrDiff(actual, expected, operator) {
235237 actualLine += ',' ;
236238 }
237239 if ( divergingLines ) {
238- // If more than one former line is identical, print that . Collapse those
239- // in case more than three lines before were identical.
240- if ( identical > 1 ) {
240+ // If more than two former lines are identical, print them . Collapse
241+ // them in case more than five lines were identical.
242+ if ( identical > 2 ) {
241243 if ( identical > 3 ) {
242- res += `\n${ blue } ...${ white } ` ;
243- skipped = true ;
244- } else if ( identical > 2 ) {
244+ if ( identical > 4 ) {
245+ if ( identical === 5 ) {
246+ res += `\n ${ actualLines [ i - 3 ] } ` ;
247+ printedLines ++ ;
248+ } else {
249+ res += `\n${ blue } ...${ white } ` ;
250+ skipped = true ;
251+ }
252+ }
245253 res += `\n ${ actualLines [ i - 2 ] } ` ;
246254 printedLines ++ ;
247255 }
@@ -264,7 +272,7 @@ function createErrDiff(actual, expected, operator) {
264272 identical ++ ;
265273 // The very first identical line since the last diverging line is be
266274 // added to the result.
267- if ( identical === 1 ) {
275+ if ( identical <= 2 ) {
268276 res += `\n ${ actualLine } ` ;
269277 printedLines ++ ;
270278 }
0 commit comments