Skip to content

Commit

Permalink
Update the test setup code, and remove the a11xy tests like Gutenberg…
Browse files Browse the repository at this point in the history
… did
  • Loading branch information
ingeniumed committed May 24, 2024
1 parent eb3540c commit 95a39c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ vendor

# Test files
.phpunit.result.cache
artifacts/
67 changes: 22 additions & 45 deletions tests/e2e/config/setup-test-framework.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/**
* External dependencies
*/
import { get, isEqual, reduce, some, forEach } from 'lodash';
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';

/**
* WordPress dependencies
*/
import {
activatePlugin,
clearLocalStorage,
enablePageDialogAccept,
isOfflineMode,
setBrowserViewport,
switchUserToAdmin,
switchUserToTest,
visitAdminPage,
visitAdminPage
} from '@wordpress/e2e-test-utils';

/**
Expand Down Expand Up @@ -125,7 +122,9 @@ function observeConsoleLogging() {
// See: https://core.trac.wordpress.org/ticket/37000
// See: https://www.chromestatus.com/feature/5088147346030592
// See: https://www.chromestatus.com/feature/5633521622188032
if ( text.includes( 'A cookie associated with a cross-site resource' ) ) {
if (
text.includes( 'A cookie associated with a cross-site resource' )
) {
return;
}

Expand All @@ -137,7 +136,10 @@ function observeConsoleLogging() {

// Network errors are ignored only if we are intentionally testing
// offline mode.
if ( text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) && isOfflineMode() ) {
if (
text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&
isOfflineMode()
) {
return;
}

Expand All @@ -146,6 +148,19 @@ 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;
}

// Ignore all JQMIGRATE (jQuery migrate) deprecation warnings.
if ( text.includes( 'JQMIGRATE' ) ) {
return;
}

const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ];

// As of Puppeteer 1.6.1, `message.text()` wrongly returns an object of
Expand All @@ -159,7 +174,7 @@ 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 = message.args()[ 0 ]?._remoteObject?.description ?? text;

// Disable reason: We intentionally bubble up the console message
// which, unless the test explicitly anticipates the logging via
Expand All @@ -171,43 +186,6 @@ function observeConsoleLogging() {
} );
}

/**
* Runs Axe tests when the block editor is found on the current page.
*
* @return {?Promise} Promise resolving once Axe texts are finished.
*/
async function runAxeTestsForBlockEditor() {
if ( ! await page.$( '.block-editor' ) ) {
return;
}

await expect( page ).toPassAxeTests( {
// Temporary disabled rules to enable initial integration.
// See: https://github.com/WordPress/gutenberg/pull/15018.
disabledRules: [
'aria-allowed-role',
'aria-hidden-focus',
'aria-input-field-name',
'aria-valid-attr-value',
'button-name',
'color-contrast',
'dlitem',
'duplicate-id',
'label',
'link-name',
'listitem',
'region',
'heading-order'
],
exclude: [
// Ignores elements created by metaboxes.
'.edit-post-layout__metaboxes',
// Ignores elements created by TinyMCE.
'.mce-container',
],
} );
}

// 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.
Expand All @@ -221,7 +199,6 @@ beforeAll( async () => {
} );

afterEach( async () => {
await runAxeTestsForBlockEditor();
await setupBrowser();
} );

Expand Down

0 comments on commit 95a39c3

Please sign in to comment.