From 9b78cb6d9ac1300a6e9bc9f2736f3b3d2d4618a4 Mon Sep 17 00:00:00 2001 From: saloua chouihi Date: Wed, 9 Apr 2025 12:11:21 +0100 Subject: [PATCH 1/2] fix: implement proper ResizeObserver mock for Cypress tests --- cypress/e2e/support/resize-observer-mock.js | 26 +++++++++++++++++ cypress/support/index.js | 32 +++++++++++++-------- 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 cypress/e2e/support/resize-observer-mock.js diff --git a/cypress/e2e/support/resize-observer-mock.js b/cypress/e2e/support/resize-observer-mock.js new file mode 100644 index 00000000000..7c22e3496fa --- /dev/null +++ b/cypress/e2e/support/resize-observer-mock.js @@ -0,0 +1,26 @@ +// Mock ResizeObserver to prevent "ResizeObserver loop completed with undelivered notifications" errors +class ResizeObserverMock { + constructor(callback) { + this.callback = callback; + this.observations = new Map(); + } + + observe(element) { + this.observations.set(element, {}); + // Trigger initial callback + this.callback([{ target: element }], this); + } + + unobserve(element) { + this.observations.delete(element); + } + + disconnect() { + this.observations.clear(); + } +} + +// Replace the global ResizeObserver with our mock +if (window.ResizeObserver) { + window.ResizeObserver = ResizeObserverMock; +} diff --git a/cypress/support/index.js b/cypress/support/index.js index 3615f85fc5a..b9d1e77946a 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -1,16 +1,24 @@ import 'cypress-plugin-tab'; +import '../e2e/support/resize-observer-mock'; -/* - * This is a workaround for the ResizeObserver loop error that occurs in Cypress. - * See https://github.com/cypress-io/cypress/issues/20341 - * See https://github.com/cypress-io/cypress/issues/29277 - */ -Cypress.on('uncaught:exception', err => { - if ( - err.message.includes( - 'ResizeObserver loop completed with undelivered notifications' - ) - ) { - return false; +// Make the CI fail if console.error in tests +const originalConsoleError = console.error; +console.error = (...args) => { + originalConsoleError.call(console, args); + throw new Error( + JSON.stringify({ + message: 'The tests failed due to `console.error` calls', + error: args, + }) + ); +}; + +// Ignore warnings about act() +// See https://github.com/testing-library/react-testing-library/issues/281, +// https://github.com/facebook/react/issues/14769 +jest.spyOn(console, 'error').mockImplementation((...args) => { + if (/Warning.*not wrapped in act/.test(args[0])) { + return; } + originalConsoleError.call(console, ...args); }); From 95713169355b5b69984152e10c049fa23fd674a4 Mon Sep 17 00:00:00 2001 From: Gildas <1122076+djhi@users.noreply.github.com> Date: Fri, 16 May 2025 10:01:25 +0200 Subject: [PATCH 2/2] Fix lint --- cypress/support/index.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cypress/support/index.js b/cypress/support/index.js index b9d1e77946a..40c81a6c062 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -12,13 +12,3 @@ console.error = (...args) => { }) ); }; - -// Ignore warnings about act() -// See https://github.com/testing-library/react-testing-library/issues/281, -// https://github.com/facebook/react/issues/14769 -jest.spyOn(console, 'error').mockImplementation((...args) => { - if (/Warning.*not wrapped in act/.test(args[0])) { - return; - } - originalConsoleError.call(console, ...args); -});