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 Tests: Verify the expected theme is active. #18699

Closed
wants to merge 1 commit into from

Conversation

epiqueras
Copy link
Contributor

Description

This PR adds a check before all E2E tests are ran that verifies that the theme the tests expect is active.

Sometimes, contributors run tests locally with different themes and are confused as to why they fail. This check will surface those situations. See this comment for an example.

How has this been tested?

It was verified that running the E2E tests with a theme other than the currently expected one, twentytwenty, throws a descriptive error before all tests are run.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

@epiqueras epiqueras added Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Nov 22, 2019
@epiqueras epiqueras added this to the Future milestone Nov 22, 2019
@epiqueras epiqueras self-assigned this Nov 22, 2019
@epiqueras epiqueras requested a review from mcsf November 22, 2019 19:44
@mcsf
Copy link
Contributor

mcsf commented Nov 22, 2019

Hm, the thing with a check added in the global config like this is that we suddenly require Twenty Twenty for any tests regardless of their needs. I think there are legitimate cases where you’d want to run given test suites against a site with a different active theme. Sure, the global config may be bypassed, but how practical is that?

This is why I was speculating in the other issue about a suite-specific theme constraint (and hence the importance of performance).

@epiqueras
Copy link
Contributor Author

Hm, the thing with a check added in the global config like this is that we suddenly require Twenty Twenty for any tests regardless of their needs.

We already do, implicitly. All of our tests expect the latest theme and our CI/CD pulls from trunk. I also only added it to the e2e package. I didn't add it to the test-e2e script in @wordpress/scripts precisely for these reasons.

async function verifyActiveTheme() {
await page.goto(
createURL( '' )
);
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this ensure, and can we achieve the same perhaps with a more semantic use of Puppeteer's API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It takes you to the home page in the front end of the site so that the theme's stylesheets will be loaded.

a more semantic use of Puppeteer's API?

What were you thinking?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thrown off by my own expectation of not having to navigate anywhere. Indeed, with a one-off requirement specially made for Twenty Twenty it would be enough to look for #twentytwenty-block-editor-styles-css in the editor itself.

What you're doing is more generic, since the existence of #foo-style-css in the front end is guaranteed by WordPress itself, not the theme implementation. There's no such guarantee for the back end, alas, as editor styles are optional.

In short: disregard my comment about anything more semantic.

@mcsf
Copy link
Contributor

mcsf commented Nov 25, 2019

I also only added it to the e2e package. I didn't add it to the test-e2e script in @wordpress/scripts precisely for these reasons.

I'm not sure I understand the distinction. Doesn't test-e2e load the config and set up the framework based on e2e?

@epiqueras
Copy link
Contributor Author

I'm not sure I understand the distinction. Doesn't test-e2e load the config and set up the framework based on e2e?

Yes, this means other projects using test-e2e won't be affected. I guess you are concerned about projects using the Gutenberg test suites to test integration with their plugins. I can see how a more granular use of verifyActiveTheme would be useful there if they only run a subset of the test suites.

How do you feel about tracking down which test suites rely on a specific theme and adding verifyActiveTheme there as granularly as possible?

@epiqueras epiqueras force-pushed the add/active-theme-verification-to-e2e-tests branch from 942e5b1 to e1f8a86 Compare November 26, 2019 00:44
@epiqueras epiqueras requested a review from gziolo as a code owner November 26, 2019 00:44
@epiqueras epiqueras force-pushed the add/active-theme-verification-to-e2e-tests branch from e1f8a86 to e61b891 Compare November 26, 2019 00:44
export async function verifyActiveTheme( theme ) {
await page.goto( createURL( '' ) );
if ( ( await page.$( `#${ theme }-style-css` ) ) === null ) {
process.exit( `Test suite must be run using the ${ theme } theme.` );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to use process.exit, because of this bug in Jest.

@epiqueras epiqueras force-pushed the add/active-theme-verification-to-e2e-tests branch from e61b891 to 674a8a5 Compare November 26, 2019 01:46
@gziolo
Copy link
Member

gziolo commented Nov 26, 2019

How feasible it would be to update the existing tests to be theme independent? Can we customize the theme by setting our own colors and fonts which override theme defaults? Alternatively, can we override CSS or element styles in places where it becomes theme-specific and fails tests?

@epiqueras
Copy link
Contributor Author

How feasible it would be to update the existing tests to be theme independent? Can we customize the theme by setting our own colors and fonts which override theme defaults? Alternatively, can we override CSS or element styles in places where it becomes theme-specific and fails tests?

I think that is a much better approach. I tried it here: #18761, and it seems to work well. Should we close this and merge that?

@mcsf
Copy link
Contributor

mcsf commented Nov 26, 2019

Yes, that sounds much better, and #18761 already looks promising.

@epiqueras
Copy link
Contributor Author

Closing this then.

@epiqueras epiqueras closed this Nov 26, 2019
@aduth aduth deleted the add/active-theme-verification-to-e2e-tests branch November 27, 2019 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants