-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add regression E2E test for the classic block initialization issue #25169
Add regression E2E test for the classic block initialization issue #25169
Conversation
This is failing for me now with:
|
Some notes: The e2e test can be run locally via I can repro the issue Jon is seeing. Apparently, switching between Visual and Code Editor isn't working. This test should fail (earlier) if we revert 65c9f74 (that's #25162), and run This is a screenshot I took while running It appears that the Gutenberg plugin isn't active during this e2e test, and that we're thus testing against the editor version that comes with Core, rather than the current GB codebase 🤔 I wonder if that's because we're running this test in isolation (and missing some 'global' setup function that enables the plugin), or whether this is a glitch with wp-env on Linux (which both @fullofcaffeine and I are using), or whether this currently affects all e2e tests 😕 |
Update, as Riad explained to me in Slack, the Gutenberg plugin has to be activated manually in the WP instance used for testing (at |
We've found that we need to disable Puppeteer cache before reloading the editor in order to repro the issue. The following works: diff --git a/packages/e2e-tests/specs/editor/blocks/classic.test.js b/packages/e2e-tests/specs/editor/blocks/classic.test.js
index ce450cd172..d2e9ee06df 100644
--- a/packages/e2e-tests/specs/editor/blocks/classic.test.js
+++ b/packages/e2e-tests/specs/editor/blocks/classic.test.js
@@ -131,6 +131,7 @@ describe( 'Classic', () => {
await saveDraft();
// reload
+ await page.setCacheEnabled( false );
await page.reload();
await clickClassic(); We need to investigate if that turns off caching for all subsequent tests, and if yes, how we can restore the previous caching state. |
As @ockham mentioned, by disabling the cache, the regression is reproducible. It's not if the cache is left enabled (default). You can test it by reverting the commit I've chosen to go the simpler route of disabling, running the relevant steps to that reproduce the regression, then enabling the cache again. I assume it should work fine unless we have some kind of page object leakage in parallel tests, but I'm assuming that's not the case (I also don't know much about the Gutenberg testing infrastructure yet). If anyone knows a better way to solve this or why browser caching causes the regression not to manifest in the E2E testing environment, please share your thoughts, we'd be keen to better understand why disabling the cache is needed in this case. |
@@ -46,6 +47,7 @@ describe( 'Classic', () => { | |||
// Click the image button. | |||
await page.waitForSelector( 'div[aria-label^="Add Media"]' ); | |||
await page.click( 'div[aria-label^="Add Media"]' ); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Might move to utils if this becomes useful enough for other tests | ||
const runWithoutCache = async ( cb ) => { | ||
await page.setCacheEnabled( false ); | ||
await cb(); | ||
await page.setCacheEnabled( true ); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I was considering just inlining this, since it's really just two (fairly intuitive) commands. Might not make much sense to encapsulate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure that page.setCacheEnabled( true )
runs at the end even if the first bits throw or reject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, good point indeed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I was considering just inlining this
Yeah, fine with me, we don't really use it anywhere else so you have a point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the actual method to disable and enable the cache is self-descriptive, the additional helper function doesn't add much in terms of meaning.
I updated the PR desc with some step-by-step instructions. |
Thanks! |
Static Analysis job is failing. Fix: #25223 |
#25223 has been merged. I'll rebase this one. |
Considering commit 65c9f74 is reverted, the only actions needed to reproduce the issue are to: * Add the block to the editor, add some content; * Save; * Reload the editor; * Click it. It should error.
Co-authored-by: Bernie Reiter <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working on this, @fullofcaffeine! Let's merge this once all checks are green 👍
Congratulations on your first merged pull request, @fullofcaffeine! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Description
Adds a regression test in the client block E2E spec to avoid the regression of this issue: #24696, as suggested in #25162 (comment).
How has this been tested?
npm build
andnpm run wp-env-start
.localhost:8889
-- log into wp-admin to verify (credentials:admin
/password
)npm run test-e2e -- packages/e2e-tests/specs/editor/blocks/classic.test.js
. (To watch tests in interactive mode, append--puppeteer-interactive
).Classic › Should not fail after save/reload
test fails withTypeError: Cannot read property 'getContent' of null
.git checkout -- packages/block-library/src/classic/edit.js
), and rebuild (npm run build
).Types of changes
New E2E test.
Checklist: