@@ -42,6 +42,8 @@ const kReadableOperator = {
4242
4343const kMaxShortStringLength = 12 ;
4444const kMaxLongStringLength = 512 ;
45+ const kMaxDiffLineCount = 1000 ;
46+ const kMaxDiffLinesToShow = 50 ;
4547
4648const kMethodsWithCustomMessageDiff = new SafeSet ( )
4749 . add ( 'deepStrictEqual' )
@@ -182,6 +184,13 @@ function isSimpleDiff(actual, inspectedActual, expected, inspectedExpected) {
182184 return typeof actual !== 'object' || actual === null || typeof expected !== 'object' || expected === null ;
183185}
184186
187+ function getTruncatedDiffValue ( lines ) {
188+ if ( lines . length > kMaxDiffLinesToShow ) {
189+ return `${ ArrayPrototypeJoin ( ArrayPrototypeSlice ( lines , 0 , kMaxDiffLinesToShow ) , '\n' ) } \n...` ;
190+ }
191+ return ArrayPrototypeJoin ( lines , '\n' ) ;
192+ }
193+
185194function createErrDiff ( actual , expected , operator , customMessage , diffType = 'simple' ) {
186195 operator = checkOperator ( actual , expected , operator ) ;
187196
@@ -213,6 +222,13 @@ function createErrDiff(actual, expected, operator, customMessage, diffType = 'si
213222 message = ArrayPrototypeJoin ( inspectedSplitActual , '\n' ) ;
214223 }
215224 header = '' ;
225+ } else if (
226+ diffType !== 'full' &&
227+ inspectedSplitActual . length + inspectedSplitExpected . length > kMaxDiffLineCount
228+ ) {
229+ message = `\n${ colors . green } +${ colors . white } ${ getTruncatedDiffValue ( inspectedSplitActual ) } \n` +
230+ `${ colors . red } -${ colors . white } ${ getTruncatedDiffValue ( inspectedSplitExpected ) } ` ;
231+ skipped = true ;
216232 } else {
217233 const checkCommaDisparity = actual != null && typeof actual === 'object' ;
218234 const diff = myersDiff ( inspectedSplitActual , inspectedSplitExpected , checkCommaDisparity ) ;
0 commit comments