From f48ca7cade85a572a55f325ce6673deb0aede38e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 26 Jan 2021 11:42:51 -0400 Subject: [PATCH] eliminate repeated missing resource messages in E2E --- tests/e2e/env/src/setup/jest.setup.js | 36 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/e2e/env/src/setup/jest.setup.js b/tests/e2e/env/src/setup/jest.setup.js index 57e42ee0252..a312c46635e 100644 --- a/tests/e2e/env/src/setup/jest.setup.js +++ b/tests/e2e/env/src/setup/jest.setup.js @@ -18,6 +18,21 @@ import { * @type {Array} */ const pageEvents = []; +/** + * Set of logged messages that will only be logged once. + * + * @type {Object} + */ +const loggedMessages = { + proxy: { + logged: false, + text: 'Failed to load resource: net::ERR_PROXY_CONNECTION_FAILED', + }, + http404: { + logged: false, + text: 'the server responded with a status of 404', + }, +}; /** * Set of console logging types observed to protect against unexpected yet * handled (i.e. not catastrophic) errors or warnings. Each key corresponds @@ -140,16 +155,21 @@ function observeConsoleLogging() { return; } - // As of WordPress 5.3.2 in Chrome 79, navigating to the block editor - // (Posts > Add New) will display a console warning about - // non - unique IDs. - // See: https://core.trac.wordpress.org/ticket/23165 - if ( text.includes( 'elements with non-unique id #_wpnonce' ) ) { - return; - } - const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ]; + // Limit warnings on missing resources. + let previouslyLogged = false; + Object.keys( loggedMessages ).forEach( function( key ) { + if ( text.includes( loggedMessages[ key ].text ) ) { + if ( loggedMessages[ key ].logged ) { + previouslyLogged = true; + } + loggedMessages[ key ].logged = true; + } + } ); + if ( previouslyLogged ) { + return; + } // As of Puppeteer 1.6.1, `message.text()` wrongly returns an object of // type JSHandle for error logging, instead of the expected string. //