Skip to content

Migrate off deprecated wp-env tests environment#2505

Merged
westonruter merged 4 commits into
trunkfrom
fix/2437-wp-env-tests-deprecation
Jun 4, 2026
Merged

Migrate off deprecated wp-env tests environment#2505
westonruter merged 4 commits into
trunkfrom
fix/2437-wp-env-tests-deprecation

Conversation

@westonruter

Copy link
Copy Markdown
Member

Summary

Fixes #2437.

@wordpress/env now deprecates starting both a development and a tests environment by default, and deprecates the env, testsPort, and testsEnvironment options. npm run wp-env start prints:

⚠ 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.

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.json is 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 port 8889, started via --config.

A separate config file is required (rather than collapsing to one environment) to preserve test isolation. With "testsEnvironment": false, wp-env generates wp-tests-config.php from the environment's own wp-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 is md5(configPath)), which is exactly what the old tests-cli / tests-mysql services provided.

Changes

  • Split .wp-env.json; add .wp-env.test.json (port 8889, matching the default Playwright base URL).
  • Add a wp-env-test npm script (shorthand for wp-env --config=.wp-env.test.json).
  • Point all test-php* scripts and bin/test-php-watch.sh at the tests environment via the cli container (replacing the removed tests-cli).
  • Update CI: php-test-plugins.yml and e2e-test.yml start and run against the tests env; copilot-setup-steps.yml starts both. plugin-check.yml already used "testsEnvironment": false.
  • Git-ignore .wp-env.test.override.json for local test-env overrides.
  • Document the two-environment workflow in AGENTS.md.

Testing

  • Both config files validate against the wp-env JSON schema.
  • After reconfiguring, the development environment's generated docker-compose.yml contains only mysql/wordpress/cli/phpmyadmin (no tests-* services), it boots cleanly, and npm run wp-env start no longer emits the deprecation warning (the warning is gated on config.testsEnvironment !== false).
  • CI (php-test-plugins, e2e-test) exercises the tests environment end to end.

🤖 Generated with Claude Code

`@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>
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs labels Jun 3, 2026
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>
@westonruter westonruter marked this pull request as draft June 3, 2026 13:37
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.29%. Comparing base (f5222f4) to head (3659e9a).
⚠️ Report is 13 commits behind head on trunk.

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           
Flag Coverage Δ
multisite 69.29% <ø> (ø)
single 35.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter marked this pull request as ready for review June 3, 2026 13:49
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>

@adamsilverstein adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment on lines +67 to +68
npm run wp-env start
npm run wp-env-test start

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 3659e9a

Comment thread .wp-env.json
Comment on lines -26 to -28
"mappings": {
"wp-content/plugins/performance": "."
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this mapping in non test env now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .wp-env.test.json
@@ -0,0 +1,26 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"testsEnvironment": false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed from both configs given it's deprecated and false by default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@westonruter westonruter merged commit a2815e6 into trunk Jun 4, 2026
29 of 30 checks passed
@westonruter westonruter deleted the fix/2437-wp-env-tests-deprecation branch June 4, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning for wp-env tests environment

4 participants