From b4015b637005f70cc9d852b87a350911e5569ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Mon, 27 Feb 2023 23:32:27 +0800 Subject: [PATCH] chore: test clean up log (#40955) --- tests/setup.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/setup.js b/tests/setup.js index afd91cdbfe..25f9bf9901 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -4,6 +4,21 @@ const util = require('util'); // eslint-disable-next-line no-console console.log('Current React Version:', React.version); +const originConsoleErr = console.error; + +// Hack off React warning to avoid too large log in CI. +console.error = (...args) => { + const str = args.join('').replace(/\n/g, ''); + + if ( + ['validateDOMNesting', 'on an unmounted component', 'not wrapped in act'].every( + (warn) => !str.includes(warn), + ) + ) { + originConsoleErr(...args); + } +}; + /* eslint-disable global-require */ if (typeof window !== 'undefined') { global.window.resizeTo = (width, height) => { @@ -17,7 +32,7 @@ if (typeof window !== 'undefined') { Object.defineProperty(global.window, 'matchMedia', { writable: true, configurable: true, - value: jest.fn(query => ({ + value: jest.fn((query) => ({ matches: query.includes('max-width'), addListener: jest.fn(), removeListener: jest.fn(),