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

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Mar 14, 2024

What?

I don't know if this PR is good or not, but throwing it out there.

When switching themes in E2E tests, optionalFolder regex part matches paths with a folder, so it will return the first match, which might contain a folder.

The consequence is that the regex will match somefolder/twentytwentyfour given a theme slug of twentytwentyfour, and therefore tests that wish to test against twentytwentyfour won't be able to because somefolder/twentytwentyfour will be activated instead.

Why?

Context: #59792 (comment)

How?

Test for incoming theme slug first.

First try to honor the including theme slug, that is, without a folder, the look for the optional folder path, if any.

Testing Instructions

All E2E tests should pass.

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 including theme slug, that is, without a folder, the look for the optional folder path, if any.
@ramonjd ramonjd self-assigned this Mar 14, 2024
Copy link

github-actions bot commented Mar 14, 2024

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: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

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

@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended [Package] E2E Tests /packages/e2e-tests labels Mar 14, 2024
@ramonjd ramonjd requested a review from ellatrix March 14, 2024 00:49
// If the theme is not found, try to match the theme slug with a folder.
if ( ! matchGroup ) {
matchGroup = html.match(
`action=activate&amp;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:

// so it will return the first match, which might contain a folder.
// First try to honor the including theme slug, that is, without a folder.
let matchGroup = html.match(
`action=activate&amp;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.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Just double-checking I'm understanding the logic here. The goal is to:

  • First attempt to match without an optional folder (i.e. default to theme included in the WP release)
  • Then attempt to match with an optional folder (i.e. default to a theme in a nested location)
  • For situations were folks wish to explicitly include a folder, they can include it in the value of themeSlug?

That sounds pretty reasonable to me, as I imagine the expectation is to go with the direct theme first, unless someone has explicitly declared otherwise 👍

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
@ramonjd
Copy link
Member Author

ramonjd commented Mar 14, 2024

Just double-checking I'm understanding the logic here.

Yes, what you wrote is also my understanding (and the intention behind this change).

Thanks for the 👀 !!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Thanks for confirming, the logic here sounds good to me. Given that it's an optionalFolder, preferencing first checking for a match without a folder I think is a good plan, and if anyone using the function winds up encountering an edge case, it's still possible for them to provide a folder explicitly, so this LGTM! ✨

@ramonjd ramonjd enabled auto-merge (squash) March 14, 2024 02:33
@ramonjd ramonjd merged commit 7882911 into trunk Mar 14, 2024
57 checks passed
@ramonjd ramonjd deleted the try/e2e-match-themeslug-then-option-dir branch March 14, 2024 02:49
@github-actions github-actions bot added this to the Gutenberg 18.0 milestone Mar 14, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
…rdPress#59851)

* Test for incoming theme slug first.
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 including theme slug, that is, without a folder, the look for the optional folder path, if any.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
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 [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants