Skip to content

Run the Cypress suite with pretty permalinks, fixing the Preview panel poll spec - #619

Open
galbus wants to merge 8 commits into
mainfrom
claude/block-editor-preview-timeout-3e53a2
Open

Run the Cypress suite with pretty permalinks, fixing the Preview panel poll spec#619
galbus wants to merge 8 commits into
mainfrom
claude/block-editor-preview-timeout-3e53a2

Conversation

@galbus

@galbus galbus commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Problem

tests/cypress/e2e/block-editor/preview-panel.cy.js fails on main:

1) Block Editor: Preview panel
     waits for a still-processing voice-customised preview instead of embedding it early:
   CypressError: Timed out retrying after 5000ms: `cy.wait()` timed out waiting `5000ms`
   for the 1st request to the route: `statusCheck`. No request ever occurred.

Cause

The test environment was running plain permalinks, which almost no real site does.

The workflow already sets a permalink structure before starting Cypress:

- name: Set permalinks
  run: |
    wp rewrite structure '/%postname%/' --hard

…but the first spec's setupDatabase task runs wp reset reset --yes (wp-reset), which
restores WordPress defaults and wipes it. So from spec 1 onwards, every spec ran against
plain permalinks, and that step was dead configuration.

Under plain permalinks get_rest_url() returns the query-string form, so the poll in
src/editor/components/play-audio/hooks.jsapiFetch( { path } ) — requests:

/index.php?rest_route=%2Fbeyondwords%2Fv1%2Fprojects%2F9969%2Fcontent%2F<id>&_locale=user

The spec's glob (**/beyondwords/v1/projects/<id>/content/<id>*) has no slashes to match
against, so the intercept never fired, cy.wait( '@statusCheck' ) timed out, and the poll
hit the real endpoint instead of the stub. Classic-editor specs use the same glob shape and
pass because that code builds URLs as restUrl + 'beyondwords/v1/…', keeping the slashes
literal.

Fix

Test-only — no source change.

  • Set the permalink structure in setupDatabase, after the reset that was wiping it, so
    the suite exercises the /wp-json/… routes real sites use. The dead workflow step is
    removed, with a comment recording what owns the structure now.
  • Add tests/cypress/scripts/router.php for the CI web server. CI serves the site with
    php -S, which has no rewrite support, so pretty URLs would 404 wholesale; the router
    hands non-file requests to index.php the way Apache's .htaccess fallback does.
  • Match the poll with a plain path glob again, now that the URL has literal slashes in
    it. No separator-encoding workaround in the spec.
  • Stub the player SDK via window:before:load instead of intercepting the CDN script.
    With the namespace already defined the plugin never appends the script, so the assertions
    no longer depend on intercepting a cross-origin request that an earlier spec may have left
    in the browser cache — which is how the real player ended up running in the CI failure.

One other spec depended on the old structure: plugins/amp.cy.js built its AMP URL as
`${ url }&amp=1`, which only parsed while every post URL already carried a query string
(/?p=123). It now sets the query var through URL/searchParams, so it is correct under
either structure.

Note that embeds a voice-customised preview once it has finished processing had never
actually executed in CI: cypress-fail-fast skipped it behind the failing test. It runs and
passes here, so both sides of the poll-then-embed behaviour are now covered.

Verification

npx cypress run --browser chrome --spec 'tests/cypress/e2e/block-editor/preview-panel.cy.js'
→ 3 passing

Because the permalink change is environment-wide, the full suite was also run locally with
fail-fast disabled (--expose failFastEnabled=false) so that every permalink-related failure
surfaced rather than being skipped behind the first one:

27 specs, 231 tests → 221 passing, 8 pending, 2 failing
✖ plugins/amp.cy.js   (both failures — the `&amp=1` URL above)

plugins/amp.cy.js passes with that spec fixed; no other spec was affected.

The router was verified standalone against a stub docroot: /, /my-post/ and
/wp-json/…?_locale=user reach WordPress, while /style.css and /wp-admin/ are served
directly.

🤖 Generated with Claude Code

galbus and others added 2 commits August 11, 2026 16:01
…spec

apiFetch percent-encodes the REST path into `rest_route` under plain
permalinks, so the slash glob never matched and the poll request reached
the real endpoint. Stub the player SDK before boot too, so assertions no
longer depend on intercepting a cacheable CDN script.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

The content ID is the one part of the URL unaffected by whether
apiFetch percent-encodes the path, so matching on it drops the
separator alternation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@galbus
galbus requested review from nklhtv and ptrko August 11, 2026 16:13
galbus and others added 2 commits August 11, 2026 17:18
Matching the ID alone left the helper's name promising a route its body
no longer described.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
wp-reset restores plain permalinks, so the workflow's own permalink step
was wiped by the first spec and every spec ran a configuration almost no
real site uses: REST served as `?rest_route=` rather than `/wp-json/`.
Setting the structure in setupDatabase makes it stick, and lets the
preview poll be matched with a plain path glob again.

`php -S` cannot rewrite, so CI needs a router to hand non-file requests
to WordPress the way Apache's .htaccess does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@galbus galbus changed the title Fix the block-editor Preview panel poll spec failing on main Run the Cypress suite with pretty permalinks, fixing the Preview panel poll spec Aug 11, 2026
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@galbus
galbus removed request for nklhtv and ptrko August 11, 2026 17:38
@galbus
galbus marked this pull request as draft August 11, 2026 17:38
The spec appended `&amp=1` to the permalink, which only parsed while the
test site ran plain permalinks and every post URL already had a query
string. Pretty permalinks made it a 404.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@galbus
galbus requested a review from gouravkhunger August 11, 2026 19:53
@galbus
galbus marked this pull request as ready for review August 11, 2026 19:54
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant