diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 473f0bfc8b..e4923fd6bc 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -62,5 +62,13 @@ 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: | + set -euo pipefail + trap 'kill 0' ERR + + npm run wp-env start & + npm run wp-env-test start & + + wait -n + wait -n diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index a7e864803e..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 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..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 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..6df028964c --- /dev/null +++ b/.wp-env.test.json @@ -0,0 +1,26 @@ +{ + "$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": { + "WP_DEBUG": false, + "SCRIPT_DEBUG": false, + "FS_METHOD": "direct" + }, + "mappings": { + "wp-content/plugins/performance": "." + } +} diff --git a/AGENTS.md b/AGENTS.md index 23e8aa05b9..0a973ee2fc 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" } }