@@ -57,7 +57,7 @@ const FORMAT_OPTIONS = {
57
57
}
58
58
const FALLBACK_FORMAT_OPTIONS = {
59
59
callToJSON : false ,
60
- maxDepth : 10 ,
60
+ maxDepth : 8 ,
61
61
plugins : PLUGINS ,
62
62
}
63
63
@@ -97,8 +97,18 @@ export function diff(a: any, b: any, options?: DiffOptions): string | undefined
97
97
const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator }
98
98
= normalizeDiffOptions ( options )
99
99
const formatOptions = getFormatOptions ( FALLBACK_FORMAT_OPTIONS , options )
100
- const aDisplay = prettyFormat ( a , formatOptions )
101
- const bDisplay = prettyFormat ( b , formatOptions )
100
+ let aDisplay = prettyFormat ( a , formatOptions )
101
+ let bDisplay = prettyFormat ( b , formatOptions )
102
+ // even if prettyFormat prints successfully big objects,
103
+ // large string can choke later on (concatenation? RPC?),
104
+ // so truncate it to a reasonable length here.
105
+ // (For example, playwright's ElementHandle can become about 200_000_000 length string)
106
+ const MAX_LENGTH = 100_000
107
+ function truncate ( s : string ) {
108
+ return s . length <= MAX_LENGTH ? s : ( `${ s . slice ( 0 , MAX_LENGTH ) } ...` )
109
+ }
110
+ aDisplay = truncate ( aDisplay )
111
+ bDisplay = truncate ( bDisplay )
102
112
const aDiff = `${ aColor ( `${ aIndicator } ${ aAnnotation } :` ) } \n${ aDisplay } `
103
113
const bDiff = `${ bColor ( `${ bIndicator } ${ bAnnotation } :` ) } \n${ bDisplay } `
104
114
return `${ aDiff } \n\n${ bDiff } `
0 commit comments