Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@
"storybook:manifest-snapshot": "npm run --workspace @wordpress/storybook manifest-snapshot",
"test": "npm run lint && npm run test:unit",
"test:create-block": "npm run --workspace @wordpress/validation-tools test-create-block --",
"test:e2e": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.config.ts",
"test:e2e:debug": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.config.ts --ui",
"test:e2e": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.config.ts --wp-env-config=../../.wp-env.test.json",
"test:e2e:debug": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.config.ts --wp-env-config=../../.wp-env.test.json --ui",
"test:e2e:playwright": "npm run test:e2e",
"test:e2e:playwright:debug": "npm run test:e2e:debug",
"test:e2e:rtc-websocket": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.rtc-websocket.config.ts",
"test:e2e:rtc-websocket:debug": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --ui",
"test:e2e:rtc-websocket": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --wp-env-config=../../.wp-env.test.json",
"test:e2e:rtc-websocket:debug": "npm exec --no --workspace @wordpress/e2e-tests-playwright -- wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --wp-env-config=../../.wp-env.test.json --ui",
"test:e2e:storybook": "npm exec --no --workspace @wordpress/storybook-playwright -- playwright test --config playwright.config.ts",
"test:e2e:watch": "npm run test:e2e -- --watch",
"test:performance": "npm exec --no --workspace @wordpress/performance-tests -- wp-scripts test-e2e --config playwright.config.ts",
Expand Down
8 changes: 8 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

- Update the bundled `webpack-dev-server` from `^5.2.1` to `^6.0.0` and `@pmmmwh/react-refresh-webpack-plugin` from `^0.5.11` to `^0.6.3`. Custom `devServer` configs need migrating: SockJS is removed, so drop `webSocketServer: 'sockjs'` and `client.webSocketTransport: 'sockjs'` to use the default `ws`; the proxy `bypass` option is removed in favor of `http-proxy-middleware`'s `context` or `router`; custom middleware runs on Express 5; and `getFilenameFromUrl()` is now asynchronous. See the [webpack-dev-server 6.0.0 release notes](https://github.com/webpack/webpack-dev-server/releases/tag/v6.0.0) ([#84674](https://github.com/WordPress/gutenberg/pull/84674)).

### Enhancements

- `test-e2e` and `test-playwright`: Add a `--wp-env-config` option for the custom config file that the environment for the tests is started from with `wp-env --config`, such as `.wp-env.test.json`. When `WP_BASE_URL` is not set, the tests run on the port from that file merged with its override file, such as `.wp-env.test.override.json`, and any `WP_ENV_*` environment variables ([#84654](https://github.com/WordPress/gutenberg/pull/84654)).

### Bug Fixes

- `test-e2e` and `test-playwright`: When `WP_BASE_URL` is not set and the `wp-env` config disables the tests environment with `"testsEnvironment": false`, run the tests on the port of the development environment instead of falling back to `http://localhost:8889`, which may belong to another project's environment ([#84654](https://github.com/WordPress/gutenberg/pull/84654)).

## 36.1.0 (2026-10-07)

### Enhancements
Expand Down
15 changes: 15 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,21 @@ By default, Playwright looks for JavaScript or TypeScript files with `.test` or
This script automatically detects the best config to start Playwright, but sometimes you may need to specify custom options.
To do so, you can add a file called `playwright.config.ts` or `playwright.config.js` in the top-level directory of your package (at the same level as your `package.json`).

#### Test Environment

The tests run against the site at the `WP_BASE_URL` environment variable. When it is not set and [`@wordpress/env`](https://www.npmjs.com/package/@wordpress/env) is installed, they run against the `wp-env` environment configured in the current directory: its tests environment if the config enables one, and otherwise its development environment. As with `wp-env start`, the port comes from `.wp-env.json` merged with `.wp-env.override.json` and any `WP_ENV_*` environment variables, so each project can have its own ports. Without either, the tests run against `http://localhost:8889`.

If you start the environment for the tests from a custom config file with `wp-env --config`, pass the same file with `--wp-env-config=<path>`. Its path is resolved relative to the current directory, as with `wp-env --config`, and its override file is merged in too, for example `.wp-env.test.override.json` for `.wp-env.test.json`:

```json
{
"scripts": {
"env:test": "wp-env --config .wp-env.test.json",
"test:e2e": "wp-scripts test-e2e --wp-env-config=.wp-env.test.json"
}
}
```

#### Failed Test Artifacts

When tests fail, snapshots will be taken of the page and stored in the `artifacts/` directory at the root of your project. These snapshots may help debug failed tests during development or when running tests in a CI environment.
Expand Down
35 changes: 29 additions & 6 deletions packages/scripts/scripts/test-playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,33 @@ const {
fromConfigRoot,
hasProjectFile,
hasArgInCLI,
getArgFromCLI,
getArgsFromCLI,
getAsBooleanFromENV,
} = require( '../utils' );

const wpEnvConfig = getArgFromCLI( '--wp-env-config' );

if ( wpEnvConfig === null ) {
console.error(
'Error: The --wp-env-config option requires the path to a wp-env config file, as in --wp-env-config=<path>.'
);
process.exit( 1 );
}

// Playwright rejects options it does not know.
const playwrightArgs = getArgsFromCLI().filter(
( arg ) => arg.split( '=' )[ 0 ] !== '--wp-env-config'
);

/**
* @typedef {import('../../env/lib/config/load-config').WPConfig} WPConfig
*/

/**
* Loads any configuration from a given directory.
*
* @type {(configDirectoryPath: string) => Promise<WPConfig> | null}
* @type {(configDirectoryPath: string, customConfigPath?: string|null) => Promise<WPConfig> | null}
*/
let loadConfig = null;

Expand Down Expand Up @@ -72,7 +87,7 @@ function spawnProcess() {
require.resolve( '@playwright/test/cli' ),
'test',
...config,
...getArgsFromCLI(),
...playwrightArgs,
],
{
stdio: 'inherit',
Expand All @@ -84,10 +99,18 @@ function spawnProcess() {
}
}

if ( loadConfig ) {
loadConfig( resolve( '.' ) ).then( ( envConfig ) => {
if ( ! process.env.WP_BASE_URL && envConfig?.env?.tests?.port ) {
process.env.WP_BASE_URL = `http://localhost:${ envConfig.env.tests.port }`;
if ( loadConfig && ! process.env.WP_BASE_URL ) {
// As with `wp-env start`, this merges in the override file of the config
// (such as `.wp-env.test.override.json` for `.wp-env.test.json`) and any
// `WP_ENV_*` environment variables. Versions of `@wordpress/env` before
// support for `--config` ignore the custom config path.
loadConfig( resolve( '.' ), wpEnvConfig ).then( ( envConfig ) => {
// A config without the deprecated tests environment has only the
// development environment to run the tests against.
const port =
envConfig?.env?.tests?.port ?? envConfig?.env?.development?.port;
if ( port ) {
process.env.WP_BASE_URL = `http://localhost:${ port }`;
}
spawnProcess();
} );
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
},
"scripts": {
"test:e2e:update-timings": "flakiness-playwright-timings fetch -c ./playwright.config.ts -o timings.json",
"test:e2e": "wp-scripts test-e2e --config playwright.config.ts",
"test:e2e:debug": "wp-scripts test-e2e --config playwright.config.ts --ui",
"test:e2e:rtc-websocket": "wp-scripts test-e2e --config playwright.rtc-websocket.config.ts",
"test:e2e:rtc-websocket:debug": "wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --ui",
"test:e2e:site-editor-v2": "wp-scripts test-e2e --config playwright.site-editor-v2.config.ts",
"test:e2e:site-editor-v2:debug": "wp-scripts test-e2e --config playwright.site-editor-v2.config.ts --ui"
"test:e2e": "wp-scripts test-e2e --config playwright.config.ts --wp-env-config=../../.wp-env.test.json",
"test:e2e:debug": "wp-scripts test-e2e --config playwright.config.ts --wp-env-config=../../.wp-env.test.json --ui",
"test:e2e:rtc-websocket": "wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --wp-env-config=../../.wp-env.test.json",
"test:e2e:rtc-websocket:debug": "wp-scripts test-e2e --config playwright.rtc-websocket.config.ts --wp-env-config=../../.wp-env.test.json --ui",
"test:e2e:site-editor-v2": "wp-scripts test-e2e --config playwright.site-editor-v2.config.ts --wp-env-config=../../.wp-env.test.json",
"test:e2e:site-editor-v2:debug": "wp-scripts test-e2e --config playwright.site-editor-v2.config.ts --wp-env-config=../../.wp-env.test.json --ui"
}
}
Loading