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: Fix performance tests by making inserter search container waiting optional #46268

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/e2e-test-utils/src/inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ async function waitForInserterCloseAndContentFocus() {
* Wait for the inserter search to yield results because that input is debounced.
*/
async function waitForInserterSearch() {
await page.waitForSelector( '.block-editor-inserter__no-tab-container' );
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially we could use Promise.any and only wait like 2 seconds or so

Copy link
Member Author

Choose a reason for hiding this comment

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

True, we could. We could also reduce the timeout of waitForSelector() to like 2 seconds, which should be more than enough. No need to wait for the full 30 seconds. Done in fc8f801

Copy link
Member

@WunderBart WunderBart Dec 6, 2022

Choose a reason for hiding this comment

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

I think a universal solution to this could be using the Page.waitForResponse method. AFAIR, both previous and current Inserter versions use the /search endpoint, so something like this should improve stability and require less maintenance at the same time:

async function waitForInserterSearch() {
  return await page.waitForResponse( '/search' );
}

Copy link
Member

@WunderBart WunderBart Dec 6, 2022

Choose a reason for hiding this comment

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

To be extra sure the response is not returned before the waitForInserterSearch is called, I'd refactor a bit further and couple waitForRequest with the term input so that we start waiting before the search request is triggered, for example:

async function inserterSearch( searchTerm ) {
	return await Promise.all( [
		page.waitForResponse( `/search?term=${ searchTerm }` ),
		page.keyboard.type( searchTerm )
	] );
}

Puppeteer doesn't seem to recommend this convention, but Playwright does. I think both implementations work the same way, so my recommendation would be going with the Playwright convention, also because we're currently migrating to it :)

Does that make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes a lot of sense! Thanks for offering a better alternative @WunderBart! Would you like to follow up with that, or should I give it a go?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a bunch, @WunderBart 🙌

Copy link
Member

Choose a reason for hiding this comment

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

Sharing an early WiP #46366 - did a bit more than planned, but it's mostly removing unnecessary waits and code duplication. Waiting for the test results now! 🤞

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @WunderBart! Let me know when you feel it's ready for a look.

Copy link
Member

Choose a reason for hiding this comment

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

It's basically ready, @tyxla. I'm still looking at the few tests that keep failing, but they don't seem to be related to the change, and they do pass for me locally. 🤔 I've just updated the branch with the current trunk, so hopefully it helps. 🤞

Copy link
Member Author

Choose a reason for hiding this comment

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

Will keep an eye on it 👍

await page.waitForSelector(
'.block-editor-inserter__no-tab-container',
{ timeout: 2000 }
);
} catch ( e ) {
// This selector doesn't exist in older versions, so let's just continue.
}
}

/**
Expand Down