Commit 99c3aece90f for woocommerce
commit 99c3aece90f6dca7d47f28507175921b2d737c4b
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Thu Sep 10 22:34:09 2026 +0300
[tests] Make the Blocks E2E seed reset the shipping zones and tax settings it relies on (#68248)
* fix(e2e): converge the Blocks seed's shipping and tax topology
`wp site empty` removes posts and terms but not shipping zones, zone
methods, or tax classes. Depending on what ran before the seed, the
Blocks profile could carry a named smart-default zone from a Core
run, zone 0 could hold four methods instead of two, and the reduced
and zero tax classes the specs assume could be missing. Specs then
failed far from the seed, and only on some machines.
Delete every named zone and every zone 0 method before seeding the
Flat/Free pair, mark the smart-default zones as created so
WooCommerce does not add one back, and ensure the two tax classes
exist. Each step reads its result back and fails the seed if it did
not take.
Refs TESTOPS-234
* fix(e2e): reset the Blocks seed's tax settings to WooCommerce defaults
Core's tax settings spec changes the tax display and calculation
options and restores only woocommerce_calc_taxes. It leaves the cart
showing prices including tax, so after a Core run the Blocks checkout
shows Flat rate shipping as $12.00 instead of the $10.00 its specs
expect, and the checkout shopper shipping test fails.
The Blocks seed already owns the tax classes and rates. Reset the tax
options the Blocks specs render with to WooCommerce's defaults in the
same step, and fail the seed if a value does not stick.
Refs TESTOPS-234
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* docs(e2e): Document switching between the Core and Blocks profiles
The E2E README only said that `pnpm env:e2e:restart` gives a fresh
state. It did not say that Core and Blocks tests share one wp-env
database, or that `pnpm env:start:blocks` seeds on top of whatever that
database already holds.
Running Core tests and then the Blocks seed on the same environment can
leave state behind that the Blocks profile does not expect. The seed
now resets the shipping zones, tax classes, and tax settings it relies
on, but nothing covers the rest.
Say what the seed resets, that other Core state can still leak, and
when to run `pnpm env:e2e:restart` before switching profiles.
Refs TESTOPS-234
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* chore(changelog): Add entry for the Blocks E2E seed convergence
The branch changes E2E test infrastructure in the WooCommerce plugin
package, and every package change needs a changelog entry. Nothing
ships to merchants, so the entry is a dev-type comment with no body.
Refs TESTOPS-234
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/testops-234-blocks-seed-convergence b/plugins/woocommerce/changelog/testops-234-blocks-seed-convergence
new file mode 100644
index 00000000000..587f0ea4131
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-234-blocks-seed-convergence
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Make the Blocks E2E seed reset the shipping zones, tax classes, and tax settings it depends on, and document switching between the Core and Blocks E2E profiles. Test infrastructure only.
+
diff --git a/plugins/woocommerce/tests/e2e/README.md b/plugins/woocommerce/tests/e2e/README.md
index ba2605c6058..a126290cdb6 100644
--- a/plugins/woocommerce/tests/e2e/README.md
+++ b/plugins/woocommerce/tests/e2e/README.md
@@ -43,6 +43,8 @@ To re-create the environment for a fresh state:
`pnpm env:e2e:restart` (resets and restarts the E2E test environment)
+Core and Blocks tests share the same E2E `wp-env` database but expect different fixture profiles. `pnpm env:start:blocks` seeds the Blocks profile on top of whatever the database already holds, and `pnpm test:e2e:*` runs against the environment's current state. The Blocks seed resets the shipping zones, tax classes, and tax settings it relies on, so running it after Core tests is safe for those. Other state a Core run leaves behind can still leak into the Blocks profile. If Blocks tests fail after Core tests ran on the same environment, run `pnpm env:e2e:restart` and then `pnpm env:start:blocks`. To go back to Core tests after Blocks, run `pnpm env:e2e:restart`.
+
You can refer to the pnpm scripts in the `package.json` file for more commands. Check out the `env:some-command` scripts
for managing the `wp-env` environment.
diff --git a/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/shipping.sh b/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/shipping.sh
index 5eddc57681a..570f0461285 100644
--- a/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/shipping.sh
+++ b/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/shipping.sh
@@ -2,17 +2,29 @@
set -euo pipefail
-# `wp site empty` does not remove shipping zone methods: they are rows in the
-# woocommerce_shipping_zone_methods table rather than posts or terms, so they
-# survive it. Creating them again on a re-seed leaves zone 0 with four methods
-# instead of two, at exit 0, and the specs that rely on the seeded shape then
-# fail somewhere far from the seed. Clear the zone first so this is re-runnable.
+# `wp site empty` does not remove shipping zones or methods. Converge the full
+# topology so this profile always uses only its zone 0 Flat/Free pair, even
+# after another profile creates a named smart-default zone.
wp eval "$(cat <<'PHP'
+foreach ( WC_Shipping_Zones::get_zones() as $zone_data ) {
+ WC_Shipping_Zones::delete_zone( $zone_data['zone_id'] );
+}
+
+$remaining_zones = WC_Shipping_Zones::get_zones();
+if ( ! empty( $remaining_zones ) ) {
+ WP_CLI::error( sprintf( 'Unable to delete %d named shipping zone(s).', count( $remaining_zones ) ) );
+}
+
$zone = WC_Shipping_Zones::get_zone( 0 );
foreach ( $zone->get_shipping_methods() as $method ) {
$zone->delete_shipping_method( $method->instance_id );
}
+
+update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
+if ( 'yes' !== get_option( 'woocommerce_admin_created_default_shipping_zones' ) ) {
+ WP_CLI::error( 'Unable to persist the smart-default shipping zone marker.' );
+}
PHP
)"
diff --git a/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/tax.sh b/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/tax.sh
index 97a6dd13024..c9fdb9e3d65 100644
--- a/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/tax.sh
+++ b/plugins/woocommerce/tests/e2e/bin/blocks/scripts/parallel/tax.sh
@@ -17,6 +17,42 @@ $rate_ids = $wpdb->get_col( "SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_
foreach ( $rate_ids as $rate_id ) {
WC_Tax::_delete_tax_rate( $rate_id );
}
+
+$required_tax_classes = array(
+ 'reduced-rate' => 'Reduced rate',
+ 'zero-rate' => 'Zero rate',
+);
+
+foreach ( $required_tax_classes as $slug => $name ) {
+ if ( WC_Tax::get_tax_class_by( 'slug', $slug ) ) {
+ continue;
+ }
+
+ $result = WC_Tax::create_tax_class( $name, $slug );
+ if ( is_wp_error( $result ) ) {
+ WP_CLI::error( sprintf( 'Could not create tax class "%1$s": %2$s', $slug, $result->get_error_message() ) );
+ }
+}
+
+// Core's tax settings spec changes these and restores only
+// woocommerce_calc_taxes. Blocks specs expect WooCommerce's defaults.
+$tax_option_defaults = array(
+ 'woocommerce_prices_include_tax' => 'no',
+ 'woocommerce_tax_based_on' => 'shipping',
+ 'woocommerce_shipping_tax_class' => 'inherit',
+ 'woocommerce_tax_round_at_subtotal' => 'no',
+ 'woocommerce_tax_display_shop' => 'excl',
+ 'woocommerce_tax_display_cart' => 'excl',
+ 'woocommerce_price_display_suffix' => '',
+ 'woocommerce_tax_total_display' => 'itemized',
+);
+
+foreach ( $tax_option_defaults as $option => $value ) {
+ update_option( $option, $value );
+ if ( get_option( $option ) !== $value ) {
+ WP_CLI::error( sprintf( 'Could not reset %s.', $option ) );
+ }
+}
PHP
)"