@@ -133,7 +133,7 @@ export function getFullRecordingSnapshots(replayRequest: Request): RecordingSnap
133133 return events . filter ( event => event . type === 2 ) . map ( event => event . data as RecordingSnapshot ) ;
134134}
135135
136- function getincrementalRecordingSnapshots ( replayRequest : Request ) : RecordingSnapshot [ ] {
136+ function getIncrementalRecordingSnapshots ( replayRequest : Request ) : RecordingSnapshot [ ] {
137137 const events = getDecompressedRecordingEvents ( replayRequest ) as RecordingEvent [ ] ;
138138 return events . filter ( event => event . type === 3 ) . map ( event => event . data as RecordingSnapshot ) ;
139139}
@@ -144,7 +144,7 @@ function getDecompressedRecordingEvents(replayRequest: Request): RecordingEvent[
144144
145145export function getReplayRecordingContent ( replayRequest : Request ) : RecordingContent {
146146 const fullSnapshots = getFullRecordingSnapshots ( replayRequest ) ;
147- const incrementalSnapshots = getincrementalRecordingSnapshots ( replayRequest ) ;
147+ const incrementalSnapshots = getIncrementalRecordingSnapshots ( replayRequest ) ;
148148 const customEvents = getCustomRecordingEvents ( replayRequest ) ;
149149
150150 return { fullSnapshots, incrementalSnapshots, ...customEvents } ;
@@ -216,10 +216,29 @@ export function shouldSkipReplayTest(): boolean {
216216 * files which break the tests on different machines.
217217 * Also, we need to normalize any time offsets as they can vary and cause flakes.
218218 */
219- export function normalize ( obj : unknown ) : string {
219+ export function normalize (
220+ obj : unknown ,
221+ { normalizeNumberAttributes } : { normalizeNumberAttributes ?: string [ ] } = { } ,
222+ ) : string {
220223 const rawString = JSON . stringify ( obj , null , 2 ) ;
221- const normalizedString = rawString
224+ let normalizedString = rawString
222225 . replace ( / " f i l e : \/ \/ .+ ( \/ .* \. h t m l ) " / gm, '"$1"' )
223226 . replace ( / " t i m e O f f s e t " : \s * - ? \d + / gm, '"timeOffset": [timeOffset]' ) ;
227+
228+ if ( normalizeNumberAttributes ?. length ) {
229+ // We look for: "attr": "123px", "123", "123%", "123em", "123rem"
230+ const regex = new RegExp (
231+ `"(${ normalizeNumberAttributes
232+ . map ( attr => `(?:${ attr } )` )
233+ . join ( '|' ) } )":\\s*"([\\d\\.]+)((?:px)|%|(?:em)(?:rem))?"`,
234+ 'gm' ,
235+ ) ;
236+
237+ normalizedString = normalizedString . replace ( regex , ( _ , attr , num , unit ) => {
238+ // Remove floating points here, to ensure this is a bit less flaky
239+ return `"${ attr } ": "${ parseInt ( num , 10 ) } ${ unit || '' } "` ;
240+ } ) ;
241+ }
242+
224243 return normalizedString ;
225244}
0 commit comments