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

Boost: Refactor and add new e2e tests #21819

Merged
merged 71 commits into from
Dec 15, 2021
Merged

Boost: Refactor and add new e2e tests #21819

merged 71 commits into from
Dec 15, 2021

Conversation

davidlonjon
Copy link
Contributor

@davidlonjon davidlonjon commented Nov 19, 2021

Fixes #21756

Changes proposed in this Pull Request:

This PR implements the core E2E tests described in #21756. It is important to note there is not exactly a 1-1 relationship between the tests in this PR and the tests scenarios highlighted in #21756 but the tests in this PR will cover scenarios by doing a combination of steps and checks.

It adds some new Jetpack Boost WP CLI commands to allow managing tests prerequisites more easily. These commands

  • A command to manage Jetpack Boost connection to WPCOM. it can be used to activate/deactivate and check the connection status.
  • A command to clear any jetpack Boost cache, posts and related options to be able to bootstrap a clean Boost environment.

It creates a new prerequisite allowing setting up some test posts useful to test the Lazy Images and Defer JS modules. These test post pages can be accessed during a test via a new projects/plugins/boost/tests/e2e/lib/pages/TestContentPage.js. The appropriate test post page is retrieved using its id number which is retrieved using the post title. This is to avoid messing out and changing the permalinks structure since the repo files and therefore the .htaccess file are shared between the local development environment and the test environment. This might not be ideal but it seems to work pretty well.

This PR also make some refactoring and additions to the E2E Common files package to support the Jetpack Boost E2E tests. I tried to make them generic so they could be re-used in other plugins. These changes are:

  • Adding the new selectJetpackBoost method to tools/e2e-commons/pages/wp-admin/sidebar.js to allow accessing the Jetpack Boost settings page. It could be contained inside the jetpack Boost E2E files but I thought it makes sense to keep all sidebar actions in that file.
  • Refactoring the methods to activate and deactivate the Jetpack plugin from the Plugins page (using actions such as clicking on activate/deactivate links) in tools/e2e-commons/pages/wp-admin/plugins.js to make them more generic so they can be used to activate and inactivate any plugins.
  • Add prerequisite actions to the tools/e2e-commons/env/prerequisites.js files to allow activating and deactivating plugins using the WP-CLI commands.

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

N/A

Testing instructions:

  • The Jetpack Boost E2E GitHub action should pass.

Locally it can be tested doing the following:

  • run pnpm install at the root of the repo
  • run jetpack install plugins/jetpack
  • run jetpack install plugins/boost
  • in projects/plugins/boost/tests/e2e run pnpm install
  • then in that same folder run pnpm run test-decrypt-config
  • run pnpm run env-start && pnpm run tunnel-on
  • and finally run pnpm run test-e2e

Also individual specs file can be run using for the command pnpm run test-e2e -- path/to/the/spec/file for example pnpm run test-e2e -- specs/speed-score.test.j.

Also the debug mode can be activated using the following command PWDEBUG=1 pnpm run test-e2e -- path/to/the/spec/file or PWDEBUG=1 pnpm run test-e2e for the whole test suite. The PWDEBUG=1 statement makes sure Chromium becomes visible so you can see the actual tests being executed. You will have to manually move some tests step forward from the Playwright Inspector window. See the video below:

CleanShot.2021-12-09.at.14.40.15.mp4

Finally, you once you did the original pnpm run env-start && pnpm run tunnel-on command, you can access your test site from any browser using the tunnel URL provided by the pnpm run tunnel-on command.

* master: (28 commits)
  Prepare for 10.4-a.7 (#21797)
  Check if maxwidth exists before trying to call .length (#21785)
  Podcast Player: Increase podcast shown (#21661)
  licensing: jetpack-js-test-runner is a dev dependency (#21794)
  Update dependency @mdn/browser-compat-data to v4.0.11 (#21792)
  Tests: Fix unit tests for wpcom (#21649)
  SSO: Fix Button Text Alignment on Mobile   (#18770)
  Add/my jetpack skeleton (#21464)
  Identity Crisis: add unit tests for has_identity_crisis and get_mismatched_urls (#21754)
  Remove special cases for calling changelogger on packages/changelogger (#21783)
  eslint-config-target-es: Release 1.0.0! (#21766)
  Revert "WPCOM no longer forces home_urls to be http" (#21769)
  WPCOM no longer forces home_urls to be http (#21747)
  Revert and fix "Revert "Assets: do not use the new method yet (#21760)"" (#21763)
  eslint-config-target-es: Fix README.md (#21743)
  codesniffer: Disable CI on PHP 8.1 (#21742)
  RNA Pricing card component: Fix case where prices before and after match (#21757)
  Janitorial: update Jetpack version for 10.4-a.6 cycle (#21762)
  Releases: prepare changelog for 10.4-a.5 release (#21758)
  Assets: do not use the new method yet (#21760)
  ...
@davidlonjon davidlonjon added E2E Tests [Plugin] Boost A feature to speed up the site and improve performance. labels Nov 19, 2021
@davidlonjon davidlonjon self-assigned this Nov 19, 2021
@davidlonjon davidlonjon marked this pull request as draft November 19, 2021 07:21
@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Boost plugin:

  • Next scheduled release: January 31, 2022.
  • Scheduled code freeze: January 24, 2022.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Nov 19, 2021
@davidlonjon davidlonjon added [Status] In Progress and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Nov 19, 2021
* master: (45 commits)
  Prepare for Boost 1.3.1-beta (#21853)
  Add 'View all purchases' and 'Activate a product' buttons in My Plan card footer. (#21824)
  Move Woop menu item method to parent class so filter can be used in WPCOMSH.  (#21717)
  Dismiss licenses activation notice when license is activated. (#21844)
  assets: Stop `_doing_it_wrong` wrong (#21852)
  Update/jetpack backup version 1.0.1 (#21851)
  assets: Release 1.13.0 (#21847)
  Verification tools: remove old Tools interface (#21846)
  Connection: deactivate the Connection Manager UI (#21828)
  assets: Have `register_script()` take a textdomain (#21831)
  Update/inform first connected plugin (#21672)
  Analyzer: Handle more code tokens (#21652)
  Post List: Release version 0.2.4 (#21820)
  New workflow to push Boost issues to Project Board (#21800)
  Gist Shortcode: refactor unit tests (#21781)
  REST API: Return user ID for comment author if present. (#21834)
  Add License Activation Flow to Jetpack Plugin  (#21764)
  Update wordpress monorepo (#21832)
  docs: Add some tips about handling merge issues (#21825)
  Update error screens and detect backup retry (#21735)
  ...
# By Jeremy Herve (5) and others
# Via GitHub
* master: (26 commits)
  Colors: update Primary green reference to match latest brand book (#21741)
  JS Connection: Moves registerSite logic to the store (#21732)
  Search: Add essential scaffolding for package (#21814)
  Search: avoid registering the widget when the module is not active (#21588)
  Add Video Tracks Support to VideoPress Block (#21578)
  Add deprecated to VideoPress block (#21802)
  Admin Menu: Make API tests compatible with WPCOM (#21850)
  External Media: Short-circuit requests earlier in the stack (#21854)
  Add Busy State to License Activation Flow Button (#21861)
  Fixed an issue with screen resolutions of under 783px that caused the content to not be properly displayed when the nav-unification is expanded on wp-admin. (#21869)
  E2E tests: migrate from Jest to Playwright runner (#21848)
  Update reCAPTCHA constants to match Google's Verbage (#12289)
  JITM: Sideload Jetpack Boost functionality  (#21860)
  Connection: properly add GET-parameters for the `fetchAuthorizationUrl` API call (#21750)
  License Flow: Assorted Styling Improvements (#21859)
  JITM: Sideload Jetpack Backup (#21719)
  Widget Visibility: Apply widget filtering to customizer preview (#21505)
  jetpack: Avoid generating unused JS for static-site-generator assets (#21789)
  Nav Unification: Support absolute URLs in upsell nudges (#21821)
  RePublicize: Enable the block editor UI by default (#21855)
  ...

# Conflicts:
#	projects/plugins/boost/tests/e2e/lib/env/prerequisites.js
#	projects/plugins/boost/tests/e2e/lib/setupTests.js
* master: (22 commits)
  Update storybook monorepo to v6.4.0 (#21897)
  Refresh the site's modules and settings after successful product activation (#21886)
  Plugin Install: Bump MC stat on success or fail. (#21893)
  Nav Unification: Use correct user capability for the Inbox menu item (#21882)
  Jetpack: Extend disconnection dialog component to handle multiple steps and accept more props (#21048)
  Disable CSSTidy property shorthand optimization in the editor or headstart (#21891)
  Connection UI: Update Composer instructions in README.md (#21890)
  Partner Compatibility: Adding a unique connection screen for customers who receive a coupon from a Jetpack partner (#21813)
  Search package: move search dashboard to package - the base (#21865)
  JITM: wrap CTA below text on small viewports (#21688)
  Licensing JS Package – fix icon positioning and width (#21878)
  JITM: new JS and CSS builder (#21874)
  Support site_intent for `/me/sites` endpoint (#21880)
  Don't render Critical CSS while generating CritCSS. (#21879)
  ConnectScreen: make button full width on small screens (#21683)
  Improve the copy of the license activation banner (#21876)
  Rename Webpack-built files back from `.min.js` and remove hashes (#21748)
  Search: Migrate more helper classes to package (#21751)
  Search: migrate/add search rest API (#21584)
  Add initial state to the connection package (#21864)
  ...
* master:
  Added a custom composer installer to use a separate vendor folder. (#21877)
  Masterbar: rewrite tracks-events.js without jQuery (#21907)
  pre-commit: Run `eslint --fix` like we do `phpcbf` (#21923)
  Hide licenses activation route when user account not linked. (#21919)
  Beta: Handle exception when no Internet connection (#21915)
  Update wordpress monorepo (#21918)
  Pin dependency automattic/wordbless to 0.3.1 (#21920)
  Use new GitHub secret to manage pushing to Project Boards (#21838)
  Backup: provide additional disconnect info in backup plugin (#21421)
  IDC: Event tracking for the new screen (#21900)
  Releases: add testing list for Jetpack 10.4 (#21909)
  Jetpack 10.5-a.0 Cycle Start (#21912)
  Jetpack 10.4: Changelog (#21908)
  Add/contextualized jetpack connection (#21815)
  Fix masterbar not being displayed entirely for resolutions of under 660px. (#21871)
  Handle the intermittent occurrence of null in `columnWidths[ rowIndex ]` array  in TiledGallery (#21892)
  Add to My Plan's header section a small licensing-related piece of copy (#21899)
  Sharing: ask search engines to not index pages with query string. (#21843)
  PR Template: Indicate use of milestone (#21898)
  Likes: add some extra checks to queuehandler.js (#21896)
# By Adnan Haque
# Via GitHub
* master:
  Boost: fix inconsistent lazy load (#21921)

# Conflicts:
#	projects/plugins/boost/tests/e2e/specs/jetpack-boost/modules-common.test.js
@davidlonjon
Copy link
Contributor Author

@thingalon, I pushed a couple of commits since your last review to fix a typo and also to improve (a little) some of the horrific names of the Jetpack Boost page methods.

karthikax
karthikax previously approved these changes Dec 14, 2021
Copy link
Contributor

@karthikax karthikax left a comment

Choose a reason for hiding this comment

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

Great work @davidlonjon, Thanks for this PR!

I was reviewing and testing this PR. Everything works great (again thanks for the testing instructions) with PWDEBUG=true.

However, when I run in headless mode some tests fail. Eg: specs/modules-common.test.js:44:3 › Modules › The render-blocking-js module state should revert back to original state. Adding some dummy timeouts solved the issue. Maybe this is something specific to my setup. So, I will leave it for others to review this as well.

Overall, it is amazing to see a developed test suite for Boost!!

@adimoldovan
Copy link
Member

@davidlonjon, this looks great!

I have two concerns though:

  1. The use of test.describe.serial. This is normally used to group tests that depend on each other, ensuring they run in the correct order. Looking at the tests, they seem to be independent of each other, so a serial run shouldn't be necessary. One big disadvantage to serial mode is that one failure will cause the next tests to be skipped.
    I'm not sure about your intention with this (maybe to make sure they won't run in parallel?), but either way, I strongly suggest not creating a dependency between tests.

  2. Tests stability. I ran the suite a few times, both locally and in CI by re-running the job and every 2-3 runs there seems to be a failure. Tests related to Critical CSS and connection seem to be the most common failing.
    This is very important because an unstable test will very quickly lose its value.
    This is of course something that can closely be monitored and addressed later on. We're using this dashboard to monitor test stability in time.

@thingalon
Copy link
Member

thingalon commented Dec 15, 2021

I've fixed a couple of issues which affected stability:

  • In edea4ec, I fixed the way we use waitForLoadState. We're supposed to call it after triggering navigation, not before. This would have created a race condition, as were not (really) waiting for navigation to finish before pressing on after some actions (plugin activate, deactivate, login).
  • In 4bd8587, I fixed a missing prerequisite; you shouldn't try to connect Jetpack when the plugin isn't active :)
  • In abad901, I removed test.describe.serial; it's not necessary and the tests run fine without it.

Since applying these fixes, I'm finding it a lot more stable. @adimoldovan, really hoping to get this merged soon so that other members of my team can implement some additional tests while David is still here to help us through it. :)

thingalon
thingalon previously approved these changes Dec 15, 2021
Copy link
Member

@thingalon thingalon left a comment

Choose a reason for hiding this comment

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

This is great!

I've tidied up a few inconsistency issues, and now it seems to reliably succeed every time for me.

adimoldovan
adimoldovan previously approved these changes Dec 15, 2021
Copy link
Member

@adimoldovan adimoldovan left a comment

Choose a reason for hiding this comment

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

@thingalon, @davidlonjon Let's merge it!

Copy link
Contributor

@haqadn haqadn left a comment

Choose a reason for hiding this comment

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

test.describe.serial is actually needed on Modules test suit @thingalon.

I have also found that sometimes the lazy-images revert fails for me as the waitForApiResponse is not effective in its case. I am pushing a couple of changes to fix these issues.

@@ -10,7 +10,7 @@ const modules = [
[ 'render-blocking-js', 'disabled' ],
];

test.describe.serial( 'Modules', () => {
test.describe( 'Modules', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, serial makes sense here. The default, toggle and revert depend on the sequence for each module.

Copy link
Member

@pyronaur pyronaur Dec 15, 2021

Choose a reason for hiding this comment

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

Just cc'ing @adimoldovan to make sure that makes sense :)

Copy link
Contributor

Choose a reason for hiding this comment

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

To add some context, serial was used in multiple tests, and @adimoldovan's objection is valid. I only found on one test suit Modules where using serial was appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it looks like it. It's pretty confusing and I strongly suggest moving away from it.

I suggest merging the 3 tests into a single one and using steps for each action:

test( 'Toggle modules', async () => {
    test.step( `The ${ moduleSlug } module should be ${ moduleState } by default`, async () => {}
    test.step( `The ${ moduleSlug } module state should toggle to an inverse state`, async () => {}
    test.step( `The ${ moduleSlug } module state should revert back to original state, async () => {}
}

test.describe can be removed completely.

Copy link
Member

Choose a reason for hiding this comment

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

Or better:

test( 'Toggle ${ moduleSlug } module', async () => {
    test.step( `The module should be ${ moduleState } by default`, async () => {}
    test.step( `The module state should toggle to an inverse state`, async () => {}
    test.step( `The module state should revert back to original state, async () => {}
}

New endpoints to make waitForApiResponse to be effective for lazy-images and render-blocking-js status
@haqadn haqadn dismissed stale reviews from adimoldovan and thingalon via 9463596 December 15, 2021 12:10
Copy link
Contributor

@haqadn haqadn left a comment

Choose a reason for hiding this comment

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

👍🏼

@adimoldovan adimoldovan self-requested a review December 15, 2021 13:21
@sdixon194 sdixon194 added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Dec 15, 2021
@thingalon thingalon enabled auto-merge (squash) December 15, 2021 23:26
@thingalon thingalon merged commit 0571017 into master Dec 15, 2021
@thingalon thingalon deleted the add/boost-e2e-tests branch December 15, 2021 23:46
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Dec 15, 2021
@github-actions github-actions bot added this to the boost/1.3.2 milestone Dec 15, 2021
@davidlonjon
Copy link
Contributor Author

Thank you all for the contribution to this PR and particularly @adimoldovan for having supported me all the way on this E2E journey for Boost. I am truly thankful for the guidance and kindness 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management E2E Tests [Plugin] Boost A feature to speed up the site and improve performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boost: Create core E2E tests
7 participants