Commit c3d027a5e67 for woocommerce
commit c3d027a5e671e95919dad44d485ba45cc82bc809
Author: Ján Mikláš <neosinner@gmail.com>
Date: Wed Nov 18 23:23:55 2026 +0100
Share Playwright defaults for extensions (#71114)
* build: share extension Playwright defaults
* docs: log shared Playwright defaults
diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index f52f06606ba..65f57bdb295 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -61,6 +61,25 @@ Set `EXTENSION_TOOLING_BIN` to the absolute path of that `bin` directory. The in
The Bash ZIP command works without Node.js when `config.woo.zip.build` is empty and the extension's staging hook and Composer scripts, if present, also work on that host.
+## Playwright configuration defaults
+
+Use the shared defaults in `tests/e2e/playwright.config.js` with the extension's installed Playwright. The helper supplies the browser site URL, CI retries, focused-test checks, failure artifacts, timeouts, and reporters. Pass paths relative to your Playwright config or absolute paths. Omit `jsonReport` for suites that produce only HTML reports.
+
+```js
+const { defineConfig } = require( '@playwright/test' );
+const playwrightDefaults = require( '@woocommerce/extension-tooling/playwright-defaults' );
+
+module.exports = defineConfig( playwrightDefaults( {
+ htmlReport: './test-results/playwright-report',
+ jsonReport: './test-results/results.json',
+} ), {
+ testDir: './specs',
+ workers: 1,
+} );
+```
+
+Use the second config to set suite-specific projects, worker limits, storage state, and overrides.
+
## Webpack
Import the helpers from the extension's webpack configuration. Keep the entry paths, output paths and match patterns in that configuration.
diff --git a/packages/js/extension-tooling/changelog/shared-extension-playwright-defaults b/packages/js/extension-tooling/changelog/shared-extension-playwright-defaults
new file mode 100644
index 00000000000..7b85cad6215
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/shared-extension-playwright-defaults
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Share Playwright configuration defaults across extension suites.
diff --git a/packages/js/extension-tooling/package.json b/packages/js/extension-tooling/package.json
index 643554c4196..e9551c4bae7 100644
--- a/packages/js/extension-tooling/package.json
+++ b/packages/js/extension-tooling/package.json
@@ -17,6 +17,7 @@
"./webpack-dist-minify": "./src/webpack-dist-minify.js",
"./webpack-text-includes": "./src/webpack-text-includes.js",
"./check-i18n": "./src/check-i18n.js",
+ "./playwright-defaults": "./src/playwright-defaults.js",
"./e2e-site-config": "./src/e2e-site-config.js",
"./stylelint/legacy-scss": "./configs/stylelint-legacy-scss.json"
},
diff --git a/packages/js/extension-tooling/src/playwright-defaults.js b/packages/js/extension-tooling/src/playwright-defaults.js
new file mode 100644
index 00000000000..43f0751d877
--- /dev/null
+++ b/packages/js/extension-tooling/src/playwright-defaults.js
@@ -0,0 +1,36 @@
+/**
+ * Build shared Playwright settings for a WooCommerce extension's browser suite.
+ *
+ * @param {Object} options Reporter paths and environment.
+ * @param {string} options.htmlReport HTML report directory.
+ * @param {string} [options.jsonReport] JSON report path, if needed in CI.
+ * @param {NodeJS.ProcessEnv} [options.env] Environment, defaults to process.env.
+ * @return {Object} Playwright configuration to compose with suite settings.
+ */
+module.exports = function playwrightDefaults( {
+ htmlReport,
+ jsonReport,
+ env = process.env,
+} ) {
+ return {
+ timeout: 60_000,
+ expect: { timeout: 10_000 },
+ forbidOnly: !! env.CI,
+ retries: env.CI ? 1 : 0,
+ reporter: [
+ [ 'list' ],
+ ...( env.GITHUB_ACTIONS ? [ [ 'github' ] ] : [] ),
+ [ 'html', { outputFolder: htmlReport, open: 'never' } ],
+ ...( env.CI && jsonReport
+ ? [ [ 'json', { outputFile: jsonReport } ] ]
+ : [] ),
+ ],
+ use: {
+ baseURL:
+ env.WP_BASE_URL ||
+ `http://localhost:${ env.WP_ENV_TESTS_PORT || 8889 }`,
+ trace: 'retain-on-failure',
+ screenshot: 'only-on-failure',
+ },
+ };
+};
diff --git a/packages/js/extension-tooling/test/playwright-defaults.test.js b/packages/js/extension-tooling/test/playwright-defaults.test.js
new file mode 100644
index 00000000000..bb1fee343ce
--- /dev/null
+++ b/packages/js/extension-tooling/test/playwright-defaults.test.js
@@ -0,0 +1,71 @@
+const assert = require( 'node:assert/strict' );
+const test = require( 'node:test' );
+const playwrightDefaults = require( '@woocommerce/extension-tooling/playwright-defaults' );
+
+test( 'uses local defaults and writes only the configured HTML report', () => {
+ assert.deepEqual(
+ playwrightDefaults( {
+ htmlReport: './test-results/playwright-report',
+ jsonReport: './test-results/results.json',
+ env: { WP_ENV_TESTS_PORT: '8897' },
+ } ),
+ {
+ timeout: 60_000,
+ expect: { timeout: 10_000 },
+ forbidOnly: false,
+ retries: 0,
+ reporter: [
+ [ 'list' ],
+ [
+ 'html',
+ {
+ outputFolder: './test-results/playwright-report',
+ open: 'never',
+ },
+ ],
+ ],
+ use: {
+ baseURL: 'http://localhost:8897',
+ trace: 'retain-on-failure',
+ screenshot: 'only-on-failure',
+ },
+ }
+ );
+} );
+
+test( 'keeps an explicit URL and enables the selected CI reports', () => {
+ const options = {
+ htmlReport: '/tmp/e2e results/html',
+ jsonReport: '/tmp/e2e results/results.json',
+ env: {
+ CI: 'true',
+ GITHUB_ACTIONS: 'true',
+ WP_BASE_URL: 'http://example.test:8894/subdirectory/',
+ WP_ENV_TESTS_PORT: '8897',
+ },
+ };
+ const config = playwrightDefaults( options );
+ assert.equal( config.forbidOnly, true );
+ assert.equal( config.retries, 1 );
+ assert.equal( config.use.baseURL, options.env.WP_BASE_URL );
+ assert.deepEqual( config.reporter, [
+ [ 'list' ],
+ [ 'github' ],
+ [ 'html', { outputFolder: options.htmlReport, open: 'never' } ],
+ [ 'json', { outputFile: options.jsonReport } ],
+ ] );
+ assert.deepEqual(
+ playwrightDefaults( { ...options, jsonReport: undefined } ).reporter,
+ config.reporter.slice( 0, -1 )
+ );
+} );
+
+test( 'can enable GitHub annotations independently of CI mode', () => {
+ const config = playwrightDefaults( {
+ htmlReport: './test-results/playwright-report',
+ env: { GITHUB_ACTIONS: 'true' },
+ } );
+ assert.equal( config.use.baseURL, 'http://localhost:8889' );
+ assert.equal( config.retries, 0 );
+ assert.deepEqual( config.reporter[ 1 ], [ 'github' ] );
+} );