From 9a65c185d06725aaea5aa9ce38b649cdf504d038 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Thu, 27 Jul 2023 15:30:16 +0100 Subject: [PATCH] Updates to remainder of tests based on refined compact style mutations --- .../__snapshots__/integration.test.ts.snap | 14 ++------ .../cross-origin-iframes.test.ts.snap | 5 +-- packages/rrweb/test/utils.ts | 33 ++++++++++--------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/packages/rrweb/test/__snapshots__/integration.test.ts.snap b/packages/rrweb/test/__snapshots__/integration.test.ts.snap index ea8d39638d..773d2351b4 100644 --- a/packages/rrweb/test/__snapshots__/integration.test.ts.snap +++ b/packages/rrweb/test/__snapshots__/integration.test.ts.snap @@ -2933,24 +2933,14 @@ exports[`record integration tests can record node mutations 1`] = ` \\"id\\": 36, \\"attributes\\": { \\"id\\": \\"select2-drop\\", - \\"style\\": { - \\"left\\": \\"Npx\\", - \\"width\\": \\"Npx\\", - \\"top\\": \\"Npx\\", - \\"bottom\\": \\"auto\\", - \\"display\\": \\"block\\", - \\"position\\": false, - \\"visibility\\": false - }, + \\"style\\": \\"left: Npx; width: Npx; top: Npx; bottom: auto; display: block;\\", \\"class\\": \\"select2-drop select2-display-none select2-with-searchbox select2-drop-active\\" } }, { \\"id\\": 70, \\"attributes\\": { - \\"style\\": { - \\"display\\": false - } + \\"style\\": \\"\\" } }, { diff --git a/packages/rrweb/test/record/__snapshots__/cross-origin-iframes.test.ts.snap b/packages/rrweb/test/record/__snapshots__/cross-origin-iframes.test.ts.snap index 48d4bdb33a..5caabe69ee 100644 --- a/packages/rrweb/test/record/__snapshots__/cross-origin-iframes.test.ts.snap +++ b/packages/rrweb/test/record/__snapshots__/cross-origin-iframes.test.ts.snap @@ -2625,10 +2625,7 @@ exports[`cross origin iframes form.html should map scroll events correctly 1`] = { \\"id\\": 9, \\"attributes\\": { - \\"style\\": { - \\"width\\": \\"Npx\\", - \\"height\\": \\"Npx\\" - } + \\"style\\": \\"width: Npx; height: Npx;\\" } } ], diff --git a/packages/rrweb/test/utils.ts b/packages/rrweb/test/utils.ts index dd5a8cf7cc..0d1e6400c6 100644 --- a/packages/rrweb/test/utils.ts +++ b/packages/rrweb/test/utils.ts @@ -133,23 +133,26 @@ function stringifySnapshots(snapshots: eventWithTime[]): string { s.data.source === IncrementalSource.Mutation ) { s.data.attributes.forEach((a) => { - if ( - 'style' in a.attributes && - a.attributes.style && - typeof a.attributes.style === 'object' - ) { - for (const [k, v] of Object.entries(a.attributes.style)) { - if (Array.isArray(v)) { - if (coordinatesReg.test(k + ': ' + v[0])) { - // TODO: could round the number here instead depending on what's coming out of various test envs - a.attributes.style[k] = ['Npx', v[1]]; - } - } else if (typeof v === 'string') { - if (coordinatesReg.test(k + ': ' + v)) { - a.attributes.style[k] = 'Npx'; + if ('style' in a.attributes && a.attributes.style) { + if (typeof a.attributes.style === 'object') { + for (const [k, v] of Object.entries(a.attributes.style)) { + if (Array.isArray(v)) { + if (coordinatesReg.test(k + ': ' + v[0])) { + // TODO: could round the number here instead depending on what's coming out of various test envs + a.attributes.style[k] = ['Npx', v[1]]; + } + } else if (typeof v === 'string') { + if (coordinatesReg.test(k + ': ' + v)) { + a.attributes.style[k] = 'Npx'; + } } + coordinatesReg.lastIndex = 0; // wow, a real wart in ECMAScript } - coordinatesReg.lastIndex = 0; // wow, a real wart in ECMAScript + } else if (coordinatesReg.test(a.attributes.style)) { + a.attributes.style = a.attributes.style.replace( + coordinatesReg, + '$1: Npx', + ); } }