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 f41d10d6710a2c45758fb389131239136dfed7c8 Mon Sep 17 00:00:00 2001 From: saloua chouihi Date: Wed, 9 Apr 2025 12:40:23 +0100 Subject: [PATCH 2/2] fix: correct panelSumary typo to panelSummary in Error component --- packages/ra-ui-materialui/src/layout/Error.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ra-ui-materialui/src/layout/Error.tsx b/packages/ra-ui-materialui/src/layout/Error.tsx index 216e55f8fe6..c14dbbd2f05 100644 --- a/packages/ra-ui-materialui/src/layout/Error.tsx +++ b/packages/ra-ui-materialui/src/layout/Error.tsx @@ -62,7 +62,7 @@ export const Error = ( } - className={ErrorClasses.panelSumary} + className={ErrorClasses.panelSummary} > {translate(error.message, { _: error.message, @@ -146,7 +146,7 @@ export const ErrorClasses = { title: `${PREFIX}-title`, icon: `${PREFIX}-icon`, panel: `${PREFIX}-panel`, - panelSumary: `${PREFIX}-panelSumary`, + panelSummary: `${PREFIX}-panelSummary`, panelDetails: `${PREFIX}-panelDetails`, toolbar: `${PREFIX}-toolbar`, advice: `${PREFIX}-advice`, @@ -182,7 +182,7 @@ const Root = styled('div', { maxWidth: '60em', }, - [`& .${ErrorClasses.panelSumary}`]: { + [`& .${ErrorClasses.panelSummary}`]: { userSelect: 'all', },