Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Deprecation warning for wp-env tests environment #2437

Closed

Description

@westonruter

When running npm run wp-env start, I'm seeing a warning in the terminal:

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

We need to ensure that the tests environment doesn't go away, or else we need to revisit how we handle tests.

Activity

  1. added theissue type on Apr 2, 2026
  2. added
    [Type] Bug
    Infrastructure
    on Apr 2, 2026
  3. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon Apr 2, 2026
  4. changed the title [-]Deprecation warning for wp-env tests envirionment[/-] [+]Deprecation warning for wp-env tests environment[/+] on Apr 2, 2026
  5. westonruter commented on Apr 2, 2026

    @westonruter
    MemberAuthor

    I also faced a maddening issue whereby once I run npx wp-env start, any changes I made to the codebase aren't reflected anymore when I run tests. I have to explicitly run npx wp-env start --update or else destroy and start anew. The workaround for me on MacOS is to create a symlink in the tests-src back to the repo. It made this script for me:

    fix-wp-env-tests-src-bind-mount.sh
    #!/bin/bash
    #
    # Fixes the wp-env tests-src bind mount so that file changes are reflected
    # immediately in the container without needing to run `npx wp-env start --update`.
    #
    # Background: wp-env copies project files into a `tests-src` directory that is
    # bind-mounted at /var/www/html. It also creates a separate bind mount for the
    # performance plugin mapping at /var/www/html/wp-content/plugins/performance.
    # However, Docker Desktop on macOS does not properly overlay the child bind mount
    # on top of the parent, so the stale copy in tests-src is served instead. This
    # script replaces that stale copy with a symlink to the actual source directory,
    # which Docker follows through the parent mount.
    #
    # Run this after `npx wp-env destroy && npx wp-env start` or `npx wp-env start --update`.
    
    set -e
    
    REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
    
    INSTALL_PATH="$(npx wp-env status --json 2>/dev/null | python3 -c "import json,sys; print(json.load(sys.stdin)['installPath'])" 2>/dev/null)"
    if [ -z "$INSTALL_PATH" ]; then
    	echo "Error: Could not determine wp-env install path."
    	echo "Make sure wp-env is running: npx wp-env start"
    	exit 1
    fi
    
    TARGET="$INSTALL_PATH/tests-src/wp-content/plugins/performance"
    
    if [ -L "$TARGET" ]; then
    	echo "Already a symlink: $TARGET"
    	echo "Nothing to do."
    	exit 0
    fi
    
    if [ ! -e "$TARGET" ]; then
    	echo "Error: $TARGET does not exist."
    	echo "Make sure wp-env is running: npx wp-env start"
    	exit 1
    fi
    
    echo "Stopping wp-env..."
    npx wp-env stop
    
    echo "Removing stale copy: $TARGET"
    rm -rf "$TARGET"
    
    echo "Creating symlink: $TARGET -> $REPO_DIR"
    ln -s "$REPO_DIR" "$TARGET"
    
    echo "Starting wp-env..."
    npx wp-env start
    
    echo "Done! File changes will now be reflected immediately in the tests container."

    Claude drafted an issue title and description for this issue.


    Title: Mappings in .wp-env.json are not live bind-mounted on Docker Desktop for macOS — file changes require --update

    Description:

    When using mappings in .wp-env.json to map the project root into the tests container, file changes on the host are not reflected in the container. This means every edit to a test file (or any mapped file) requires running npx wp-env start --update before the change is picked up, making the development workflow extremely slow.

    Steps to reproduce:

    1. Configure .wp-env.json with a mapping like:
      {
        "env": {
          "tests": {
            "mappings": {
              "wp-content/plugins/performance": "."
            }
          }
        }
      }
    2. Run npx wp-env start
    3. Create or modify a file on the host inside the mapped directory
    4. Check the container — the change is not visible:
      echo "test" > ./testfile.txt
      npx wp-env run tests-cli -- cat /var/www/html/wp-content/plugins/performance/testfile.txt
      # Shows old content or "No such file or directory"
      

    Root cause:

    wp-env bind-mounts the WordPress installation directory (tests-src) at /var/www/html, and then creates a separate child bind mount for the mapping at /var/www/html/wp-content/plugins/performance. However, Docker Desktop on macOS does not properly overlay the child bind mount on top of the parent. The tests-src directory contains a copy of the mapped files (placed there during wp-env start or --update), and this stale copy is always served instead of the live bind mount.

    This can be confirmed by checking /proc/mounts inside the container — only a single mount at /var/www/html is visible, with no separate mount for the mapping path.

    Workaround:

    Replace the stale copy in tests-src with a symlink to the actual source directory. Docker follows the symlink through the parent mount, restoring live file syncing:

    INSTALL_PATH="$(npx wp-env status --json | python3 -c "import json,sys; print(json.load(sys.stdin)['installPath'])")"
    npx wp-env stop
    rm -rf "$INSTALL_PATH/tests-src/wp-content/plugins/performance"
    ln -s /path/to/your/project "$INSTALL_PATH/tests-src/wp-content/plugins/performance"
    npx wp-env start

    This symlink is destroyed by wp-env destroy or wp-env start --update and must be recreated afterward.

    Environment:

    • macOS (Darwin 24.6.0)
    • Docker Desktop 29.3.1 (with VirtioFS, containerd snapshotter enabled)
    • @wordpress/env (version from npm)

    Aside:

    For the Performance repo, the mappings is needed because the plugins array mounts each individual plugin at /var/www/html/wp-content/plugins/<slug>, but the test runner needs the monorepo root — composer.json, vendor/ (with PHPUnit), phpunit.xml.dist, and the test bootstrap files. The npm test scripts all use:

    wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:<plugin>
    

    Without the mapping, /var/www/html/wp-content/plugins/performance wouldn't have composer.json, vendor/bin/phpunit, or phpunit.xml.dist, so none of the test commands would work.

  6. westonruter commented on Apr 2, 2026

    @westonruter
    MemberAuthor

    Something else that had broken for me: 654d69b fixed as part of #2436.

  7. added
    ContributorDay
    on Apr 6, 2026
  8. westonruter commented on Apr 13, 2026

    @westonruter
    MemberAuthor

    I also faced a maddening issue whereby once I run npx wp-env start, any changes I made to the codebase aren't reflected anymore when I run tests.

    Maybe related: WordPress/gutenberg#76930

    See Slack: https://wordpress.slack.com/archives/C02QB8GMM/p1775706867355449?thread_ts=1775706867.355449&cid=C02QB8GMM

  9. moved this from Not Started/Backlog 📆 to Done 😃 in WP Performance Ongoingon Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ContributorDayInfrastructure[Type] Bug

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions