Commit b39a1ca4d4d for woocommerce
commit b39a1ca4d4d09483055a2ac493acd9e7e02f6ff7
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Thu Jul 16 16:05:51 2026 +0300
[e2e] Reduce Blocks E2E database restore overhead (#66671)
* perf(e2e): reduce Blocks database restore overhead
Blocks tests reset the database and import a snapshot after every test. Running each operation through a separate npm and wp-env launch repeats process and container startup across the suite.
Run both operations within one CLI-container invocation while preserving reset-before-import ordering and failure short-circuiting. Two local benchmark runs measured approximately 33% lower median restoration time.
* chore(changelog): document Blocks E2E restore optimization
WooCommerce package changes require a changelog entry. Record the recurring E2E teardown improvement as a patch-level performance change.
diff --git a/plugins/woocommerce/changelog/perf-e2e-combined-db-restore b/plugins/woocommerce/changelog/perf-e2e-combined-db-restore
new file mode 100644
index 00000000000..987b94dcea9
--- /dev/null
+++ b/plugins/woocommerce/changelog/perf-e2e-combined-db-restore
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Reduce Blocks E2E per-test database restoration overhead by running reset and snapshot import in one wp-env container invocation.
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
index 18a8e85b1f7..a6458e52ac3 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
@@ -18,6 +18,11 @@ import {
ShippingUtils,
} from '@woocommerce/e2e-utils';
+/**
+ * Internal dependencies
+ */
+import { restoreBlocksDatabase } from './wp-cli';
+
/**
* Set of console logging types observed to protect against unexpected yet
* handled (i.e. not catastrophic) errors or warnings. Each key corresponds
@@ -159,9 +164,8 @@ const test = base.extend<
);
}
- await wpCLI( `db reset --yes` );
// Reset the database to the initial state via snapshot import.
- await wpCLI( `db import ${ DB_EXPORT_FILE }` );
+ await restoreBlocksDatabase( DB_EXPORT_FILE );
},
pageUtils: async ( { page }, use ) => {
await use( new PageUtils( { page } ) );
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/wp-cli.ts b/plugins/woocommerce/tests/e2e/utils/blocks/wp-cli.ts
index 37fb6e487c9..0eb34a84692 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/wp-cli.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/wp-cli.ts
@@ -2,9 +2,10 @@
* External dependencies
*/
import { promisify } from 'util';
-import { exec } from 'child_process';
+import { exec, execFile } from 'child_process';
const execPromisified = promisify( exec );
+const execFilePromisified = promisify( execFile );
/**
* Runs a WP-CLI command inside the single-container E2E environment's `cli`
@@ -16,6 +17,25 @@ export async function wpCLI( command: string ) {
);
}
+/**
+ * Resets the Blocks E2E database and imports its snapshot in one CLI-container
+ * invocation.
+ */
+export async function restoreBlocksDatabase( databaseFile: string ) {
+ return await execFilePromisified( 'npm', [
+ 'run',
+ 'wp-env:e2e',
+ 'run',
+ 'cli',
+ '--',
+ 'sh',
+ '-c',
+ 'wp db reset --yes && wp db import "$1"',
+ 'restore-blocks-database',
+ databaseFile,
+ ] );
+}
+
/**
* Returns the ID of the post with the given slug, throwing if none is found.
*