2023-10-31 10:16:40 +00:00
|
|
|
/* eslint-disable rulesdir/no-raw-playwright-test-import */
|
2023-05-05 11:03:36 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-27 14:54:06 +00:00
|
|
|
import { test as base, expect, ConsoleMessage } from '@playwright/test';
|
2023-05-05 11:03:36 +00:00
|
|
|
import {
|
2023-06-01 11:51:59 +00:00
|
|
|
STORAGE_STATE_PATH,
|
2024-04-26 09:39:11 +00:00
|
|
|
DB_EXPORT_FILE,
|
2024-05-27 14:54:06 +00:00
|
|
|
cli,
|
|
|
|
WPCLIUtils,
|
|
|
|
Admin,
|
|
|
|
Editor,
|
2023-06-30 07:08:14 +00:00
|
|
|
FrontendUtils,
|
2024-01-31 09:23:09 +00:00
|
|
|
LocalPickupUtils,
|
|
|
|
MiniCartUtils,
|
2024-05-27 14:54:06 +00:00
|
|
|
PageUtils,
|
|
|
|
PerformanceUtils,
|
|
|
|
RequestUtils,
|
|
|
|
ShippingUtils,
|
|
|
|
StoreApiUtils,
|
2023-06-01 11:51:59 +00:00
|
|
|
} from '@woocommerce/e2e-utils';
|
2023-05-05 11:03:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set of console logging types observed to protect against unexpected yet
|
|
|
|
* handled (i.e. not catastrophic) errors or warnings. Each key corresponds
|
|
|
|
* to the Playwright ConsoleMessage type, its value the corresponding function
|
|
|
|
* on the console global object.
|
|
|
|
*/
|
|
|
|
const OBSERVED_CONSOLE_MESSAGE_TYPES = [ 'warn', 'error' ] as const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a page event handler to emit uncaught exception to process if one of
|
|
|
|
* the observed console logging types is encountered.
|
|
|
|
*
|
2023-12-12 23:05:20 +00:00
|
|
|
* @param message The console message.
|
2023-05-05 11:03:36 +00:00
|
|
|
*/
|
|
|
|
function observeConsoleLogging( message: ConsoleMessage ) {
|
|
|
|
const type = message.type();
|
|
|
|
if (
|
|
|
|
! OBSERVED_CONSOLE_MESSAGE_TYPES.includes(
|
2023-12-12 23:05:20 +00:00
|
|
|
type as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ]
|
2023-05-05 11:03:36 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const 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' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A chrome advisory warning about SameSite cookies is informational
|
|
|
|
// about future changes, tracked separately for improvement in core.
|
|
|
|
//
|
|
|
|
// 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' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not implemented yet.
|
|
|
|
// Network errors are ignored only if we are intentionally testing
|
|
|
|
// offline mode.
|
|
|
|
// if (
|
|
|
|
// text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&
|
|
|
|
// isOfflineMode()
|
|
|
|
// ) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2023-12-12 23:05:20 +00:00
|
|
|
const logFunction =
|
|
|
|
type as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ];
|
2023-05-05 11:03:36 +00:00
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
const test = base.extend<
|
|
|
|
{
|
|
|
|
admin: Admin;
|
|
|
|
editor: Editor;
|
|
|
|
pageUtils: PageUtils;
|
2023-06-30 07:08:14 +00:00
|
|
|
frontendUtils: FrontendUtils;
|
2023-08-10 14:02:33 +00:00
|
|
|
storeApiUtils: StoreApiUtils;
|
2024-01-15 17:03:24 +00:00
|
|
|
performanceUtils: PerformanceUtils;
|
2023-05-05 11:03:36 +00:00
|
|
|
snapshotConfig: void;
|
2024-01-31 09:23:09 +00:00
|
|
|
shippingUtils: ShippingUtils;
|
|
|
|
localPickupUtils: LocalPickupUtils;
|
|
|
|
miniCartUtils: MiniCartUtils;
|
|
|
|
wpCliUtils: WPCLIUtils;
|
2023-05-05 11:03:36 +00:00
|
|
|
},
|
|
|
|
{
|
2024-05-27 14:54:06 +00:00
|
|
|
requestUtils: RequestUtils;
|
2023-05-05 11:03:36 +00:00
|
|
|
}
|
|
|
|
>( {
|
2024-03-27 09:54:44 +00:00
|
|
|
admin: async ( { page, pageUtils, editor }, use ) => {
|
|
|
|
await use( new Admin( { page, pageUtils, editor } ) );
|
2023-05-05 11:03:36 +00:00
|
|
|
},
|
|
|
|
editor: async ( { page }, use ) => {
|
|
|
|
await use( new Editor( { page } ) );
|
|
|
|
},
|
|
|
|
page: async ( { page }, use ) => {
|
|
|
|
page.on( 'console', observeConsoleLogging );
|
|
|
|
|
|
|
|
await use( page );
|
|
|
|
|
|
|
|
// Clear local storage after each test.
|
|
|
|
await page.evaluate( () => {
|
|
|
|
window.localStorage.clear();
|
|
|
|
} );
|
2024-04-26 09:39:11 +00:00
|
|
|
|
2024-05-13 12:58:26 +00:00
|
|
|
await cli(
|
2024-04-26 09:39:11 +00:00
|
|
|
`npm run wp-env run tests-cli wp db import ${ DB_EXPORT_FILE }`
|
|
|
|
);
|
2023-05-05 11:03:36 +00:00
|
|
|
},
|
|
|
|
pageUtils: async ( { page }, use ) => {
|
|
|
|
await use( new PageUtils( { page } ) );
|
|
|
|
},
|
2023-08-15 10:42:29 +00:00
|
|
|
frontendUtils: async ( { page, requestUtils }, use ) => {
|
|
|
|
await use( new FrontendUtils( page, requestUtils ) );
|
2023-06-30 07:08:14 +00:00
|
|
|
},
|
2024-01-15 17:03:24 +00:00
|
|
|
performanceUtils: async ( { page }, use ) => {
|
|
|
|
await use( new PerformanceUtils( page ) );
|
|
|
|
},
|
2023-08-10 14:02:33 +00:00
|
|
|
storeApiUtils: async ( { requestUtils }, use ) => {
|
|
|
|
await use( new StoreApiUtils( requestUtils ) );
|
|
|
|
},
|
2024-01-31 09:23:09 +00:00
|
|
|
shippingUtils: async ( { page, admin }, use ) => {
|
|
|
|
await use( new ShippingUtils( page, admin ) );
|
|
|
|
},
|
|
|
|
localPickupUtils: async ( { page, admin }, use ) => {
|
|
|
|
await use( new LocalPickupUtils( page, admin ) );
|
|
|
|
},
|
|
|
|
miniCartUtils: async ( { page, frontendUtils }, use ) => {
|
|
|
|
await use( new MiniCartUtils( page, frontendUtils ) );
|
|
|
|
},
|
|
|
|
wpCliUtils: async ( {}, use ) => {
|
|
|
|
await use( new WPCLIUtils() );
|
|
|
|
},
|
2023-05-05 11:03:36 +00:00
|
|
|
requestUtils: [
|
|
|
|
async ( {}, use, workerInfo ) => {
|
|
|
|
const requestUtils = await RequestUtils.setup( {
|
2024-05-27 14:54:06 +00:00
|
|
|
baseURL: workerInfo.project.use.baseURL as string,
|
2023-05-05 11:03:36 +00:00
|
|
|
storageStatePath: STORAGE_STATE_PATH,
|
|
|
|
} );
|
|
|
|
|
2024-05-27 14:54:06 +00:00
|
|
|
await use( requestUtils );
|
2023-05-05 11:03:36 +00:00
|
|
|
},
|
|
|
|
{ scope: 'worker', auto: true },
|
|
|
|
],
|
|
|
|
} );
|
|
|
|
|
|
|
|
export { test, expect };
|