From 9b1c6e522b6b2724d74479eef73f57687c696cbf Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Thu, 11 May 2023 09:18:27 +0545 Subject: [PATCH] lesser evil --- test/helpers.js | 4 ++-- test/runtime-puppeteer/assert.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/helpers.js b/test/helpers.js index 1382af0691..f118a818f7 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -102,7 +102,7 @@ function cleanChildren(node) { }); // recurse - [...node.childNodes].forEach((child) => { + for (let child of node.childNodes) { if (child.nodeType === 3) { // text if ( @@ -130,7 +130,7 @@ function cleanChildren(node) { } previous = child; - }); + } // collapse whitespace if (node.firstChild && node.firstChild.nodeType === 3) { diff --git a/test/runtime-puppeteer/assert.js b/test/runtime-puppeteer/assert.js index e4d6f02f33..32e14b6830 100644 --- a/test/runtime-puppeteer/assert.js +++ b/test/runtime-puppeteer/assert.js @@ -43,8 +43,23 @@ function normalizeHtml(window, html) { .replace(//g, '') .replace(/>[\s\r\n]+<') .trim(); + + cleanStyle(node); + return node.innerHTML.replace(/<\/?noscript\/?>/g, ''); } catch (err) { throw new Error(`Failed to normalize HTML:\n${html}`); } } + +function cleanStyle(node) { + if (node.nodeType === 1) { + if (node.hasAttribute('style')) { + node.style = node.style.cssText; + } + + for (const child of node.childNodes) { + cleanStyle(child); + } + } +}