1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-18 01:18:23 +02:00

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.
This commit is contained in:
Thomas Heartman 2024-10-17 14:02:47 +02:00 committed by GitHub
parent d5ddbdd75f
commit bb22210e46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}
});
});