Commit f3107ab1426 for woocommerce
commit f3107ab1426717c92e29818ad79e90b347af608a
Author: Ján Mikláš <neosinner@gmail.com>
Date: Thu Nov 19 15:53:43 2026 +0100
Share the Playwright wait for cart and checkout updates (#71140)
* feat: share the checkout update wait
* docs: record the package change
diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index c505754d3e3..6a9e05b0563 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -80,6 +80,10 @@ module.exports = defineConfig( playwrightDefaults( {
Use the second config to set suite-specific projects, worker limits, storage state, and overrides.
+### Wait for cart and checkout updates
+
+Call `await waitForCheckoutUpdates( page )` using `@woocommerce/extension-tooling/wait-for-checkout-updates` to wait for active jQuery requests and pending WooCommerce cart and checkout store updates. For actions that schedule a later update, wait for the expected response or UI change in the test.
+
### Filter PHP debug logs
Use `@woocommerce/extension-tooling/php-warning-filter` with the log text and the path fragments for the tested plugins. The filter returns matching PHP errors, warnings, notices and deprecations. The extension reads the log and checks the result in its warnings project.
diff --git a/packages/js/extension-tooling/changelog/add-wait-for-checkout-updates b/packages/js/extension-tooling/changelog/add-wait-for-checkout-updates
new file mode 100644
index 00000000000..97b6ebf04ad
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/add-wait-for-checkout-updates
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Share the Playwright wait for cart and checkout updates.
diff --git a/packages/js/extension-tooling/package.json b/packages/js/extension-tooling/package.json
index c4e54c4b8f2..7a21a20f289 100644
--- a/packages/js/extension-tooling/package.json
+++ b/packages/js/extension-tooling/package.json
@@ -18,6 +18,7 @@
"./webpack-text-includes": "./src/webpack-text-includes.js",
"./check-i18n": "./src/check-i18n.js",
"./playwright-defaults": "./src/playwright-defaults.js",
+ "./wait-for-checkout-updates": "./src/wait-for-checkout-updates.js",
"./e2e-site-config": "./src/e2e-site-config.js",
"./php-warning-filter": "./src/php-warning-filter.js",
"./stylelint/legacy-scss": "./configs/stylelint-legacy-scss.json"
diff --git a/packages/js/extension-tooling/src/wait-for-checkout-updates.js b/packages/js/extension-tooling/src/wait-for-checkout-updates.js
new file mode 100644
index 00000000000..a7706dd7541
--- /dev/null
+++ b/packages/js/extension-tooling/src/wait-for-checkout-updates.js
@@ -0,0 +1,28 @@
+/**
+ * Wait for active classic requests and pending Cart and Checkout block updates.
+ *
+ * @param {import('@playwright/test').Page} page Playwright page.
+ * @return {Promise<void>} Resolves when the tracked updates settle.
+ */
+module.exports = async function waitForCheckoutUpdates( page ) {
+ await page.waitForFunction( () => {
+ if ( window.jQuery?.active > 0 ) {
+ return false;
+ }
+ const select = window.wp?.data?.select;
+ if ( ! select ) {
+ return true;
+ }
+ const cart = select( 'wc/store/cart' );
+ if (
+ cart &&
+ ( cart.isCustomerDataUpdating?.() ||
+ cart.isShippingRateBeingSelected?.() ||
+ cart.getItemsPendingQuantityUpdate?.()?.length ||
+ cart.getItemsPendingDelete?.()?.length )
+ ) {
+ return false;
+ }
+ return ! select( 'wc/store/checkout' )?.isCalculating?.();
+ } );
+};
diff --git a/packages/js/extension-tooling/test/wait-for-checkout-updates.test.js b/packages/js/extension-tooling/test/wait-for-checkout-updates.test.js
new file mode 100644
index 00000000000..8dc51a18841
--- /dev/null
+++ b/packages/js/extension-tooling/test/wait-for-checkout-updates.test.js
@@ -0,0 +1,76 @@
+/**
+ * External dependencies
+ */
+const assert = require( 'node:assert/strict' );
+const test = require( 'node:test' );
+const { runInNewContext } = require( 'node:vm' );
+
+/**
+ * Internal dependencies
+ */
+const waitForCheckoutUpdates = require( '../src/wait-for-checkout-updates' );
+
+test( 'waits for classic requests and pending cart and checkout updates', async () => {
+ const states = [
+ [ {}, true ],
+ [ { jQuery: { active: 0 } }, true ],
+ [ { jQuery: { active: 1 } }, false ],
+ ];
+ const withStores = ( cart, checkout ) => ( {
+ wp: {
+ data: {
+ select: ( store ) =>
+ store === 'wc/store/cart' ? cart : checkout,
+ },
+ },
+ } );
+
+ states.push(
+ [ withStores( undefined, undefined ), true ],
+ [ withStores( {}, {} ), true ],
+ [
+ {
+ jQuery: { active: 0 },
+ ...withStores( { isCustomerDataUpdating: () => true } ),
+ },
+ false,
+ ],
+ [ withStores( { getItemsPendingQuantityUpdate: () => [ 1 ] } ), false ],
+ [ withStores( { getItemsPendingDelete: () => [ 1 ] } ), false ],
+ [ withStores( { isShippingRateBeingSelected: () => true } ), false ],
+ [ withStores( {}, { isCalculating: () => true } ), false ],
+ [
+ withStores(
+ { getItemsPendingQuantityUpdate: () => [] },
+ { isCalculating: () => false }
+ ),
+ true,
+ ]
+ );
+
+ let waits = 0;
+ await waitForCheckoutUpdates( {
+ waitForFunction: async ( condition ) => {
+ waits++;
+ for ( const [ window, expected ] of states ) {
+ assert.equal(
+ runInNewContext( `(${ condition })()`, { window } ),
+ expected
+ );
+ }
+ },
+ } );
+ assert.equal( waits, 1 );
+} );
+
+test( 'propagates a browser wait failure to the caller', async () => {
+ const timeout = new Error( 'Cart updates did not settle' );
+ await assert.rejects(
+ waitForCheckoutUpdates( {
+ waitForFunction: async () => {
+ throw timeout;
+ },
+ } ),
+ ( error ) => error === timeout
+ );
+} );