@@ -47,6 +47,7 @@ const kMaxLongStringLength = 512;
4747// Objects with many converging paths can produce exponential growth in
4848// util.inspect output at high depths, leading to OOM during diff generation.
4949const kMaxInspectOutputLength = 2 * 1024 * 1024 ; // 2MB
50+ const kTruncatedByteMarker = '\n... [truncated]' ;
5051
5152const kMethodsWithCustomMessageDiff = new SafeSet ( )
5253 . add ( 'deepStrictEqual' )
@@ -74,7 +75,7 @@ function copyError(source) {
7475 return target ;
7576}
7677
77- function inspectValue ( val , maxLength = kMaxInspectOutputLength ) {
78+ function inspectValue ( val ) {
7879 // The util.inspect default values could be changed. This makes sure the
7980 // error messages contain the necessary information nevertheless.
8081 const result = inspect ( val , {
@@ -95,8 +96,9 @@ function inspectValue(val, maxLength = kMaxInspectOutputLength) {
9596 // Objects with deeply nested structures can produce exponentially large
9697 // inspect output that causes memory exhaustion when passed to the diff
9798 // algorithm.
98- if ( result . length > maxLength ) {
99- return StringPrototypeSlice ( result , 0 , maxLength ) + '\n... [truncated]' ;
99+ if ( result . length > kMaxInspectOutputLength ) {
100+ return StringPrototypeSlice ( result , 0 , kMaxInspectOutputLength ) +
101+ kTruncatedByteMarker ;
100102 }
101103 return result ;
102104}
@@ -205,9 +207,8 @@ function createErrDiff(actual, expected, operator, customMessage, diffType = 'si
205207 const inspectedExpected = inspectValue ( expected ) ;
206208
207209 // Check if either value was truncated due to size limits
208- const truncationMarker = '\n... [truncated]' ;
209- if ( StringPrototypeEndsWith ( inspectedActual , truncationMarker ) ||
210- StringPrototypeEndsWith ( inspectedExpected , truncationMarker ) ) {
210+ if ( StringPrototypeEndsWith ( inspectedActual , kTruncatedByteMarker ) ||
211+ StringPrototypeEndsWith ( inspectedExpected , kTruncatedByteMarker ) ) {
211212 skipped = true ;
212213 }
213214 const inspectedSplitActual = StringPrototypeSplit ( inspectedActual , '\n' ) ;
0 commit comments