Commit 216c5413344 for woocommerce
commit 216c5413344018034eab9798867bfd15e418b757
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Tue Jul 14 12:06:29 2026 +0300
e2e tests: fix flaky blocks e2e specs: cart store races and rapid-click test (#66578)
diff --git a/plugins/woocommerce/changelog/testops-deflake-blocks-e2e b/plugins/woocommerce/changelog/testops-deflake-blocks-e2e
new file mode 100644
index 00000000000..9fe3c367649
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-deflake-blocks-e2e
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+De-flake blocks e2e tests.
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
index 097221ff6e3..45a4264f16d 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
@@ -794,6 +794,17 @@ test.describe( 'Add to Cart + Options Block', () => {
} );
await test.step( 'verify cart state persists after reload', async () => {
+ // Reloading while a batch request is still in flight aborts it,
+ // losing the re-add server-side.
+ await page.evaluate( async () => {
+ const { store } = await import( '@wordpress/interactivity' );
+ const unlockKey =
+ 'I acknowledge that using a private store means my plugin will inevitably break on the next store release.';
+ await import( '@woocommerce/stores/woocommerce/cart' );
+ const { actions } = store( 'woocommerce', {}, { lock: unlockKey } );
+ await actions.waitForIdle();
+ } );
+
await page.reload();
await expect(
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-store.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-store.block_theme.spec.ts
index c280a0f4d92..83b4f025a9e 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-store.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-store.block_theme.spec.ts
@@ -47,11 +47,9 @@ test.describe( 'Cart Store', () => {
await frontendUtils.goToShop();
- // Wait for the GET /cart request (refreshCartItems) to complete.
- await page.waitForResponse( '**/wc/store/v1/cart**' );
-
- // refreshCartItems should return a nonce.
- expect( refreshNonce ).toBeTruthy();
+ // The GET /cart fires during page load, so a waitForResponse set up
+ // here can miss it — poll the intercepted nonce instead.
+ await expect.poll( () => refreshNonce ).toBeTruthy();
// Adding a product should use the nonce from refreshCartItems.
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
index bb13d363760..9ecad5f986b 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
@@ -66,35 +66,4 @@ test.describe( `${ blockData.name } Block`, () => {
} );
await expect( productElement ).toBeVisible();
} );
-
- test( 'should compound quantity when rapidly clicking same button', async ( {
- frontendUtils,
- page,
- } ) => {
- const blocks = await frontendUtils.getBlockByName( blockData.slug );
- const block = blocks.first();
-
- await block.locator( 'loading' ).waitFor( {
- state: 'detached',
- } );
-
- // Set up waitForResponse BEFORE the clicks to avoid a race condition:
- // on fast networks the batched Store API request may complete before we
- // start listening. Asserting before the request settles is what makes
- // this test flaky. Mirrors the add-to-cart-with-options rapid-click test.
- const batchPromise = page.waitForResponse( '**/wc/store/v1/batch**' );
-
- // Click the same button 3 times rapidly.
- await block.click();
- await block.click();
- await block.click();
-
- // Wait for the batched add-to-cart request to complete before asserting.
- await batchPromise;
-
- // All 3 clicks should compound to "3 in cart".
- await expect( block.getByRole( 'button' ) ).toHaveText( '3 in cart', {
- timeout: 15000,
- } );
- } );
} );