Skip to content
Draft
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
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,88 @@ jobs:
name: playwright-artifacts
path: artifacts/
retention-days: 7

# The same suite against WordPress Playground (PHP compiled to WebAssembly)
# instead of wp-env, so no Docker images, containers or MariaDB. Runs next
# to the wp-env job while the two are compared; see
# tests/e2e/playground/server.mjs.
e2e-playground:
name: E2E (Playwright, Playground)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Same reason as the e2e job: `npm ci` runs Composer in postinstall.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache Composer
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-e2e-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-e2e-

- name: Install dependencies
run: npm ci

- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> "$GITHUB_OUTPUT"

- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}

# Playground keeps the downloaded WordPress zip and wp-cli.phar here.
# The key follows the core version in .wp-env.ci.json.
- name: Cache Playground downloads
uses: actions/cache@v4
with:
path: ~/.wordpress-playground
key: ${{ runner.os }}-wp-playground-${{ hashFiles('.wp-env.ci.json', 'package-lock.json') }}
restore-keys: |
${{ runner.os }}-wp-playground-

- name: Install browsers, build assets
env:
PLAYWRIGHT_CACHE_HIT: ${{ steps.playwright-cache.outputs.cache-hit }}
run: |
if [ "$PLAYWRIGHT_CACHE_HIT" = "true" ]; then
npx playwright install-deps chromium
else
npx playwright install --with-deps chromium
fi

npm run build

# Starts Playground, runs both Playwright passes, stops Playground.
- name: Run E2E tests
env:
CLOUDINARY_E2E_URL: ${{ secrets.CLOUDINARY_E2E_URL }}
run: npm run test:e2e:playground

- name: Upload Playwright artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-artifacts-playground
path: artifacts/
retention-days: 7
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ The suite runs against the HTTPS tests site. Start it through the npm scripts, w
WP_BASE_URL=http://localhost:8889 npm run test:e2e
```

### Running the tests without Docker (WordPress Playground)

```bash
npm run test:e2e:playground
```

This starts the site in [WordPress Playground](https://wordpress.github.io/wordpress-playground/) (PHP compiled to WebAssembly, SQLite instead of MariaDB), runs the suite against it on `http://localhost:8889`, and stops it. The parallel and `@serial` passes each get a fresh site; see `tests/e2e/playground/run-e2e.sh` for why. It needs no Docker and no `npm run env:start`. Stop wp-env first, because both use port 8889. WordPress core, the PHP version and the `wp-config.php` constants come from `.wp-env.ci.json`. Pass Playwright arguments to run a part of the suite:

```bash
npm run test:e2e:playground -- tests/e2e/plugin.spec.js
```

The specs call WP-CLI through `tests/e2e/utils/wizard.js`. With Playground, that helper sends the commands to a small bridge in `tests/e2e/playground/server.mjs` instead of `docker exec`. The Playground log is in `artifacts/playground.log`.

### Wizard test credentials

`tests/e2e/wizard-setup.spec.js` exercises the live Cloudinary connection flow, so it needs a real connection string. Provide one of two ways:
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test:e2e:parallel": "./.wp-env/scripts/run-e2e.sh --grep-invert @serial",
"test:e2e:serial": "./.wp-env/scripts/run-e2e.sh --grep @serial --workers=1",
"test:e2e:debug": "./.wp-env/scripts/run-e2e.sh --ui",
"test:e2e:playground": "./tests/e2e/playground/run-e2e.sh",
"test:unit": "wp-env run tests-cli --env-cwd=\"wp-content/plugins/$(basename \"$PWD\")\" vendor/bin/phpunit"
},
"lint-staged": {
Expand Down Expand Up @@ -87,6 +88,7 @@
"@wordpress/hooks": "^5.0.0",
"@wordpress/i18n": "^7.0.0",
"@wordpress/scripts": "^37.1.0",
"@wp-playground/cli": "^3.1.61",
"copy-webpack-plugin": "^14.0.0",
"css-loader": "^7.1.5",
"css-minimizer-webpack-plugin": "^8.0.0",
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/cloudinary-gallery-delivery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ test.describe( 'Cloudinary Gallery block delivery', { tag: '@serial' }, () => {
} ) => {
await admin.editPost( created.postId );

// editPost() returns before the editor has parsed the post content,
// so wait for the block to reach the store before reading it.
await page.waitForFunction( () =>
window.wp?.data
?.select( 'core/block-editor' )
.getBlocks()
.some( ( b ) => b.name === 'cloudinary/gallery' )
);

// Select the block through the data store. Clicking it in the canvas
// would hit the widget's own buttons inside the block.
const clientId = await page.evaluate( () => {
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/cloudinary-video-delivery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ function setVideoPlayer( value ) {
'update_option("cloudinary_media_display", array_merge((array) get_option("cloudinary_media_display", array()), array("video_player" => "' +
value +
'")));';

// Playground has no container; the helper applies its own timeout.
if ( process.env.WP_E2E_RUNTIME === 'playground' ) {
wpCli( [ 'eval', `'${ php }'` ] );
return;
}

const cmd = [
'docker',
'exec',
Expand Down
103 changes: 103 additions & 0 deletions tests/e2e/playground/run-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
# Run the e2e suite against WordPress Playground instead of wp-env.
#
# Starts tests/e2e/playground/server.mjs in the background, waits until its
# WP-CLI bridge answers, runs Playwright, then stops the server. The
# Playground log is written to artifacts/playground.log.
#
# Without arguments, runs the passes of `npm run test:e2e`, each against a
# fresh site:
#
# - The parallel pass, 6 PHP workers.
# - The @serial pass without the storage-modes spec, 6 PHP workers.
# - The storage-modes spec, 1 PHP worker. It checks local files after a
# sync, and with more than one worker a deleted file can still look present
# to another worker (see the `workers` comment in server.mjs). Other specs
# stay on 6 workers, because with 1 the block editor saves too slowly on CI
# runners.
#
# With arguments, starts one site with 1 PHP worker and passes the arguments
# to Playwright, e.g. a single spec file.
#
# Usage: tests/e2e/playground/run-e2e.sh [playwright args]

set -euo pipefail

PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
cd "$PROJECT_DIR"

export WP_E2E_RUNTIME=playground
export WP_PLAYGROUND_PORT="${WP_PLAYGROUND_PORT:-8889}"
export WP_PLAYGROUND_CLI_PORT="${WP_PLAYGROUND_CLI_PORT:-8890}"
export WP_BASE_URL="http://localhost:${WP_PLAYGROUND_PORT}"

LOG_FILE="$PROJECT_DIR/artifacts/playground.log"
mkdir -p "$(dirname "$LOG_FILE")"
: > "$LOG_FILE"

server_pid=""

stop_server() {
if [ -n "$server_pid" ]; then
kill "$server_pid" 2> /dev/null || true
wait "$server_pid" 2> /dev/null || true
server_pid=""
fi
}
trap stop_server EXIT

# Starts a fresh site and waits until the WP-CLI bridge, which starts
# listening only after WordPress has booted, is up.
#
# $1: number of PHP workers.
start_server() {
local start_line
start_line=$(($(wc -l < "$LOG_FILE") + 1))

WP_PLAYGROUND_WORKERS="$1" node tests/e2e/playground/server.mjs >> "$LOG_FILE" 2>&1 &
server_pid=$!

for _ in $(seq 1 180); do
if ! kill -0 "$server_pid" 2> /dev/null; then
echo "Playground exited during startup:" >&2
tail -n "+$start_line" "$LOG_FILE" >&2
exit 1
fi
if tail -n "+$start_line" "$LOG_FILE" | grep -q "Playground ready"; then
tail -n "+$start_line" "$LOG_FILE" | grep "Playground ready"
return
fi
sleep 1
done

echo "Playground did not start within 180s:" >&2
tail -n "+$start_line" "$LOG_FILE" >&2
exit 1
}

if [ "$#" -gt 0 ]; then
start_server 1
./.wp-env/scripts/run-e2e.sh "$@"
exit
fi

STORAGE_SPEC="tests/e2e/cloudinary-storage-modes.spec.js"

# Unlike `npm run test:e2e`, run every pass even when one fails, so one CI
# run reports every failure. Exit non-zero if any failed.
status=0

start_server 6
npm run --silent test:e2e:parallel || status=1
stop_server

start_server 6
./.wp-env/scripts/run-e2e.sh --grep @serial --workers=1 \
--grep-invert "Cloudinary storage modes" || status=1
stop_server

start_server 1
./.wp-env/scripts/run-e2e.sh "$STORAGE_SPEC" --workers=1 || status=1
stop_server

exit "$status"
Loading
Loading