Skip to content

E2E: Support WordPress installs served from a subdirectory#79166

Merged
jorgefilipecosta merged 1 commit into
trunkfrom
fix/e2e-subdirectory-installs
Jun 23, 2026
Merged

E2E: Support WordPress installs served from a subdirectory#79166
jorgefilipecosta merged 1 commit into
trunkfrom
fix/e2e-subdirectory-installs

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

What?

Makes the Playwright e2e harness and a handful of specs work when WP_BASE_URL points to a WordPress install served from a subdirectory (e.g. http://localhost:8888/wp/).

Why?

Playwright resolves root-relative URLs (/wp-admin/...) against the origin only — new URL( '/x', 'http://host/sub/' ) yields http://host/x, silently dropping the subdirectory. The suite currently assumes a root install (which wp-env always provides), so running it against a subdirectory install fails in three distinct ways:

  1. page.goto( '/...' ) calls (79 call sites across the specs) navigate to the wrong host path — e.g. the font-library spec's front-end check lands on the server's root page instead of the post.
  2. expect( page ).toHaveURL( '/wp-admin/...' ) assertions build the expected URL without the subdirectory and never match.
  3. requestUtils.request.get( '/wp-admin/options-writing.php' ) in the collaboration fixtures fetches the wrong path, the _wpnonce scrape returns null, and every collaboration spec fails in beforeEach with TypeError: Cannot read properties of null (reading '1').

How?

  • Harness (e2e-test-utils-playwright): the page fixture now rewrites root-relative goto() URLs against the full baseURL (including its path). This fixes all existing goto( '/...' ) call sites in one place, with no change needed in specs.
  • Specs: toHaveURL strings in browser-history and change-detection specs and the two requestUtils.request paths in the collaboration fixtures are now relative (no leading slash), which Playwright resolves against baseURL — the same style visitAdminPage already uses.

No behavior change for root installs: with baseURL ending in /, relative and root-relative forms resolve identically.

Testing Instructions

  1. Set up a WordPress install served from a subdirectory (e.g. symlink a wordpress-develop build into an Apache docroot at /wp/) with the Gutenberg plugin and e2e test plugins mapped as in .wp-env.test.json.
  2. WP_BASE_URL=http://localhost:<port>/<subdir>/ npm run test:e2e -- test/e2e/specs/admin/font-library.spec.js test/e2e/specs/site-editor/browser-history.spec.js
  3. Without this change, the font-library front-end assertions and the browser-history URL assertions fail; with it they pass.
  4. Against a regular wp-env (npm run test:e2e), behavior is unchanged.

Testing done

Ran the full suite against a subdirectory MAMP install (WP_BASE_URL=http://localhost:6888/test/test-2/): the previously failing font-library, browser-history, change-detection, and all collaboration specs pass with these changes. Spot-checked specs against the default wp-env root URL to confirm no regressions.

@github-actions github-actions Bot added the [Package] E2E Tests /packages/e2e-tests label Jun 12, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] E2E Tests.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 8.05 MB

compressed-size-action

@jorgefilipecosta jorgefilipecosta force-pushed the fix/e2e-subdirectory-installs branch from 92d144e to 04661f0 Compare June 16, 2026 10:45
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

Flaky tests detected in 7c23f7a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27821405494
📝 Reported issues:

When WP_BASE_URL points to a subdirectory install (e.g.
http://localhost/wp/), Playwright resolves root-relative URLs against
the origin only, dropping the subdirectory path. This broke:

- page.goto( '/...' ) calls throughout the specs (the harness now
  resolves them against the full baseURL in the page fixture);
- toHaveURL( '/wp-admin/...' ) assertions in browser-history and
  change-detection specs (now relative, which Playwright resolves
  against baseURL);
- requestUtils.request calls with a leading slash in the collaboration
  fixtures, which silently fetched the wrong host path and failed the
  nonce scrape (now relative, matching visitAdminPage style).

No behavior change for root installs: with a baseURL of
http://localhost:8889/, relative and root-relative forms resolve to the
same URLs.
@jorgefilipecosta jorgefilipecosta force-pushed the fix/e2e-subdirectory-installs branch from 04661f0 to 7c23f7a Compare June 19, 2026 10:52
@jorgefilipecosta jorgefilipecosta merged commit a7fcec7 into trunk Jun 23, 2026
40 checks passed
@jorgefilipecosta jorgefilipecosta deleted the fix/e2e-subdirectory-installs branch June 23, 2026 18:13
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] E2E Tests /packages/e2e-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant