Skip to content

Add wp-env support for running integration tests across all Yoast plugins #23107

@enricobattocchi

Description

@enricobattocchi

Problem

Running WordPress integration tests locally requires a complex manual setup as documented on developer.yoast.com:

  1. Clone WordPress/wordpress-develop separately
  2. Build and start the environment (npm install && npm run build:dev && npm run env:start && npm run env:install)
  3. Expose MySQL via network aliases requiring sudo (sudo ifconfig lo:0 10.254.254.254 on Linux, sudo ifconfig lo0 alias 10.254.254.254 on macOS)
  4. Configure WP_DEVELOP_DIR and WP_PLUGIN_DIR environment variables
  5. Run composer test-wp

This manual process:

  • Blocks AI agents from running integration tests autonomously (they can't execute sudo or configure network interfaces)
  • Slows down onboarding for new developers
  • Requires platform-specific steps (different ifconfig syntax per OS)

Solution

Use @wordpress/env (wp-env) to provide a self-contained Docker-based test environment that can be started and used with a single command: composer test-wp-env.

The wp-env setup handles everything automatically:

  • Starts WordPress + MySQL in Docker containers
  • Mounts the plugin directory automatically
  • Provides the WordPress PHPUnit test framework at /wordpress-phpunit/
  • Supports --php, --wp, --multisite, --coverage flags
  • Patches wp-tests-config.php at runtime to fix three wp-env defaults that differ from the standard install-wp-tests.sh setup (WP_HOME/WP_SITEURL, WP_TESTS_DOMAIN, WP_ENVIRONMENT_TYPE)

Plugins to update

All Yoast plugins with WordPress integration tests need this setup:

Additional considerations

  • Windows support: The current implementation uses a bash script. Developers on Windows without WSL cannot run it natively. A follow-up could convert the script to PHP for cross-platform support.
  • Node.js version: @wordpress/env requires Node >= 20.10.0. The .nvmrc needs to be bumped from 18 to 20 in each plugin.
  • Documentation: Update developer.yoast.com setup guide to include the wp-env alternative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions