From 11f6279ed08bfa07a8d435fb706d9299ecb23aa3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 3 Jun 2026 14:41:15 +0200 Subject: [PATCH 1/4] Migrate off deprecated wp-env tests environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `@wordpress/env` has deprecated starting both a development and a tests environment by default, along with the `env`, `testsPort`, and `testsEnvironment` options. Running `npm run wp-env start` now prints a deprecation warning, and the legacy dual-environment startup path is slated for removal. Split the single dual-environment `.wp-env.json` into two flat, single-environment configs (each with `"testsEnvironment": false`), mirroring the approach used in the Gutenberg repository: * `.wp-env.json` — the development/browsing environment. * `.wp-env.test.json` — an isolated tests environment on port 8889, started via `--config`. Because each config file gets its own Docker containers and database, this preserves the test isolation that the old `tests-cli`/`tests-mysql` services provided (the WordPress PHPUnit suite resets its database on every run). The `test-php*` scripts, the `test-php-watch` helper, and the CI workflows now target the tests environment through a new `wp-env-test` script (shorthand for `wp-env --config=.wp-env.test.json`). A matching `.wp-env.test.override.json` is git-ignored for local overrides, and AGENTS.md documents the two-environment workflow. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/copilot-setup-steps.yml | 6 ++- .github/workflows/e2e-test.yml | 2 +- .github/workflows/php-test-plugins.yml | 6 +-- .gitignore | 1 + .wp-env.json | 17 ++------- .wp-env.test.json | 24 ++++++++++++ AGENTS.md | 20 +++++++--- bin/test-php-watch.sh | 2 +- package.json | 45 ++++++++++++----------- 9 files changed, 75 insertions(+), 48 deletions(-) create mode 100644 .wp-env.test.json diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 473f0bfc8b..54c63d7f55 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -62,5 +62,7 @@ jobs: run: composer install --no-interaction --no-progress - name: Build assets run: npm run build - - name: Install WordPress and start environment - run: npm run wp-env start + - name: Install WordPress and start environments + run: | + npm run wp-env start + npm run wp-env-test -- start diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index a7e864803e..236330f325 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -57,7 +57,7 @@ jobs: run: npx playwright install chromium --with-deps - name: Install WordPress - run: npm run wp-env start + run: npm run wp-env-test -- start - name: Run tests env: diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 25324e324e..88edeeaa4c 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -85,12 +85,12 @@ jobs: - name: Install WordPress run: | if [ "${{ matrix.coverage }}" == "true" ]; then - npm run wp-env start -- --xdebug=coverage + npm run wp-env-test -- start --xdebug=coverage else - npm run wp-env start + npm run wp-env-test -- start fi - name: Composer Install - run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress + run: npm run wp-env-test -- run cli --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress - name: Update Composer Dependencies run: composer update --with-all-dependencies --no-interaction --no-progress - name: Install PHPUnit diff --git a/.gitignore b/.gitignore index 4f52de6bab..5b8808d022 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ nbproject/ build .wp-env.override.json +.wp-env.test.override.json *.min.js *.min.css *.asset.php diff --git a/.wp-env.json b/.wp-env.json index 7e0511af4c..2dbd5c790a 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/wp-env.json", + "testsEnvironment": false, "core": null, "plugins": [ "./plugins/optimization-detective", @@ -13,19 +14,7 @@ "./plugins/web-worker-offloading", "./plugins/webp-uploads" ], - "env": { - "development": { - "config": { - "WP_DEVELOPMENT_MODE": "plugin" - } - }, - "tests": { - "config": { - "FS_METHOD": "direct" - }, - "mappings": { - "wp-content/plugins/performance": "." - } - } + "config": { + "WP_DEVELOPMENT_MODE": "plugin" } } diff --git a/.wp-env.test.json b/.wp-env.test.json new file mode 100644 index 0000000000..622269db11 --- /dev/null +++ b/.wp-env.test.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://schemas.wp.org/trunk/wp-env.json", + "testsEnvironment": false, + "port": 8889, + "core": null, + "plugins": [ + "./plugins/optimization-detective", + "./plugins/auto-sizes", + "./plugins/dominant-color-images", + "./plugins/embed-optimizer", + "./plugins/image-prioritizer", + "./plugins/performance-lab", + "./plugins/speculation-rules", + "./plugins/view-transitions", + "./plugins/web-worker-offloading", + "./plugins/webp-uploads" + ], + "config": { + "FS_METHOD": "direct" + }, + "mappings": { + "wp-content/plugins/performance": "." + } +} diff --git a/AGENTS.md b/AGENTS.md index 23e8aa05b9..a6e8096109 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,13 +38,23 @@ This is a monorepo for the WordPress Performance Team, containing a collection o ### Running a Local Environment -This project uses `@wordpress/env` to create a local development environment. +This project uses `@wordpress/env` to create local environments. There are two, +each defined by its own config file and running as fully isolated containers: -* Check if the environment is already running: `npm run wp-env status` -* Start the environment: `npm run wp-env start` -* Stop the environment: `npm run wp-env stop` +* **Development** (for browsing) — `.wp-env.json`, at `http://localhost:8888`. +* **Tests** (for PHPUnit and E2E) — `.wp-env.test.json`, at `http://localhost:8889`. -The environment will by default be located at `http://localhost:8888` but this can be overridden by `.wp-env.override.json`. +The `wp-env-test` script is shorthand for `wp-env --config=.wp-env.test.json`. + +* Check if the environments are running: `npm run wp-env status` / `npm run wp-env-test -- status` +* Start the environments: `npm run wp-env start` / `npm run wp-env-test -- start` +* Stop the environments: `npm run wp-env stop` / `npm run wp-env-test -- stop` + +The `test-php*` and `test-e2e*` scripts run against the tests environment, so +start it with `npm run wp-env-test -- start` before running them. + +Each environment can be overridden locally (these files are git-ignored): +`.wp-env.override.json` for development and `.wp-env.test.override.json` for tests. ## Code Style diff --git a/bin/test-php-watch.sh b/bin/test-php-watch.sh index 7ddbe3c966..1dbfd13e2d 100755 --- a/bin/test-php-watch.sh +++ b/bin/test-php-watch.sh @@ -29,5 +29,5 @@ while true; do echo "Running phpunit tests for $(tput bold)$plugin_slug$(tput sgr0):" # TODO: Interrupt when a change is made while running tests or re-run if change made since tests started running. # Note: This is calling phpunit directly and not the composer script due to extra noise it outputs. - npm run wp-env --silent -- run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance -- vendor/bin/phpunit --testsuite "$plugin_slug" "$@" + npm run wp-env-test --silent -- run cli --env-cwd=/var/www/html/wp-content/plugins/performance -- vendor/bin/phpunit --testsuite "$plugin_slug" "$@" done diff --git a/package.json b/package.json index cfd5dcd534..fad9326fec 100644 --- a/package.json +++ b/package.json @@ -65,31 +65,32 @@ "test-e2e:debug": "wp-scripts test-playwright --config tools/e2e/playwright.config.ts --ui", "test-e2e:auto-sizes": "wp-scripts test-playwright --config tools/e2e/playwright.config.ts --project=auto-sizes", "lint-php": "composer lint:all", - "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins", + "test-php": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins", "test-php-watch": "./bin/test-php-watch.sh", - "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins", - "test-php:performance-lab": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:performance-lab", - "test-php:auto-sizes": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:auto-sizes", - "test-php:dominant-color-images": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:dominant-color-images", - "test-php:embed-optimizer": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:embed-optimizer", - "test-php:image-prioritizer": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:image-prioritizer", - "test-php:optimization-detective": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:optimization-detective", - "test-php:speculation-rules": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:speculation-rules", - "test-php:view-transitions": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:view-transitions", - "test-php:web-worker-offloading": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:web-worker-offloading", - "test-php:webp-uploads": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:webp-uploads", - "test-php-multisite:performance-lab": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:performance-lab", - "test-php-multisite:auto-sizes": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:auto-sizes", - "test-php-multisite:dominant-color-images": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:dominant-color-images", - "test-php-multisite:embed-optimizer": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:embed-optimizer", - "test-php-multisite:image-prioritizer": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:image-prioritizer", - "test-php-multisite:optimization-detective": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:optimization-detective", - "test-php-multisite:speculation-rules": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:speculation-rules", - "test-php-multisite:view-transitions": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:view-transitions", - "test-php-multisite:web-worker-offloading": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:web-worker-offloading", - "test-php-multisite:webp-uploads": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:webp-uploads", + "test-php-multisite": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins", + "test-php:performance-lab": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:performance-lab", + "test-php:auto-sizes": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:auto-sizes", + "test-php:dominant-color-images": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:dominant-color-images", + "test-php:embed-optimizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:embed-optimizer", + "test-php:image-prioritizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:image-prioritizer", + "test-php:optimization-detective": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:optimization-detective", + "test-php:speculation-rules": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:speculation-rules", + "test-php:view-transitions": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:view-transitions", + "test-php:web-worker-offloading": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:web-worker-offloading", + "test-php:webp-uploads": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:webp-uploads", + "test-php-multisite:performance-lab": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:performance-lab", + "test-php-multisite:auto-sizes": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:auto-sizes", + "test-php-multisite:dominant-color-images": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:dominant-color-images", + "test-php-multisite:embed-optimizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:embed-optimizer", + "test-php-multisite:image-prioritizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:image-prioritizer", + "test-php-multisite:optimization-detective": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:optimization-detective", + "test-php-multisite:speculation-rules": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:speculation-rules", + "test-php-multisite:view-transitions": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:view-transitions", + "test-php-multisite:web-worker-offloading": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:web-worker-offloading", + "test-php-multisite:webp-uploads": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:webp-uploads", "update-test-case-snapshots": "bin/update-test-case-snapshots.sh", "wp-env": "wp-env", + "wp-env-test": "wp-env --config=.wp-env.test.json", "prepare": "husky" } } From 97c5e31e113316e490a7bd7a851dfe7873115e99 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 3 Jun 2026 15:36:14 +0200 Subject: [PATCH 2/4] Disable WP_DEBUG and SCRIPT_DEBUG in the tests environment The deprecated `tests` environment defaulted both `WP_DEBUG` and `SCRIPT_DEBUG` to `false`. The new single-environment `.wp-env.test.json` is treated as a development environment, which defaults them to `true`. With `SCRIPT_DEBUG` enabled, plugins enqueue their unminified source assets, so the `?ver=__VERSION__` placeholder appears in the markup and the snapshot assertions fail. Set both constants to `false` in the tests config to restore the old behavior, matching what the Gutenberg repository does in its `.wp-env.test.json`. Co-Authored-By: Claude Opus 4.8 (1M context) --- .wp-env.test.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.wp-env.test.json b/.wp-env.test.json index 622269db11..6df028964c 100644 --- a/.wp-env.test.json +++ b/.wp-env.test.json @@ -16,6 +16,8 @@ "./plugins/webp-uploads" ], "config": { + "WP_DEBUG": false, + "SCRIPT_DEBUG": false, "FS_METHOD": "direct" }, "mappings": { From 8540d1f652b2c92b540536bf019857a54d8c88fa Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 4 Jun 2026 01:08:41 +0200 Subject: [PATCH 3/4] Drop redundant `--` before bare wp-env-test subcommands Use `npm run wp-env-test start` (etc.) to match the existing `npm run wp-env start` convention, keeping `--` only where a flag is passed through to wp-env (e.g. `start -- --xdebug=coverage`, `run cli -- --env-cwd=...`). Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/copilot-setup-steps.yml | 2 +- .github/workflows/e2e-test.yml | 2 +- .github/workflows/php-test-plugins.yml | 6 +++--- AGENTS.md | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 54c63d7f55..ca5d9e87d9 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -65,4 +65,4 @@ jobs: - name: Install WordPress and start environments run: | npm run wp-env start - npm run wp-env-test -- start + npm run wp-env-test start diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 236330f325..df1c122803 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -57,7 +57,7 @@ jobs: run: npx playwright install chromium --with-deps - name: Install WordPress - run: npm run wp-env-test -- start + run: npm run wp-env-test start - name: Run tests env: diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 88edeeaa4c..294848e6d3 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -85,12 +85,12 @@ jobs: - name: Install WordPress run: | if [ "${{ matrix.coverage }}" == "true" ]; then - npm run wp-env-test -- start --xdebug=coverage + npm run wp-env-test start -- --xdebug=coverage else - npm run wp-env-test -- start + npm run wp-env-test start fi - name: Composer Install - run: npm run wp-env-test -- run cli --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress + run: npm run wp-env-test run cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress - name: Update Composer Dependencies run: composer update --with-all-dependencies --no-interaction --no-progress - name: Install PHPUnit diff --git a/AGENTS.md b/AGENTS.md index a6e8096109..0a973ee2fc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,12 +46,12 @@ each defined by its own config file and running as fully isolated containers: The `wp-env-test` script is shorthand for `wp-env --config=.wp-env.test.json`. -* Check if the environments are running: `npm run wp-env status` / `npm run wp-env-test -- status` -* Start the environments: `npm run wp-env start` / `npm run wp-env-test -- start` -* Stop the environments: `npm run wp-env stop` / `npm run wp-env-test -- stop` +* Check if the environments are running: `npm run wp-env status` / `npm run wp-env-test status` +* Start the environments: `npm run wp-env start` / `npm run wp-env-test start` +* Stop the environments: `npm run wp-env stop` / `npm run wp-env-test stop` The `test-php*` and `test-e2e*` scripts run against the tests environment, so -start it with `npm run wp-env-test -- start` before running them. +start it with `npm run wp-env-test start` before running them. Each environment can be overridden locally (these files are git-ignored): `.wp-env.override.json` for development and `.wp-env.test.override.json` for tests. From 3659e9a3b9aaf0e7b1f997f8f748647efc2b6a76 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 4 Jun 2026 10:50:57 +0200 Subject: [PATCH 4/4] Start dev and tests envs in parallel Co-authored-by: thelovekesh --- .github/workflows/copilot-setup-steps.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index ca5d9e87d9..e4923fd6bc 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -64,5 +64,11 @@ jobs: run: npm run build - name: Install WordPress and start environments run: | - npm run wp-env start - npm run wp-env-test start + set -euo pipefail + trap 'kill 0' ERR + + npm run wp-env start & + npm run wp-env-test start & + + wait -n + wait -n