Skip to content

test(e2e): verify Cloudinary image delivery on front-end#1177

Open
utkarshcloudinary wants to merge 7 commits into
developfrom
feature/e2e-cloudinary-images
Open

test(e2e): verify Cloudinary image delivery on front-end#1177
utkarshcloudinary wants to merge 7 commits into
developfrom
feature/e2e-cloudinary-images

Conversation

@utkarshcloudinary
Copy link
Copy Markdown
Collaborator

Approach

Adds a Playwright e2e test that verifies images on the WordPress front-end are served from Cloudinary once the plugin is configured with valid credentials.

New files

  • tests/e2e/cloudinary-image-delivery.spec.js — the spec.
  • tests/e2e/utils/connection.js — helper that connects the plugin via WP-CLI (cloudinary_connect option) and parses the cloud name out of CLOUDINARY_E2E_URL.
  • tests/e2e/fixtures/test-image.jpg — small (~2KB) JPEG fixture.

What the test does

  1. beforeAll: connect the plugin via WP-CLI using CLOUDINARY_E2E_URL (no UI walk; that path is covered by the wizard spec).
  2. beforeEach: upload the fixture via the WP REST media endpoint, create a published post that uses the attachment as both the featured image and an inline image block, then run wp cloudinary sync so the asset is pushed to Cloudinary deterministically.
  3. Visit the post on the front-end, scroll each image into view (the wizard enables lazy-load, which means src starts as an SVG placeholder until JS replaces it), then assert that the resolved src (and the first srcset candidate when present) for both the featured image and the inline image have host res.cloudinary.com and a pathname starting with /<cloud_name>/.
  4. afterEach: delete the post and attachment via WP-CLI.

Decisions worth flagging

  • The inline-image selector is scoped to .wp-block-image because Twenty Twenty-Five tags the featured image with wp-image-<ID> too.
  • Cleanup uses WP-CLI rather than the REST API because the wp-env test site does not use pretty permalinks, which makes appending force=true to the ?rest_route=-style REST URL fragile.
  • No assertions on specific transformation strings (f_auto, q_auto, etc.). The intent is to catch a regression where URLs stop being rewritten at all; transformation specifics are an implementation detail of the plugin and likely to evolve.

QA notes

Requires CLOUDINARY_E2E_URL to be set (already wired via .env and the e2e workflow secret).

npm run test:e2e -- tests/e2e/cloudinary-image-delivery.spec.js

Expected: 1 passed in ~13s. Full suite (npm run test:e2e) should report 8 passed.

To inspect the run:

npm run test:e2e:debug -- tests/e2e/cloudinary-image-delivery.spec.js

- Inline selector scoped to .wp-block-image so the featured image (which
  some themes also tag with wp-image-<ID>) is not double-counted.
- After post creation, run 'wp cloudinary sync' so the asset is pushed
  to Cloudinary before the front-end visit; otherwise the plugin only
  queues the sync on the first render and the page still shows local URLs.
- Wait for the lazy-load JS to swap the SVG-placeholder src for the real
  Cloudinary URL via scrollIntoViewIfNeeded + an http(s) src expectation.
- Switch cleanup to WP-CLI; building 'force=true' onto the wp-env
  rest_route-style REST URL is fragile.
The previous version waited for the plugin's lazy-load JS to swap the
SVG placeholder in 'src' for a real Cloudinary URL. That swap depends on
IntersectionObserver firing and the placeholder's onload callback, which
is unreliable in headless CI (the GitHub Actions run timed out on
toHaveAttribute(src, /http/) on all 3 attempts).

Switch to asserting the plugin's own server-rendered marker
(data-public-id) plus, opportunistically, validating any HTTP(S) URL
present in src or srcset. The marker is deterministic; the URL check
remains real because we still require at least one HTTP(S) URL across
the two images to confirm we are not just trusting the marker.

Also bump the fixture from 320x240 to 1200x900 so themes consistently
emit srcset (WP only generates intermediate sizes above ~600px), giving
the URL check something to validate even when src remains the placeholder.
@utkarshcloudinary
Copy link
Copy Markdown
Collaborator Author

@gabrielcld2 This is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants