From 557ce04080923e6bb3eb06d146cde089a2d97180 Mon Sep 17 00:00:00 2001 From: Phil Ricketts <812139+replete@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:15:52 +0100 Subject: [PATCH] Attempt #4 to fix GTM breaking CI tests --- jest.setup.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jest.setup.js b/jest.setup.js index 2ea0b53..8bd2629 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -51,16 +51,17 @@ beforeAll(async () => { headless: true }) - page.on('pageerror', (error) => { - if (error.toString && error.toString().includes('CookieDeprecationLabel')) return false // GTM bug: https://github.com/replete/biscuitman/issues/4 - console.error('Page error:', error) - }) - page.on('console', (msg) => { - let text = msg.text() + const text = msg.text() + const location = msg.location() if (msg.type() === 'error') { + // Squash 404 errors if (text.startsWith('Failed to load resource:')) return false - console.log('Console error:', msg.text()) + + // Raise errors if it originated from a locally-served resource + if (location && location.url && location.url.startsWith(global.__SERVERURL__)) { + console.error('Console error:', msg.text()) + } else return false } }) })