Migrate off deprecated wp-env tests environment#2505
Conversation
`@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) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2505 +/- ##
=======================================
Coverage 69.29% 69.29%
=======================================
Files 90 90
Lines 7723 7723
=======================================
Hits 5352 5352
Misses 2371 2371
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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) <noreply@anthropic.com>
| npm run wp-env start | ||
| npm run wp-env-test start |
There was a problem hiding this comment.
can be run in parallel
set -euo pipefail
trap 'kill 0' ERR
npm run wp-env start &
npm run wp-env-test start &
wait -n
wait -n| "mappings": { | ||
| "wp-content/plugins/performance": "." | ||
| } |
There was a problem hiding this comment.
we don't need this mapping in non test env now?
There was a problem hiding this comment.
Not sure. You added this mapping for tests in db957d4 and it remains for tests in this PR, but it was moved to the .wp-env.test.json config.
There was a problem hiding this comment.
oh it was there to map root files in the container since it was having test data files etc. maybe not required in runtime, and just only in tests.
| @@ -0,0 +1,26 @@ | |||
| { | |||
| "$schema": "https://schemas.wp.org/trunk/wp-env.json", | |||
| "testsEnvironment": false, | |||
There was a problem hiding this comment.
can be removed from both configs given it's deprecated and false by default
There was a problem hiding this comment.
This doesn't seem to be the case, currently.
I tried removing this, and I got the warning:
⚠ Warning: wp-env starts both development and tests environments by default.
This behavior is deprecated and will be removed in a future version.
To avoid this warning, add "testsEnvironment": false to your .wp-env.json.
The "env", "testsPort", and "testsEnvironment" options are also deprecated.
Use the --config option with a separate config file for test environments instead.
Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org>
Summary
Fixes #2437.
@wordpress/envnow deprecates starting both a development and a tests environment by default, and deprecates theenv,testsPort, andtestsEnvironmentoptions.npm run wp-env startprints:Approach
This follows the precedent set in the Gutenberg repository, which owns
@wordpress/env(.wp-env.json+.wp-env.test.json, each with"testsEnvironment": false, wired via--config).The single dual-environment
.wp-env.jsonis split into two flat, single-environment configs:.wp-env.json— the development / browsing environment (http://localhost:8888)..wp-env.test.json— an isolated tests environment on port8889, started via--config.A separate config file is required (rather than collapsing to one environment) to preserve test isolation. With
"testsEnvironment": false, wp-env generateswp-tests-config.phpfrom the environment's ownwp-config.php, so the WordPress PHPUnit suite — which resets its database on every run — would otherwise wipe the development site. Each config file gets its own isolated Docker containers and database (its work dir ismd5(configPath)), which is exactly what the oldtests-cli/tests-mysqlservices provided.Changes
.wp-env.json; add.wp-env.test.json(port8889, matching the default Playwright base URL).wp-env-testnpm script (shorthand forwp-env --config=.wp-env.test.json).test-php*scripts andbin/test-php-watch.shat the tests environment via theclicontainer (replacing the removedtests-cli).php-test-plugins.ymlande2e-test.ymlstart and run against the tests env;copilot-setup-steps.ymlstarts both.plugin-check.ymlalready used"testsEnvironment": false..wp-env.test.override.jsonfor local test-env overrides.AGENTS.md.Testing
docker-compose.ymlcontains onlymysql/wordpress/cli/phpmyadmin(notests-*services), it boots cleanly, andnpm run wp-env startno longer emits the deprecation warning (the warning is gated onconfig.testsEnvironment !== false).php-test-plugins,e2e-test) exercises the tests environment end to end.🤖 Generated with Claude Code