123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import { get } from 'lodash';
- import {
- clearLocalStorage,
- enablePageDialogAccept,
- setBrowserViewport,
- } from '@wordpress/e2e-test-utils';
- const { PUPPETEER_TIMEOUT } = process.env;
- const OBSERVED_CONSOLE_MESSAGE_TYPES = {
- warning: 'warn',
- error: 'error',
- };
- const pageEvents = [];
- jest.setTimeout( PUPPETEER_TIMEOUT || 100000 );
- function capturePageEventsForTearDown() {
- page.on( 'newListener', ( eventName, listener ) => {
- pageEvents.push( [ eventName, listener ] );
- } );
- }
- function removePageEvents() {
- pageEvents.forEach( ( [ eventName, handler ] ) => {
- page.removeListener( eventName, handler );
- } );
- }
- function observeConsoleLogging() {
- page.on( 'console', ( message ) => {
- const type = message.type();
- if ( ! OBSERVED_CONSOLE_MESSAGE_TYPES.hasOwnProperty( type ) ) {
- return;
- }
- let text = message.text();
-
-
- if ( text.includes( 'This is a global warning' ) ) {
- return;
- }
-
-
- if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) {
- return;
- }
-
-
-
-
-
-
- if (
- text.startsWith( 'Failed to decode downloaded font:' ) ||
- text.startsWith( 'OTS parsing error:' )
- ) {
- return;
- }
- const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ];
-
-
-
-
-
-
-
-
-
-
-
- text = get( message.args(), [ 0, '_remoteObject', 'description' ], text );
- // Disable reason: We intentionally bubble up the console message
- // which, unless the test explicitly anticipates the logging via
- // @wordpress/jest-console matchers, will cause the intended test
- // failure.
- // eslint-disable-next-line no-console
- console[ logFunction ]( text );
- } );
- }
- // Before every test suite run, delete all content created by the test. This ensures
- // other posts/comments/etc. aren't dirtying tests and tests don't depend on
- // each other's side-effects.
- beforeAll( async () => {
- capturePageEventsForTearDown();
- enablePageDialogAccept();
- observeConsoleLogging();
- await setBrowserViewport( 'large' );
- } );
- afterEach( async () => {
- await clearLocalStorage();
- await setBrowserViewport( 'large' );
- } );
- afterAll( () => {
- removePageEvents();
- } );
|