Commit 6d41fda7d68 for woocommerce
commit 6d41fda7d686ea8e90c2ea355b8e2aee901c7b32
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Thu Nov 19 15:31:00 2026 +0200
Delete posts that Blocks e2e specs create, in the shared fixture (#71046)
diff --git a/plugins/woocommerce/changelog/testops-324-blocks-e2e-shared-post-cleanup b/plugins/woocommerce/changelog/testops-324-blocks-e2e-shared-post-cleanup
new file mode 100644
index 00000000000..f6953fe14ea
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-324-blocks-e2e-shared-post-cleanup
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Delete posts that Blocks e2e specs create, in the shared fixture; no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/parent-item-key.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/parent-item-key.block_theme.spec.ts
index b931b5b4191..e20c4a8b1e9 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/parent-item-key.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/parent-item-key.block_theme.spec.ts
@@ -141,8 +141,6 @@ const test = base.extend< {
test.describe( 'ProductButton in-cart count', () => {
test( 'does not count a child cart line in the add to cart button', async ( {
page,
- requestUtils,
- cleanup,
addToCartWithOptionsPage,
} ) => {
await addToCartWithOptionsPage.createPostWithProductBlock(
@@ -150,19 +148,6 @@ test.describe( 'ProductButton in-cart count', () => {
'hoodie-blue-yes'
);
const postUrl = page.url();
- const postId = Number(
- ( await page.locator( 'body' ).getAttribute( 'class' ) )?.match(
- /\bpostid-(\d+)\b/
- )?.[ 1 ]
- );
- expect( postId ).toBeGreaterThan( 0 );
- cleanup( async () => {
- await requestUtils.rest( {
- method: 'DELETE',
- path: `/wp/v2/posts/${ postId }`,
- params: { force: true },
- } );
- } );
// All workers share the admin cart, so the cart steps run as a guest.
await page.context().clearCookies();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/product-picker.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/product-picker.block_theme.spec.ts
index c0cc5fdb9b9..1a4f00c1773 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/product-picker.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/product-picker.block_theme.spec.ts
@@ -17,27 +17,6 @@ import ProductCollectionPage, {
} from './product-collection.page';
const test = base.extend< { pageObject: ProductCollectionPage } >( {
- // Each new post gets an ID when the editor opens it, so this deletes
- // published posts and drafts alike.
- admin: async ( { admin, requestUtils, cleanup }, use ) => {
- const createNewPost = admin.createNewPost.bind( admin );
- admin.createNewPost = async ( ...args ) => {
- await createNewPost( ...args );
- const postId = await (
- await admin.page.waitForFunction( () =>
- window.wp.data.select( 'core/editor' )?.getCurrentPostId()
- )
- ).jsonValue();
- cleanup( () =>
- requestUtils.rest( {
- method: 'DELETE',
- path: `/wp/v2/posts/${ postId }`,
- params: { force: true },
- } )
- );
- };
- await use( admin );
- },
pageObject: async ( { page, admin, editor }, use ) => {
const pageObject = new ProductCollectionPage( {
page,
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/register-product-collection.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/register-product-collection.block_theme.spec.ts
index b29c01e0d80..dea180253fd 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/register-product-collection.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-collection/register-product-collection.block_theme.spec.ts
@@ -25,27 +25,6 @@ declare global {
}
const test = base.extend< { pageObject: ProductCollectionPage } >( {
- // Each new post gets an ID when the editor opens it, so this deletes
- // published posts and drafts alike.
- admin: async ( { admin, requestUtils, cleanup }, use ) => {
- const createNewPost = admin.createNewPost.bind( admin );
- admin.createNewPost = async ( ...args ) => {
- await createNewPost( ...args );
- const postId = await (
- await admin.page.waitForFunction( () =>
- window.wp.data.select( 'core/editor' )?.getCurrentPostId()
- )
- ).jsonValue();
- cleanup( () =>
- requestUtils.rest( {
- method: 'DELETE',
- path: `/wp/v2/posts/${ postId }`,
- params: { force: true },
- } )
- );
- };
- await use( admin );
- },
pageObject: async ( { page, admin, editor }, use ) => {
const pageObject = new ProductCollectionPage( {
page,
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
index 79d9f3f947d..2d040c7652b 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
@@ -145,8 +145,43 @@ const test = base.extend<
wpCoreVersion: number;
}
>( {
- admin: async ( { page, pageUtils, editor, wpCoreVersion }, use ) => {
- await use( new Admin( { page, pageUtils, editor, wpCoreVersion } ) );
+ // Deletes each post that `createNewPost` opens, drafts included, because
+ // `blocks-parallel` never resets the database. In `blocks-serial`, the
+ // delete runs before the database reset only when `page` is set up before
+ // `cleanup`; otherwise it fails with a 404 and only logs a warning.
+ admin: async (
+ { page, pageUtils, editor, wpCoreVersion, requestUtils, cleanup },
+ use
+ ) => {
+ const admin = new Admin( { page, pageUtils, editor, wpCoreVersion } );
+ const createNewPost = admin.createNewPost.bind( admin );
+ admin.createNewPost = async ( ...args ) => {
+ await createNewPost( ...args );
+ // `createNewPost` waits for `wp.data`, not for the editor to mount.
+ const { id, type } = await (
+ await page.waitForFunction( () => {
+ const editorStore = window.wp.data.select( 'core/editor' );
+ const postId = editorStore?.getCurrentPostId();
+ return (
+ postId && {
+ id: postId,
+ type: editorStore.getCurrentPostType(),
+ }
+ );
+ } )
+ ).jsonValue();
+ cleanup( async () => {
+ const { rest_base: restBase } = await requestUtils.rest< {
+ rest_base: string;
+ } >( { path: `/wp/v2/types/${ type }` } );
+ await requestUtils.rest( {
+ method: 'DELETE',
+ path: `/wp/v2/${ restBase }/${ id }`,
+ params: { force: true },
+ } );
+ } );
+ };
+ await use( admin );
},
editor: async ( { page, wpCoreVersion }, use ) => {
await use( new Editor( { page, wpCoreVersion } ) );