-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 regresion E2E test for the empty reusable block causing WSODs issue #26913
Add regresion E2E test for the empty reusable block causing WSODs issue #26913
Conversation
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.
I left some minor comments. Thank you for sending PR with new tests added 👍
it( "should not throw an exception if reusable block's content.raw is an empty string", () => { | ||
expect( () => | ||
__experimentalGetParsedReusableBlock( state, 1 ) | ||
).not.toThrowError(); |
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.
You can also update this check and test for the actual result. If code would throw it will fail the test as well.
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.
Do you mean to re-purpose the test to test one of the actual scenarios/happy-path for the __experimentalGetParsedReusableBlock
helper func? That means it wouldn't be a specific regression test anymore (as stated in the describe
). That's not a big deal, but then we'd be testing the func, and not the bug regression (which would still be tested indirectly, as you mention, though). I'm fine with that but just want to make sure we're on the same page.
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.
Yes, this is what I meant. not.toThrowError();
part would be replaced with the assertion checking the actual result and the description for the test updated.
@@ -35,6 +35,7 @@ export { | |||
insertBlockDirectoryBlock, | |||
openGlobalBlockInserter, | |||
closeGlobalBlockInserter, | |||
toggleGlobalBlockInserter, |
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.
There are 2 existing helpers to control the block inserter. Would it be possible to use them instead of introducing another helper function?
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.
👋🏻 Hi Greg! I tried openGlobalBlockInserter
but it waits for the actual inserter el to be present on the page. In the case the error ever regresses, it would cause a timeout because the inserter is never shown. What we really need is to just click to show the inserter, and this helper does just that. What's the other helper?
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.
Also, this is actually an existing helper, I just exported it.
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.
I tried
openGlobalBlockInserter
but it waits for the actual inserter el to be present on the page. In the case the error ever regresses, it would cause a timeout because the inserter is never shown.
It looks like openGlobalBlockInserter
is exactly what fits best here. toggleGlobalBlockInserter
only verifies if the button can be clicked. The waiting part is crucial here to prevent regression. If it would timeout in the future, that's a proper way to signal that something went wrong.
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.
toggleGlobalBlockInserter only verifies if the button can be clicked.
Hmm, it actually wraps a click
call: https://github.com/WordPress/gutenberg/blob/master/packages/e2e-test-utils/src/inserter.js#L49. For the purposes of this regression test, that's all we need.
If we decide to use openGlobalBlockInserter
, there's another potential problem as well (which I just tested): if it the bug regresses, it will fail with the timeout and not with the expect below it. It also means it will slow down the actual test that would finish faster if we weren't waiting for an inserter we know won't appear.
|
||
await toggleGlobalBlockInserter(); | ||
|
||
expect( console ).not.toHaveErrored(); |
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.
This check is scoped only to the e2e spec. It isn't possible to catch errors on the page this way. We have a global verification for the page:
page.on( 'console', ( message ) => { |
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.
Hmmm, interesting. It seemed like it did catch the error when I tested. Or maybe it was just the error bubbling up. Maybe I missed something.
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.
Do you mean then this assertion is not needed at all? Any hints on how I should rewrite that?
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.
It would mean there is console.error
call in the test code, not on the page. What error do you get when it isn't called?
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.
I double-checked (by re-introducing the bug that caused the regression) and that expect does seem to work for the purposes of the test, see the output in the gist:
https://gist.github.com/fullofcaffeine/453e58fba78d902bc690e0b6994e7b31
It is true that it might be considered redundant because if I remove it, the test still fails because the error bubbles up (as described here) and it caught from within the console object:
https://gist.github.com/fullofcaffeine/ade1be595e7f1c5bd46ed5b652814934
That being said, I'd rather keep the expect there as it communicates what the test is not expecting.
So, it seems it's fine the way it is? Let me know if I missed something 🙇🏻
… sure it properly handles the scenario when the reusable block's content is an empty string
…f explicitly checking that it does not throw an exception
It looks like the new e2e test fails on master. I’m opening a revert PR for now but we should definitely update this test and try merge again. |
Strange, this spec is green for me locally. It seems to fail when trying to get hold of the block toolbar, maybe the approach to focus the block is flaky? It does seem to consistently work locally for me, though. I'll create a new PR for the revert of the revert and look into this next week. Thanks! 🙇🏻 |
Revert of revert PR is here, |
* Revert "Revert "Add regresion E2E test for the empty reusable block causing WSODs issue (#26913)" (#26979)" This reverts commit cca33e5. * Wait for the block to be present on the page and click it to five it focus instead of tabbing to it * Make the test more resilient by waiting for the Update button to become enabled
Description
Issue: #26548
Adds a regression test in the client block E2E spec to avoid the regression of this issue: #26485.
How to test
Prepare the env
npm run build
andnpm run wp-env-start
;Run the E2E test
npm run test-e2e packages/e2e-tests/specs/editor/various/reusable-blocks.test.js
;git checkout -- packages/block-editor/src/store/selectors.js
), and rebuild (npm run build
);Run the unit test
npm run test-unit-js packages/block-editor/src/store/test/selectors.js
.git checkout -- packages/block-editor/src/store/selectors.js
), and rebuild (npm run build
).Types of changes
New E2E test.
Checklist: