From bb22210e46cf79e3ac7e03aff74cc588cdf152fb Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 17 Oct 2024 14:02:47 +0200 Subject: [PATCH] chore: silence remaining front end test warnings (#8465) This silences front end test warnings, errors, and logs that we don't care about. The reason we don't care is that: - we won't fix - it's test-specific, doesn't appear to happen in real life And it clogs the test logs. --- frontend/src/setupTests.ts | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/frontend/src/setupTests.ts b/frontend/src/setupTests.ts index 0018fca294f3..870c883bfdab 100644 --- a/frontend/src/setupTests.ts +++ b/frontend/src/setupTests.ts @@ -15,19 +15,40 @@ if (!window.ResizeObserver) { process.env.TZ = 'UTC'; +const errorsToIgnore = [ + 'Warning: An update to %s inside a test was not wrapped in act', + "Failed to create chart: can't acquire context from the given item", +]; + +const warningsToIgnore = [ + '[MSW] Found a redundant usage of query parameters in the request handler URL for', + 'MUI: You have provided an out-of-range value', +]; + +const logsToIgnore = ['An exception was caught and handled.']; + // ignore known React warnings const consoleError = console.error; +const consoleWarn = console.warn; +const consoleLog = console.log; beforeAll(() => { + const shouldIgnore = (messagesToIgnore: string[], args: any[]) => + typeof args[0] === 'string' && + messagesToIgnore.some((msg) => args[0].includes(msg)); + vi.spyOn(console, 'error').mockImplementation((...args) => { - if ( - !( - typeof args[0] === 'string' && - args[0].includes( - 'Warning: An update to %s inside a test was not wrapped in act', - ) - ) - ) { + if (!shouldIgnore(errorsToIgnore, args)) { consoleError(...args); } }); + vi.spyOn(console, 'warn').mockImplementation((...args) => { + if (!shouldIgnore(warningsToIgnore, args)) { + consoleWarn(...args); + } + }); + vi.spyOn(console, 'log').mockImplementation((...args) => { + if (!shouldIgnore(logsToIgnore, args)) { + consoleLog(...args); + } + }); });