Skip to content

Commit

Permalink
Revert whitespace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Oct 19, 2021
1 parent 2faaeba commit 42221d3
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions tests/e2e/config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,52 @@ const OBSERVED_CONSOLE_MESSAGE_TYPES = {
const pageEvents = [];

// The Jest timeout is increased because these tests are a bit slow
jest.setTimeout(PUPPETEER_TIMEOUT || 100000);
jest.setTimeout( PUPPETEER_TIMEOUT || 100000 );

const toMatchImageSnapshot = configureToMatchImageSnapshot({
const toMatchImageSnapshot = configureToMatchImageSnapshot( {
dumpDiffToConsole: true,
failureThresholdType: 'percent',
failureThreshold: 3,
});
} );

// Extend Jest's "expect" with image snapshot functionality.
expect.extend({ toMatchImageSnapshot });
expect.extend( { toMatchImageSnapshot } );

/**
* Adds an event listener to the page to handle additions of page event
* handlers, to assure that they are removed at test teardown.
*/
function capturePageEventsForTearDown() {
page.on('newListener', (eventName, listener) => {
pageEvents.push([eventName, listener]);
});
page.on( 'newListener', ( eventName, listener ) => {
pageEvents.push( [ eventName, listener ] );
} );
}

/**
* Removes all bound page event handlers.
*/
function removePageEvents() {
pageEvents.forEach(([eventName, handler]) => {
page.removeListener(eventName, handler);
});
pageEvents.forEach( ( [ eventName, handler ] ) => {
page.removeListener( eventName, handler );
} );
}

/**
* Adds a page event handler to emit uncaught exception to process if one of
* the observed console logging types is encountered.
*/
function observeConsoleLogging() {
page.on('console', (message) => {
page.on( 'console', ( message ) => {
const type = message.type();
if (!OBSERVED_CONSOLE_MESSAGE_TYPES.hasOwnProperty(type)) {
if ( ! OBSERVED_CONSOLE_MESSAGE_TYPES.hasOwnProperty( type ) ) {
return;
}

let text = message.text();

// An exception is made for _blanket_ deprecation warnings: Those
// which log regardless of whether a deprecated feature is in use.
if (text.includes('This is a global warning')) {
if ( text.includes( 'This is a global warning' ) ) {
return;
}

Expand All @@ -90,7 +90,7 @@ function observeConsoleLogging() {

// Viewing posts on the front end can result in this error, which
// has nothing to do with Gutenberg.
if (text.includes('net::ERR_UNKNOWN_URL_SCHEME')) {
if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) {
return;
}

Expand All @@ -101,13 +101,13 @@ function observeConsoleLogging() {
//
// See: https://core.trac.wordpress.org/ticket/47183
if (
text.startsWith('Failed to decode downloaded font:') ||
text.startsWith('OTS parsing error:')
text.startsWith( 'Failed to decode downloaded font:' ) ||
text.startsWith( 'OTS parsing error:' )
) {
return;
}

const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[type];
const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ];

// As of Puppeteer 1.6.1, `message.text()` wrongly returns an object of
// type JSHandle for error logging, instead of the expected string.
Expand All @@ -120,33 +120,37 @@ function observeConsoleLogging() {
// correctly. Instead, the logic here synchronously inspects the
// internal object shape of the JSHandle to find the error text. If it
// cannot be found, the default text value is used instead.
text = get(message.args(), [0, '_remoteObject', 'description'], text);
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);
});
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 () => {
beforeAll( async () => {
capturePageEventsForTearDown();
enablePageDialogAccept();
observeConsoleLogging();
await setBrowserViewport('large');
});
await setBrowserViewport( 'large' );
} );

afterEach(async () => {
afterEach( async () => {
await clearLocalStorage();
await setBrowserViewport('large');
});
await setBrowserViewport( 'large' );
} );

afterAll(() => {
afterAll( () => {
removePageEvents();
});
} );

0 comments on commit 42221d3

Please sign in to comment.