woocommerce/plugins/woocommerce-blocks/tests/e2e/utils/test.ts

175 lines
4.8 KiB
TypeScript
Raw Normal View History

/* eslint-disable rulesdir/no-raw-playwright-test-import */
/**
* External dependencies
*/
import { test as base, expect, ConsoleMessage } from '@playwright/test';
import {
STORAGE_STATE_PATH,
DB_EXPORT_FILE,
wpCLI,
Admin,
Editor,
FrontendUtils,
LocalPickupUtils,
MiniCartUtils,
PageUtils,
PerformanceUtils,
RequestUtils,
ShippingUtils,
StoreApiUtils,
} from '@woocommerce/e2e-utils';
/**
* 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.
*/
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 ]
)
) {
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 ];
// 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;
frontendUtils: FrontendUtils;
Interactivity API and Product Button (https://github.com/woocommerce/woocommerce-blocks/pull/10006) * Update Interactivity API JS files * Disable TS checks in the Interactivity API for now * Add new SSR files * Replace wp_ prefixes with wc_ ones * Replace wp- prefix with wc- * Replace guternberg_ prefix with woocommerce_ * Remove file comments from Gutenberg * Rename files with `wp` prefix * Fix code to load Interactivity API php files * Remove TODO comments * Replace @wordpress with @woocommerce * Update Webpack configuration * Fix directive prefix * Remove interactivity folder from tsconfig exclude * Add client-side navigation meta tag code * Remove unneeded blocks.php file * Fix store tag id * Register Interactivity API runtime script * Fix Interactivity API runtime registering * Remove all files related to directive processing in PHP * Move json_encode to Store's render method * WIP * WIP * WIP * WIP * Preserve previous context * Ignore Minicart block on client-side navigation * Refresh page on store updatRefresh page on store updatee * Refactor logic * Add console error when a path is missing * fix PHP lint error * WIP store * use store approach * update jest configuration * restore Mini Cart changes * move cart store subscription to interactivity package * move interactivity flag * format HTML * move addToCartText to the context * Load product-query stylesheet when rendering the Products block * update sideEffects array * fix catch * rename moreThanOneItem to isThereMoreThanOneItem * improve how scripts are enqueued * update default value for the filter woocommerce_blocks_enable_interactivity_api * Update assets/js/atomic/blocks/product-elements/button/block.json Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Update assets/js/interactivity/cart/cart-store.ts Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * fix block.json * remove updateStore function * restore interactivity api changes * import cart store * show notice when there is an error * add logic to dequeue script on classic themes and block themes * imrpove logic about notice * Interactivity API: add `afterLoad` callbacks to `store()` function (https://github.com/woocommerce/woocommerce-blocks/pull/10338) * show notice when there is an error * Add initial implementation for store callbacks * Run `afterLoad` callbacks after `init` * Move cart state subscription to Product button * Remove cart-store from Interactivity API internals * Change callbacks with options and save only afterLoad callbacks * ProductButton: Add animation (https://github.com/woocommerce/woocommerce-blocks/pull/10351) * implement animation * improve logic * refactor logic * refactor code * address feedback about code style * add support for woocommerce_add_to_cart_quantity * Fix animation flickering * Introduce wp-effect, reduce the amount of numberOfItem variables to 2 and consolidate animation status * add support for added class * Remove unnecessary selector * Don't fetch cart if it was already fetched * remove added class --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com> --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> * update deepsignal * remove added class * update deepsignal * Interactivity API and Product Button: Add E2E tests (https://github.com/woocommerce/woocommerce-blocks/pull/10036) * Add FrontendUtils class * fix conflicts * use locator * restore click usage * Product Button: Add E2E test * fix util * fix E2E tests * remove comment * Add E2E test to ensure that woocommerce_product_add_to_cart_text works * update sideEffects array * add zip and unzip as package * fix wp-env configuration * fix E2E test * add report * try now * try now * try now * fix E2E test * E2E: Add documentation for testing actions and filters. Fixes woocommerce/woocommerce-blocks#10135 (https://github.com/woocommerce/woocommerce-blocks/pull/10206) * update description * fix label * rename files * make requestUtils private * remove page.goto * use toHaveCount * use productsToDisplay variable * fix E2E tests * rename class utils --------- Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> --------- Co-authored-by: David Arenas <david.arenas@automattic.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
2023-08-10 14:02:33 +00:00
storeApiUtils: StoreApiUtils;
performanceUtils: PerformanceUtils;
snapshotConfig: void;
shippingUtils: ShippingUtils;
localPickupUtils: LocalPickupUtils;
miniCartUtils: MiniCartUtils;
},
{
requestUtils: RequestUtils;
}
>( {
Fix E2E tests for WordPress 6.5 (#44593) * Add sharding to Blocks e2e tests * Changelog * Push a change to Blocks README to trigger tests * Fix syntax * Fixed again * Try again * Trying to get the shard number * Shard names * fix E2E test * use wordpress 6.5 as test env * update util * fix Mini Cart Block E2E test * add editor dependency * fix E2E tests * fix E2E tests * fix E2E tests * restore global setup file * fix E2E tests * fix global setup * try now * try now * fix E2E test * fix E2E test * fix mini cart E2E test * add changelog * complete all the jobs * update playwright * fix E2E tests * fix E2E test * try now * fix E2E test * not show welcome guide for the post editor * update configuration * fix guest storage state * fix E2E tests * check now * fix E2E tests * fix command * improve selector * use WordPress 6.5 beta 2 * use WordPress 6.5 beta 3 * fix canvas use * wait for button * fix E2E test * fix E2E test * fix product button * fix product collection tests * fix wp build link * use beforeEach * fix E2E tests * use WordPress RC2 * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * trigger CI * fix E2E tests * fix E2E tests * fix E2E test * fix E2E tests * add timeout * Fix flaky locator assertions ...by replacing them with dedicaed auto-waiting ones. * Apply correct use of waitForRequest/Response and remove where unnecessary * Remove obsolete waitUntils * Fix accidentally isolated test * Replace saveTemplate with core's saveSiteEditorEntities * Fix findProductRow util * Restore necessary request waiters * Use activateTheme util instead of cli call * Remove unused import * Fix request destructured call Request properties cannot be destructured (todo: create upstream issue) * Revert some waitForRequest changes These need to be investigated for heavy bleeding from side-effects * Fix failing cart checkout test * Set navigation timeout to 10s We need this so that API like page.goto or page.waitForURL doesn't take 100 seconds (global timeout) to throw. * Do not close the page in the page fixture override The page will be closed anyway, and by closing it explicitly in the teardown phase of the fixture we create a flaky race condition where the page might be closed before the action/navigation timeout is reached, resulting in "page closed!" error instead of, e.g. "locator.fill timed out". * Revert product collection tests due to conflicts * Try fixing E2E test * Remove some random change * Revert to programmatic blur :shrug: * Fix additional checkout fields test * Add a waitForRequest safety check in case it's debounced * Fix price filter test * Fix flaky visitTemplateEditor util * Remove obsolete code from global setup * Revert "Fix flaky visitTemplateEditor util" This reverts commit 227336f2653eb17b37ade45634374d69ef221c50. * update to WordPress RC3 * Add waitForCustomerDataUpdate function * Don't wait for requests and use data store instead * Try with new wait condition * Re-add wait condition * Wait for customer update in guest checkout test * Add changelog * fix lint error * fix some E2E tests * disable welcome guide * remove beforeAll * add timeout * add another timeout * increase timeout * Add call to waitForSiteEditorFinishLoading when editing the theme template * remove timeout * remove not necessary comment * clean changelog * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * remove changelog --------- Co-authored-by: Jon Lane <jon.lane@automattic.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Bart Kalisz <bartlomiej.kalisz@gmail.com> Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2024-03-27 09:54:44 +00:00
admin: async ( { page, pageUtils, editor }, use ) => {
await use( new Admin( { page, pageUtils, editor } ) );
},
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();
} );
await wpCLI( `db import ${ DB_EXPORT_FILE }` );
},
pageUtils: async ( { page }, use ) => {
await use( new PageUtils( { page } ) );
},
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
frontendUtils: async ( { page, requestUtils }, use ) => {
await use( new FrontendUtils( page, requestUtils ) );
},
performanceUtils: async ( { page }, use ) => {
await use( new PerformanceUtils( page ) );
},
Interactivity API and Product Button (https://github.com/woocommerce/woocommerce-blocks/pull/10006) * Update Interactivity API JS files * Disable TS checks in the Interactivity API for now * Add new SSR files * Replace wp_ prefixes with wc_ ones * Replace wp- prefix with wc- * Replace guternberg_ prefix with woocommerce_ * Remove file comments from Gutenberg * Rename files with `wp` prefix * Fix code to load Interactivity API php files * Remove TODO comments * Replace @wordpress with @woocommerce * Update Webpack configuration * Fix directive prefix * Remove interactivity folder from tsconfig exclude * Add client-side navigation meta tag code * Remove unneeded blocks.php file * Fix store tag id * Register Interactivity API runtime script * Fix Interactivity API runtime registering * Remove all files related to directive processing in PHP * Move json_encode to Store's render method * WIP * WIP * WIP * WIP * Preserve previous context * Ignore Minicart block on client-side navigation * Refresh page on store updatRefresh page on store updatee * Refactor logic * Add console error when a path is missing * fix PHP lint error * WIP store * use store approach * update jest configuration * restore Mini Cart changes * move cart store subscription to interactivity package * move interactivity flag * format HTML * move addToCartText to the context * Load product-query stylesheet when rendering the Products block * update sideEffects array * fix catch * rename moreThanOneItem to isThereMoreThanOneItem * improve how scripts are enqueued * update default value for the filter woocommerce_blocks_enable_interactivity_api * Update assets/js/atomic/blocks/product-elements/button/block.json Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Update assets/js/interactivity/cart/cart-store.ts Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * fix block.json * remove updateStore function * restore interactivity api changes * import cart store * show notice when there is an error * add logic to dequeue script on classic themes and block themes * imrpove logic about notice * Interactivity API: add `afterLoad` callbacks to `store()` function (https://github.com/woocommerce/woocommerce-blocks/pull/10338) * show notice when there is an error * Add initial implementation for store callbacks * Run `afterLoad` callbacks after `init` * Move cart state subscription to Product button * Remove cart-store from Interactivity API internals * Change callbacks with options and save only afterLoad callbacks * ProductButton: Add animation (https://github.com/woocommerce/woocommerce-blocks/pull/10351) * implement animation * improve logic * refactor logic * refactor code * address feedback about code style * add support for woocommerce_add_to_cart_quantity * Fix animation flickering * Introduce wp-effect, reduce the amount of numberOfItem variables to 2 and consolidate animation status * add support for added class * Remove unnecessary selector * Don't fetch cart if it was already fetched * remove added class --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com> --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> * update deepsignal * remove added class * update deepsignal * Interactivity API and Product Button: Add E2E tests (https://github.com/woocommerce/woocommerce-blocks/pull/10036) * Add FrontendUtils class * fix conflicts * use locator * restore click usage * Product Button: Add E2E test * fix util * fix E2E tests * remove comment * Add E2E test to ensure that woocommerce_product_add_to_cart_text works * update sideEffects array * add zip and unzip as package * fix wp-env configuration * fix E2E test * add report * try now * try now * try now * fix E2E test * E2E: Add documentation for testing actions and filters. Fixes woocommerce/woocommerce-blocks#10135 (https://github.com/woocommerce/woocommerce-blocks/pull/10206) * update description * fix label * rename files * make requestUtils private * remove page.goto * use toHaveCount * use productsToDisplay variable * fix E2E tests * rename class utils --------- Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> --------- Co-authored-by: David Arenas <david.arenas@automattic.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
2023-08-10 14:02:33 +00:00
storeApiUtils: async ( { requestUtils }, use ) => {
await use( new StoreApiUtils( requestUtils ) );
},
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 ) );
},
requestUtils: [
async ( {}, use, workerInfo ) => {
const requestUtils = await RequestUtils.setup( {
baseURL: workerInfo.project.use.baseURL as string,
storageStatePath: STORAGE_STATE_PATH,
} );
await use( requestUtils );
},
{ scope: 'worker', auto: true },
],
} );
export { test, expect };