Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix Gutenberg e2e tests failures. #3324

Merged
merged 4 commits into from
Oct 27, 2020

Conversation

budzanowski
Copy link
Contributor

There was a recent change in how the blocks insert mechanism works. It now works as a popover: WordPress/gutenberg#24429

This means that inserting a block should close the modal and put the focus on the newly added block. Since the automatic close action is part of the new behavior the insertBlock puppeteer command was also updated. It now expects that the blocks selection panel becomes closed and focus is shifted:
https://github.com/WordPress/gutenberg/blob/master/packages/e2e-test-utils/src/inserter.js#L135

We have three instances of a test where we test that the block can be added just once on the page. Since the second add operation is not possible the block selector will not be closed and the focus will not be shifted. This means that we can't use insertBlock for our tests. A new utility function was created that tries to add the block but does not wait for the closing.

Fixes #2993

How to test the changes in this Pull Request:

  1. This fixes E2E tests triggered by Travis so the tests should be green.

@budzanowski budzanowski added skip-changelog PRs that you don't want to appear in the changelog. needs: tests The issue/PR needs tests before it can move forward. labels Oct 26, 2020
@budzanowski budzanowski requested a review from a team as a code owner October 26, 2020 16:23
@budzanowski budzanowski requested review from haszari and removed request for a team October 26, 2020 16:23
@github-actions
Copy link
Contributor

Size Change: 0 B

Total Size: 1.12 MB

ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.81 kB 0 B
build/active-filters.js 8.85 kB 0 B
build/all-products-frontend.js 31.2 kB 0 B
build/all-products.js 36.1 kB 0 B
build/all-reviews.js 9.78 kB 0 B
build/atomic-block-components/add-to-cart-frontend.js 8.95 kB 0 B
build/atomic-block-components/add-to-cart.js 7.52 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/button.js 3.18 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/image~atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/button-frontend.js 2.02 kB 0 B
build/atomic-block-components/button.js 839 B 0 B
build/atomic-block-components/category-list-frontend.js 469 B 0 B
build/atomic-block-components/category-list.js 478 B 0 B
build/atomic-block-components/image-frontend.js 1.7 kB 0 B
build/atomic-block-components/image.js 1.15 kB 0 B
build/atomic-block-components/price-frontend.js 2.29 kB 0 B
build/atomic-block-components/price.js 2.32 kB 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/rating.js 527 B 0 B
build/atomic-block-components/sale-badge-frontend.js 859 B 0 B
build/atomic-block-components/sale-badge.js 863 B 0 B
build/atomic-block-components/sku-frontend.js 386 B 0 B
build/atomic-block-components/sku.js 395 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary-frontend.js 917 B 0 B
build/atomic-block-components/summary.js 927 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/atomic-block-components/tag-list.js 474 B 0 B
build/atomic-block-components/title-frontend.js 1.23 kB 0 B
build/atomic-block-components/title.js 1.06 kB 0 B
build/attribute-filter-frontend.js 18.2 kB 0 B
build/attribute-filter.js 12.4 kB 0 B
build/blocks.js 3.54 kB 0 B
build/cart-frontend.js 70.1 kB 0 B
build/cart.js 38.7 kB 0 B
build/checkout-frontend.js 86 kB 0 B
build/checkout.js 42 kB 0 B
build/editor-rtl.css 13.8 kB 0 B
build/editor.css 13.9 kB 0 B
build/featured-category.js 7.73 kB 0 B
build/featured-product.js 9.97 kB 0 B
build/handpicked-products.js 7.37 kB 0 B
build/price-filter-frontend.js 14.8 kB 0 B
build/price-filter.js 10.3 kB 0 B
build/product-best-sellers.js 7.45 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-category.js 8.39 kB 0 B
build/product-new.js 7.61 kB 0 B
build/product-on-sale.js 8 kB 0 B
build/product-search.js 3.56 kB 0 B
build/product-tag.js 6.53 kB 0 B
build/product-top-rated.js 7.58 kB 0 B
build/products-by-attribute.js 8.33 kB 0 B
build/reviews-by-category.js 11.8 kB 0 B
build/reviews-by-product.js 13.4 kB 0 B
build/reviews-frontend.js 9.4 kB 0 B
build/single-product-frontend.js 33.8 kB 0 B
build/single-product.js 10.1 kB 0 B
build/style-rtl.css 17.9 kB 0 B
build/style.css 17.9 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors.js 417 kB 0 B
build/vendors~atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.1 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.32 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 787 B 0 B
build/wc-payment-method-cod.js 879 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 12 kB 0 B
build/wc-settings.js 2.35 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Thanks for sorting this out @budzanowski !

This approach seems reasonable. I tested by re-running the tests locally on trunk (reproduced the bug) and then again on this branch, and confirmed this fixes the problem. 🎉

Note – I manually set up gutenberg plugin and latest e2e utils as appropriate, using the commands in the travis config:

  • npm run wp-env run tests-cli "wp plugin install gutenberg --activate"
  • npm install @wordpress/e2e-test-utils@latest

I'm approving the PR, but I wonder if it's better to revisit the tests that were failing. Here are a couple of ideas:

  • Perhaps we can tweak how we implement can only be inserted once tests so they are more robust across WP versions. E.g. perhaps we can search the inserter for the block and confirm that it's hidden or disabled. Ideally we can do this using utils from WordPress core.
  • Or perhaps these tests are not actually that useful - maybe they aren't the most important thing to test.

Up to you if you want to try any of this, not a blocker - feel free to go with your existing solution.

(By the way, the inline comments on the code are mostly me figuring out the failure mode, and understanding the proposed solution.)

*
* @param {string} searchTerm The text to search the inserter for.
*/
export async function insertBlockDontWaitForInsertClose( searchTerm ) {
Copy link
Member

Choose a reason for hiding this comment

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

This name seems a little long, what's the main purpose of this utility func?

I think we can probably keep the name as insertBlock - i.e. the previous closing behaviour was an unintentional side effect.

Aha, after re-reading the PR description, I see that we were relying on the previous behaviour.

Since the second add operation is not possible the block selector will not be closed and the focus will not be shifted.

I'm a bit confused - here's a summary of what I understand, let me know if I've got something wrong.

  • Our tests often start with visitBlockPage() which takes care of creating a page containing the block.
  • For some blocks, we only allow one instance per page.
  • To test this behaviour, we do something like this:
		await insertBlock( block.name );
		await closeInserter();
		expect( await getAllBlocks() ).toHaveLength( 1 );

I'm assuming this code had an issue – what was the specific issue / error? Maybe our test code assumed something it shouldn't.

Is it possible to switch to using closeGlobalBlockInserter instead of our custom func - would that help? Or perhaps we can tweak the approach here, do we need to close the inserter?

		await insertBlock( block.name );
		await closeGlobalBlockInserter();
		expect( await getAllBlocks() ).toHaveLength( 1 );

Copy link
Member

Choose a reason for hiding this comment

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

Update: I ran this locally (with trunk) to better understand the issue. Here's the all products test fail:

 FAIL  tests/e2e/specs/backend/all-products.test.js (33.901s)
  ● All Products Block › can only be inserted once

    : Timeout - Async callback was not invoked within the 30000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 30000ms timeout specified by jest.setTimeout.Error:

So the issue is that something's timing out in the test, maybe the insertBlock().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly the failure was inside the insertBlock() that was waiting for the inserter to close https://github.com/WordPress/gutenberg/blob/master/packages/e2e-test-utils/src/inserter.js#L135 that is why we have our own function that does not wait for this behavior.

Comment on lines +20 to +22
export const closeInserter = async () => {
await page.click( '.edit-post-header [aria-label="Add block"]' );
};
Copy link
Member

Choose a reason for hiding this comment

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

Nice to see this common code factored out into the library 👍

Does this always close the inserter, or does it assume that the inserter is open? For example, if the inserter is not open, does it open it? Put another way, if we call twice in a row, what happens?

If so, might be more robust to add a check for whether the inserter is open/visible at the start of the function.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it looks like we can use e2e-test-utils for this:

If these are not available in older environments that we use for our tests, we can implement a function with the same name to patch it to the current API 😄

@budzanowski
Copy link
Contributor Author

@haszari Or perhaps these tests are not actually that useful that is what I generally think so in this case I would just go with this simple patch and do no overthink it too much. Thanks for the review.

@budzanowski budzanowski merged commit f30a20e into trunk Oct 27, 2020
@budzanowski budzanowski deleted the fix/2993-gutenberg-e2e-tests-failures branch October 27, 2020 12:24
@haszari haszari added this to the 3.7.0 milestone Oct 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: tests The issue/PR needs tests before it can move forward. skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

investigate why is WP 5.4 + GB E2E test is failing and remove the skip
3 participants