Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E theme switch: match incoming theme slug, then optional folder #59851

Merged
merged 2 commits into from Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/e2e-test-utils-playwright/src/request-utils/themes.ts
Expand Up @@ -13,12 +13,25 @@ async function activateTheme(
let response = await this.request.get( THEMES_URL );
const html = await response.text();
const optionalFolder = '([a-z0-9-]+%2F)?';
const matchGroup = html.match(
`action=activate&stylesheet=${ optionalFolder }${ encodeURIComponent(

// The `optionalFolder` regex part matches paths with a folder,
// so it will return the first match, which might contain a folder.
// First try to honor the included theme slug, that is, without a folder.
let matchGroup = html.match(
`action=activate&stylesheet=${ encodeURIComponent(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first match is to honor any incoming themeSlug when the tester wants to be explicit.

themeSlug
) }&_wpnonce=[a-z0-9]+`
);

// If the theme is not found, try to match the theme slug with a folder.
if ( ! matchGroup ) {
matchGroup = html.match(
`action=activate&stylesheet=${ optionalFolder }${ encodeURIComponent(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second match is to honor the intentions of:

themeSlug
) }&_wpnonce=[a-z0-9]+`
);
}

if ( ! matchGroup ) {
if ( html.includes( `data-slug="${ themeSlug }"` ) ) {
// The theme is already activated.
Expand Down