From 13a18b58f86e243790fa0bb3ef5826a43117785c Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 20 Jan 2021 12:59:53 +0000 Subject: [PATCH] Don't remove the style attributes altogether from tests; they are an important part of the mutations These were removed in https://github.com/rrweb-io/rrweb/commit/8ed1c999cff657c84cdcb88a14ff977c573485a6 in order to smooth over differences in test environments so have maintained that by converting pixel values to 'Npx' (could also try rounding, but didn't attempt that) --- test/__snapshots__/integration.test.ts.snap | 7 +++++-- test/utils.ts | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/__snapshots__/integration.test.ts.snap b/test/__snapshots__/integration.test.ts.snap index 19f34fb608..ab6098d2cb 100644 --- a/test/__snapshots__/integration.test.ts.snap +++ b/test/__snapshots__/integration.test.ts.snap @@ -5573,6 +5573,7 @@ exports[`select2 1`] = ` \\"id\\": 36, \\"attributes\\": { \\"id\\": \\"select2-drop\\", + \\"style\\": \\"left: Npx; width: Npx; top: Npx; bottom: auto; display: block;\\", \\"class\\": \\"select2-drop select2-display-none select2-with-searchbox select2-drop-active\\" } }, @@ -5721,7 +5722,8 @@ exports[`select2 1`] = ` \\"tagName\\": \\"div\\", \\"attributes\\": { \\"class\\": \\"select2-drop select2-display-none select2-with-searchbox select2-drop-active\\", - \\"id\\": \\"select2-drop\\" + \\"id\\": \\"select2-drop\\", + \\"style\\": \\"left: Npx; width: Npx; top: Npx; bottom: auto; display: block;\\" }, \\"childNodes\\": [], \\"id\\": 36 @@ -6033,7 +6035,8 @@ exports[`select2 1`] = ` { \\"id\\": 36, \\"attributes\\": { - \\"id\\": null + \\"id\\": null, + \\"style\\": \\"left: Npx; width: Npx; top: Npx; bottom: auto; display: none;\\" } }, { diff --git a/test/utils.ts b/test/utils.ts index 0776b963fb..3b21e30f23 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -61,7 +61,7 @@ function stringifySnapshots(snapshots: eventWithTime[]): string { s.data.href = 'about:blank'; } // FIXME: travis coordinates seems different with my laptop - const coordinatesReg = /(bottom|top|left|right)/; + const coordinatesReg = /(bottom|top|left|right|width|height): \d+(\.\d+)?px/g if ( s.type === EventType.IncrementalSnapshot && s.data.source === IncrementalSource.MouseInteraction @@ -78,7 +78,7 @@ function stringifySnapshots(snapshots: eventWithTime[]): string { 'style' in a.attributes && coordinatesReg.test(a.attributes.style!) ) { - delete a.attributes.style; + a.attributes.style = a.attributes.style!.replace(coordinatesReg, '$1: Npx'); } }); s.data.adds.forEach((add) => { @@ -88,7 +88,7 @@ function stringifySnapshots(snapshots: eventWithTime[]): string { typeof add.node.attributes.style === 'string' && coordinatesReg.test(add.node.attributes.style) ) { - delete add.node.attributes.style; + add.node.attributes.style = add.node.attributes.style.replace(coordinatesReg, '$1: Npx'); } }); }