Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nbproject/

build
.wp-env.override.json
.wp-env.test.override.json
*.min.js
*.min.css
*.asset.php
Expand Down
17 changes: 3 additions & 14 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"testsEnvironment": false,
"core": null,
"plugins": [
"./plugins/optimization-detective",
Expand All @@ -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": "."
}
Comment on lines -26 to -28

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.

}
"config": {
"WP_DEVELOPMENT_MODE": "plugin"
}
}
26 changes: 26 additions & 0 deletions .wp-env.test.json
Original file line number Diff line number Diff line change
@@ -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.

"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": "."
}
}
20 changes: 15 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bin/test-php-watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading