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
40 changes: 40 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Playwright

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
playwright:
name: Playwright
runs-on: ubuntu-latest
env:
WP_BASE_URL: http://localhost:8888
WP_CLI: npx wp-env run cli wp
steps:
- uses: actions/checkout@v5

- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm

- run: npm ci

- run: npx playwright install --with-deps chromium

- run: npm run env:start

- run: npm run test:e2e

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: tests/E2E/.report
retention-days: 7
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/vendor/
/.phpunit.result.cache
node_modules/
/tests/E2E/.state/
/tests/E2E/.results/
/tests/E2E/.report/
16 changes: 16 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"phpVersion": "8.3",
"plugins": [
".",
"https://downloads.wordpress.org/plugin/woocommerce.10.9.4.zip",
"pronamic/woocommerce-subscriptions#v9.0.0"
],
"config": {
"WP_DEBUG": true,
"WP_DEBUG_DISPLAY": false
},
"mappings": {
"wp-content/mu-plugins": "./tests/E2E/support/mu-plugins"
}
}
52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,52 @@ filter (`tests/Support/FakeHttp.php`), which is WordPress' own extension point,
and any request that is not answered that way fails the test instead of
reaching the network.

WooCommerce is not installed in the test suite, so the screens that only exist
with WooCommerce loaded — the root account endpoints, the invoice title, the
addresses redirect and the subscription confirmation flow — are still uncovered.
WooCommerce is not installed in this suite, so the screens that only exist with
WooCommerce loaded are covered by the browser tests instead.

### Browser tests

`tests/E2E/` mirrors `src/` the same way, with `.spec.ts` in place of
`Test.php`: `src/Account/Navigation.php` is covered end to end by
`tests/E2E/Account/Navigation.spec.ts`. What lives here is what PHPUnit cannot
reach without WooCommerce, the rewrite rules and a browser — the account
navigation, the account screens served from the site root and the confirmation
of a subscription status change.

The suite runs against a WordPress that is already up, described by four
variables:

| Variable | Default |
|---|---|
| `WP_BASE_URL` | `http://localhost` |
| `WP_CLI` | `docker exec -i -u www-data wordpress-docker-wordpress-1 wp --path=/var/www/html` |
| `WP_E2E_CUSTOMER_PASSWORD` | `libresign-e2e` |
| `WP_E2E_ALLOW_ANY_SITE` | unset |

The defaults are the local SaaS stack again, so there it takes no arguments:

```bash
npm install
npx playwright install chromium
npm run test:e2e
```

`tests/E2E/support/seed.php` puts the site in the state the specs expect, and
runs again before each test that changes the subscription. It is destructive and
nothing is restored afterwards: it makes My Account the front page, rebuilds the
rewrite rules, and creates `libresign_e2e_customer` with the password above,
which this repository publishes. That is why it refuses to run against anything
but `localhost` unless `WP_E2E_ALLOW_ANY_SITE=1` says so — point it at a site you
can throw away, never at production or staging.

Anywhere else, point the first two at the site under test. `.wp-env.json`
describes a disposable one, which is what CI runs:

```bash
npm run env:start
WP_BASE_URL=http://localhost:8888 WP_CLI="npx wp-env run cli wp" npm run test:e2e
```

WooCommerce only offers the billing screen when one of the available gateways
keeps payment methods. The local stack has Stripe for that; `.wp-env.json` maps
a mu-plugin that declares one.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"wordpress-install-dir": "vendor/wordpress"
},
"scripts": {
"lint": "parallel-lint --exclude vendor .",
"lint": "parallel-lint --exclude vendor --exclude node_modules .",
"cs": "phpcs",
"cs:fix": "phpcbf",
"stan": "phpstan analyse",
Expand Down
Loading
Loading