Commit 057eaf06f02 for woocommerce
commit 057eaf06f028e732160172d8decf511a77bd446a
Author: Ján Mikláš <neosinner@gmail.com>
Date: Wed Dec 2 20:32:36 2026 +0100
Fix browser test config selection in wp-env hooks (#71719)
* Fix browser test config selection in wp-env hooks
* Add changelog entry for the wp-env hook fix
diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index 0f1cb08489a..5ef6e0283ee 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -151,7 +151,7 @@ Add the compatibility mu-plugin to the mappings in `.wp-env.json` and `.wp-env.t
}
```
-For single-site setups with WooCommerce, WooCommerce Gateway Dummy and the extension, add the lifecycle scripts above to catch commands that exit successfully without activating a plugin. The hooks use a POSIX shell. Pass `.wp-env.json` as the argument in the development config. The browser test site generator carries over the mapping and sets `WOO_EXTENSION_TOOLING_WP_ENV_CONFIG` in the generated hooks so they check `.wp-env.e2e.json`.
+For single-site setups with WooCommerce, WooCommerce Gateway Dummy and the extension, add the lifecycle scripts above to catch commands that exit successfully without activating a plugin. The hooks use a POSIX shell. Pass `.wp-env.json` as the argument in the development config. Use the quoted config argument exactly as shown in `.wp-env.test.json` so the browser test site generator can replace it with `.wp-env.e2e.json` in the generated hooks.
If the test config also mounts a repository directory at `wp-content/mu-plugins`, ignore `wp-cli-compatibility.php` in that directory. Docker creates an empty mount target there and loads the package's file in the container.
diff --git a/packages/js/extension-tooling/changelog/fix-wp-env-hook-config b/packages/js/extension-tooling/changelog/fix-wp-env-hook-config
new file mode 100644
index 00000000000..b1aaa0a33c8
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/fix-wp-env-hook-config
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Keep extension browser test setup from overriding environment variables in lifecycle hooks.
diff --git a/packages/js/extension-tooling/src/e2e-site-config.js b/packages/js/extension-tooling/src/e2e-site-config.js
index a8f4400b6b5..e6ec526431a 100644
--- a/packages/js/extension-tooling/src/e2e-site-config.js
+++ b/packages/js/extension-tooling/src/e2e-site-config.js
@@ -144,15 +144,15 @@ function writeE2ESiteConfig( {
delete developmentMappings?.[ debugLogMount ];
config.mappings[ debugLogMount ] = './tests/_output/e2e-debug.log';
- const cliConfigVariable = 'WOO_EXTENSION_TOOLING_WP_ENV_CONFIG';
+ const testConfigArgument =
+ '"${WOO_EXTENSION_TOOLING_WP_ENV_CONFIG:-.wp-env.test.json}"';
for ( const hook of [ 'afterStart', 'afterReset' ] ) {
const script = config.lifecycleScripts?.[ hook ];
- if (
- typeof script === 'string' &&
- script.includes( cliConfigVariable )
- ) {
- config.lifecycleScripts[ hook ] =
- `export ${ cliConfigVariable }=.wp-env.e2e.json\n${ script }`;
+ if ( typeof script === 'string' ) {
+ config.lifecycleScripts[ hook ] = script.replaceAll(
+ testConfigArgument,
+ '".wp-env.e2e.json"'
+ );
}
}
diff --git a/packages/js/extension-tooling/test/e2e-site-config.test.js b/packages/js/extension-tooling/test/e2e-site-config.test.js
index 15d7f33d9a1..01bac06d3c9 100644
--- a/packages/js/extension-tooling/test/e2e-site-config.test.js
+++ b/packages/js/extension-tooling/test/e2e-site-config.test.js
@@ -50,8 +50,9 @@ test( 'runs the activation check on the generated browser test site', ( context
const { root, pluginPath, defaults, input, output } = site( context );
const argument =
'"${WOO_EXTENSION_TOOLING_WP_ENV_CONFIG:-.wp-env.test.json}"';
+ const configVariable = 'WOO_EXTENSION_TOOLING_WP_ENV_CONFIG';
defaults.lifecycleScripts = {
- afterStart: `echo ready && printf '%s' ${ argument }`,
+ afterStart: `echo ready && printf '%s\\n' ${ argument } && printenv ${ configVariable }`,
afterReset: `printf '%s' ${ argument }`,
afterClean: 'echo unchanged',
};
@@ -62,15 +63,17 @@ test( 'runs the activation check on the generated browser test site', ( context
const { lifecycleScripts } = JSON.parse(
fs.readFileSync( output, 'utf8' )
);
- const run = ( script ) =>
- execFileSync( 'sh', [ '-c', script ], { encoding: 'utf8', env: {} } );
+ const run = ( script, env = {} ) =>
+ execFileSync( 'sh', [ '-c', script ], { encoding: 'utf8', env } );
assert.equal(
- run( defaults.lifecycleScripts.afterStart ),
- 'ready\n.wp-env.test.json'
+ run( defaults.lifecycleScripts.afterReset ),
+ '.wp-env.test.json'
);
assert.equal(
- run( lifecycleScripts.afterStart ),
- 'ready\n.wp-env.e2e.json'
+ run( lifecycleScripts.afterStart, {
+ [ configVariable ]: 'inherited.json',
+ } ),
+ 'ready\n.wp-env.e2e.json\ninherited.json\n'
);
assert.equal( run( lifecycleScripts.afterReset ), '.wp-env.e2e.json' );
assert.equal( lifecycleScripts.afterClean, 'echo unchanged' );
@@ -81,6 +84,7 @@ test( 'leaves hooks that do not opt into browser config selection unchanged', (
defaults.lifecycleScripts = {
afterStart:
"echo 'Run woo-extension-tooling check-wp-env-plugins .wp-env.test.json separately'",
+ afterReset: "echo 'WOO_EXTENSION_TOOLING_WP_ENV_CONFIG'",
};
fs.writeFileSync( input, JSON.stringify( defaults ) );