|
1 | | -// eslint-disable-next-line import/no-extraneous-dependencies |
2 | 1 | import '@testing-library/jest-dom'; |
3 | | - |
4 | | -// eslint-disable-next-line import/no-extraneous-dependencies |
5 | 2 | import { toHaveNoViolations } from 'jest-axe'; |
6 | | -// eslint-disable-next-line import/no-extraneous-dependencies |
7 | 3 | import fetchMock from 'jest-fetch-mock'; |
| 4 | +import { loadErrorMessages, loadDevMessages } from '@apollo/client/dev'; |
| 5 | + |
| 6 | +function ignoreConsoleWarnings() { |
| 7 | + // Store the original console.warn |
| 8 | + const originalWarn = console.warn; |
| 9 | + |
| 10 | + // A list of warning messages to completely ignore |
| 11 | + const warningsToIgnore = [ |
| 12 | + '[%s]: `%s` is deprecated and will be removed in Apollo Client 4.0. %s cache.diff canonizeResults Please remove this option.', |
| 13 | + ]; |
| 14 | + |
| 15 | + // Override console.warn |
| 16 | + console.warn = (...args) => { |
| 17 | + // Check if the warning message includes any of our ignored strings |
| 18 | + const shouldIgnore = warningsToIgnore.some((ignoredMsg) => |
| 19 | + args.join(' ').includes(ignoredMsg), |
| 20 | + ); |
| 21 | + |
| 22 | + // If it's one we want to ignore, do nothing (return early) |
| 23 | + if (shouldIgnore) { |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + // For all other warnings, call the original console.warn |
| 28 | + originalWarn.apply(console, args); |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +function ignoreConsoleErrors() { |
| 33 | + // Store the original console.error |
| 34 | + const originalError = console.error; |
| 35 | + |
| 36 | + // A list of error messages to completely ignore |
| 37 | + const errorsToIgnore = [ |
| 38 | + 'Error: Could not parse CSS stylesheet', // JSDOM cannot understand stylesheets generated by HDS-React. |
| 39 | + ]; |
| 40 | + |
| 41 | + // Override console.warn |
| 42 | + console.error = (...args) => { |
| 43 | + // Check if the error message includes any of our ignored strings |
| 44 | + const shouldIgnore = errorsToIgnore.some((ignoredMsg) => |
| 45 | + args.join(' ').includes(ignoredMsg), |
| 46 | + ); |
| 47 | + |
| 48 | + // If it's one we want to ignore, do nothing (return early) |
| 49 | + if (shouldIgnore) { |
| 50 | + return; |
| 51 | + } |
| 52 | + // For all other warnings, call the original console.warn |
| 53 | + originalError.apply(console, args); |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +ignoreConsoleWarnings(); |
| 58 | +ignoreConsoleErrors(); |
8 | 59 |
|
9 | 60 | fetchMock.enableMocks(); |
10 | 61 |
|
11 | 62 | // Extend except with jest-axe |
12 | 63 | expect.extend(toHaveNoViolations); |
| 64 | + |
| 65 | +if (process.env.NODE_ENV !== 'production') { |
| 66 | + // Adds messages only in a dev environment |
| 67 | + loadDevMessages(); |
| 68 | + loadErrorMessages(); |
| 69 | +} |
0 commit comments