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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Thumbs.db
wp-auth.json
e2e/.auth/
playwright-report/
playwright-report-premium/
test-results/
blob-report/
.playwright-browsers/
Expand Down
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ Roadmap / version targeting: [org project #12](https://github.com/orgs/gambitph/
### Testing

Playwright for UI / e2e (`e2e/`, `@wp-playground/cli` — no Docker).
Run with `npm run test:e2e` (or `npm run test:debug` for the UI) after `npm run build:e2e`.
Run free with `npm run test:e2e` after `npm run build:e2e`.
With `pro__premium_only/` mounted, run premium with `npm run test:e2e:premium` after `npm run build:e2e:premium`.
See [`e2e/readme.md`](./e2e/readme.md).
Free-repo CI runs the free suite only.
Premium-repo CI runs free then premium.
There is no PHPUnit suite today - prefer Playwright for regressions that matter to upload and settings flows.

## Free / premium
Expand Down
Binary file added e2e/fixtures/sample-large.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/fixtures/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions e2e/playground-blueprint.premium.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "activatePlugin",
"pluginName": "Cimo - Image Optimizer",
"pluginPath": "/wordpress/wp-content/plugins/cimo/cimo.php"
},
{
"step": "runPHP",
"code": "<?php\nrequire_once '/wordpress/wp-load.php';\n$blog_id = get_current_blog_id();\n$site_url = get_site_url( $blog_id );\n$site_url_parts = parse_url( $site_url );\n$data = [ $site_url_parts['host'], $blog_id ];\nif ( isset( $site_url_parts['path'] ) ) {\n\t$data[] = $site_url_parts['path'];\n}\n$uid = md5( implode( '-', $data ) );\nupdate_option( 'cimo_activation_data', [\n\t'status' => 'activated',\n\t'install_id' => 'e2e-install-id',\n\t'activation_params' => [\n\t\t'uid' => $uid,\n\t\t'license_key' => 'e2e-license-key',\n\t],\n\t'install_data' => [\n\t\t'license_plan_name' => 'premium',\n\t\t'install_public_key' => 'e2e-public',\n\t\t'install_secret_key' => 'e2e-secret',\n\t],\n], false );\n"
}
]
}
83 changes: 69 additions & 14 deletions e2e/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# E2E Testing

Cimo's end-to-end tests verify that client-side upload interception actually
converts JPEG uploads to WebP across the main WordPress admin surfaces.
Cimo's end-to-end tests verify client-side upload interception, settings,
post-upload stats, freemium chrome, and (when premium is mounted) bulk
optimization across WordPress admin.

WordPress is provided by [`@wp-playground/cli`](https://www.npmjs.com/package/@wp-playground/cli)
(WASM PHP + SQLite, **no Docker**). Playwright's `webServer` boots it
Expand All @@ -11,15 +12,22 @@ automatically before the suite runs.

Just Node **20+** — no Docker, Composer, or separate WordPress install.

For **premium** specs you also need `pro__premium_only/` checked out under
the free plugin root (clone `bfintal/cimo-premium` into that directory).
Playground mounts the plugin tree as a real directory, so a symlink that
points outside the mount will not expose premium files inside WASM PHP.

## Usage

### Free suite

Build the plugin assets first (Playground mounts this repo; enqueue needs `build/`):

```bash
npm run build:e2e
```

Run e2e tests (Playground starts on port `9410` if nothing is already listening):
Run free e2e tests (Playground starts on port `9410` if nothing is already listening):

```bash
npm run test:e2e
Expand All @@ -31,49 +39,96 @@ or with the Playwright UI:
npm run test:debug
```

Locally, `playwright.config.js` reuses an already-running Playground on port
`9410` when present (fast repeat runs). In CI it always boots fresh. If a stale
### Premium suite

```bash
# Mount premium (once), e.g.:
# ln -sfn /path/to/cimo-premium pro__premium_only

npm run build:e2e:premium
npm run test:e2e:premium
```

Premium uses port `9411`, `playwright.premium.config.js`, and
`e2e/playground-blueprint.premium.json` (seeds a mock Freemius `premium` plan).

After premium builds, restore the free build type if you need free packaging:

```bash
node scripts/update-build-type.js free
```

Locally, Playwright reuses an already-running Playground on the suite's port
when present (fast repeat runs). In CI it always boots fresh. If a stale
instance is misbehaving after editing PHP/JS that Playground mounted at boot,
kill whatever is listening on `9410` and re-run.
kill whatever is listening on that port and re-run.

Optional overrides (defaults are set in `playwright.config.js`):
Optional overrides (defaults differ per config):

```
WP_PORT=9410
WP_PORT=9410 # free; premium config defaults to 9411
WP_BASE_URL=http://127.0.0.1:9410
WP_USERNAME=admin
WP_PASSWORD=password
```

## CI

| Repo | Workflow | Suites |
|------|----------|--------|
| Free (`gambitph/Cimo`) | `.github/workflows/e2e-tests.yml` | Free only (`build:e2e` → `test:e2e`) |
| Premium (`bfintal/cimo-premium`) | `pro__premium_only/.github/workflows/e2e-tests.yml` | Free then premium (checks out free as root + premium as `pro__premium_only/`) |

## What is covered

### Free

| Surface | Flow |
|---------|------|
| Image block | Upload button → JPG → WebP |
| Image block | Media Library modal drop → JPG → WebP |
| Block editor | Drop JPG on canvas → WebP image block |
| Page sidebar | Drop JPG on Featured Image → WebP |
| Media → Add New | File picker → JPG → WebP in library |
| Settings | Load/save, quality + max dimension affect upload |
| Media Library grid | Drop → WebP |
| Media modal | Select Files → WebP |
| PNG / multi-file | Convert to WebP |
| Progress modal | Cancel when visible |
| Post-upload | Sidebar stats + attachment meta box |
| Freemium | Disabled premium controls, bulk upsell, plugins links |

### Premium (`e2e/tests/premium/`)

| Surface | Flow |
|---------|------|
| Settings | Gated controls enabled; working bulk UI (not upsell) |
| Bulk optimizer | Progress, complete 4 images under timeout, stop mid-run |

## Files

| Path | Role |
| --- | --- |
| `../playwright.config.js` | Boots `@wp-playground/cli` as Playwright's `webServer`; auth/`baseURL`/storage state |
| `playground-blueprint.json` | Logs in as `admin`, activates Cimo |
| `../playwright.config.js` | Free suite; Playground on 9410; ignores `tests/premium/` |
| `../playwright.premium.config.js` | Premium suite; Playground on 9411 |
| `playground-blueprint.json` | Login + activate Cimo (free) |
| `playground-blueprint.premium.json` | Activate + seed Freemius premium plan |
| `config/global-setup.js` | Cookie-authenticates via `RequestUtils.setup()`, persists `storageState` |
| `test-utils/` | Shared fixtures + upload/drop helpers |
| `tests/*.spec.ts` | Browser-driven upload interception specs |
| `test-utils/` | Shared fixtures + upload/settings/drop helpers |
| `tests/*.spec.ts` | Free browser specs |
| `tests/premium/*.spec.ts` | Premium browser specs |
| `.auth/` | Gitignored; written by global setup |

## Troubleshooting

- **`browserType.launch: Executable doesn't exist`** — run
`npx playwright install chromium` once per machine.
- **Stale plugin behaviour after editing PHP** — Playground snapshots the
mount at boot. Stop the process on port `9410` and re-run.
mount at boot. Stop the process on the suite port and re-run.
- **Composer/settings never appear / `cimoSettings` missing** — run
`npm run build:e2e` so `build/admin/` exists for enqueue.
`npm run build:e2e` (or `build:e2e:premium`) so `build/admin/` exists for enqueue.
- **Premium suite missing Bulk Optimizer** — ensure `pro__premium_only/` is present,
`CIMO_BUILD` is `premium`, and the Freemius seed in the premium blueprint applied.

## Dev Notes

Expand Down
16 changes: 16 additions & 0 deletions e2e/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
export { test, expect } from './test'
export {
SAMPLE_JPG,
SAMPLE_PNG,
SAMPLE_LARGE_JPG,
dropFile,
dropFiles,
waitForCimoReady,
waitForCimoEditorIframeReady,
dismissEditorOverlays,
getMaxMediaId,
getMediaCreatedAfter,
getMediaById,
deletePage,
expectNewMediaIsWebp,
expectNewMediaCount,
uploadSampleViaMediaNew,
expectCimoSidebarStats,
expectCimoMetaBox,
openAttachmentInLibraryModal,
} from './media'
export {
saveCimoOptions,
gotoCimoSettings,
saveSettingsUi,
getCimoSettings,
reloadCimoRuntime,
} from './settings'
Loading
Loading