-
Notifications
You must be signed in to change notification settings - Fork 310
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 basic E2E test for blocks. #174
Conversation
I've got the tests running locally but am intermittently running into timeout errors and the workflow is having issues as well. Open to any suggestions here. |
🤔 I think it might be overkill to have e2e tests on example repo. The issue we have with the examples is we don't keep them in-sync with Gutenberg changes. Having an e2e tests won't necessarily help because:
So, the case they are testing for is the basic case that the examples work, and that should be covered by reviews merging in the PR. It might be interesting to create an example block and showing how to create an e2e test for that block. |
e2e-tests/04-controls-esnext.spec.js
Outdated
// Check if block was inserted | ||
expect( await page.$( `[data-type="${ name }"]` ) ).not.toBeNull(); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); |
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.
The snapshots generated are very simple so we can inline them into the test as explained in https://jestjs.io/docs/snapshot-testing#inline-snapshots. It would make tests easier to follow and it should work exactly the same.
It seems like 5 seconds for the e2e test is not enough. There is a different limit set in Gutenberg: We will have to find a reasonable duration here as well. Ideally, we should increase the timeout in the default config for e2e tests in
There are two goals of having e2e tests here:
You made a good point that we won't have a feedback loop when something impactful would land in the Gutenberg repository. However, we can assume that there should never be breaking changes in WordPress and even when that happens we should be able to catch that next time we land a PR in this repository. |
I tend to agree with @gziolo that these tests are more about teaching than catching errors. Although, the "does it insert" test would catch the most basic issues/regressions.
This is an excellent idea. I wonder if instead of a single folder for all the tests, we add one for each block to follow how Gutenberg approaches adding tests. We can have basic test in there i.e |
Good thinking. As far as I remember, as long as the test ends with |
I would prefer not to add one to each of the blocks, especially the early basic blocks because it muddies what the person is trying to learn. The initial goal is just to get the very basics down of what is a block, how do I even create one. If there is a lot of additional tests and other pieces that aren't core to those ideas it gets confusing. I like a more progressive approach, so maybe we have some "complete blocks" that show all the pieces together including an e2e tests, but including them too early upfront will just make it all seem overly complicated and too much stuff to learn at once. |
…e them basis.spec.js.
This is a very good point, perhaps we can exclude tests for Basic, Basic ( ESNext ) and Stylesheets? Those are very simple blocks and don't really benefit much from the tests. I'd say that we still need an example of how to test that a block is inserted, but we can start them with Editable. Thoughts? |
I opened WordPress/gutenberg#35983 to address the issue with the default timeout. |
@gziolo with WordPress/gutenberg#35983 merged, maybe we should wait for the next version of @mkaz any thoughts on my last suggestion of removing the tests from the first few examples? |
Thanks for confirming! I'll update this PR and get it approved. |
This reverts commit 22c30d3.
@gziolo I've made some updates to the tests to get them running. These are very basic but are a good starting 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.
Looks great @ryanwelcher, I added some build tweaks, changes and suggestions, otherwise looks good to merge and iterate on
@ntwb thanks for the review! I'll get these changes in today! |
Co-authored-by: Stephen Edgar <stephen@netweb.com.au>
Co-authored-by: Stephen Edgar <stephen@netweb.com.au>
@ntwb changes implemented. Mind re-reviewing and approving? |
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.
Looks like a great start 👍🏻
Some notes:
- e2e tests will run twice on different Node.js version, we should monitor it as technically it should be enough to run with Node LTS (18.x as of today)
- I think it's more important to run static checks (lining, build, etc) with all supported Node versions (14, 16, 18 as of today - 20 will replace 14 at the end of April)
- this PR removes the unit tests that were included as an example, but I don't think we had CI integration that executed them
Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Good to know.
I've committed your suggestion here.
I removed them because the were broken and failed. I'd love to add unit tests back in but I think we need practical working examples. |
Introduces basic e2e test to confirm that each block is inserted in a new post.
Closes #173.