WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

Unit Testing Components #641

Closed BE-Webdesign closed 6 years ago

BE-Webdesign commented 7 years ago

Would unit testing components be of value to the project? It doesn't appear that anyone is pursuing testing too much, maybe that would be a good place for me to be productive? Negatives is it will slow down our CI build and as things change it will slow down PRs, but we could do the component testing separately and eventually streamline it into the CI, so we don't have those kind of project flow problems, until things are more stable.

If you add tests to a component please check the matching box off and edit the list item to feature a # link to the Pull Request that added the initial tests.

Here is a list of components to be tested:

Generic Components:

Editor Components:

Block Components

nylen commented 7 years ago

It doesn't appear that anyone is pursuing testing too much

I'd still like to see a rule that we don't merge new code until it has tests. Generally I'm of the opinion that the more automated testing, the better. In fact I've considered changing my name to "James needs-unit-tests Nylen".

Unit-testing components (and refactoring them so that they can be more easily tested) would be extremely valuable and we would love your help with it. Build time should not be a consideration in making this decision.

Integration testing of actual flows would also be very valuable; however, these tests do slow things down quite a bit. Prior art from Calypso: https://github.com/Automattic/wp-e2e-tests

aduth commented 7 years ago

What did you have in mind for component testing? What sorts of behaviors should we be testing?

I'm very open toward something like Enzyme, with an emphasis on shallow render testing. I don't think there's a performance worry here (per your note on slower CI build).

We already create a fake DOM context in our test bootstrap:

https://github.com/WordPress/gutenberg/blob/master/bootstrap-test.js

BE-Webdesign commented 7 years ago

Yeah, I was thinking of using Enzyme. https://github.com/Automattic/wp-e2e-tests is a lot to take in 😅.

What sorts of behaviors should we be testing?

I think testing rendering with default state, and basic state changes is a good place to start. Testing the editor components as well first would be good as they are not changing as frequently as the block components. That way as the block API changes we will know whether or not our components are breaking at least, (hopefully). I don't know if we will want to use the Full DOM as well to keep track of focusing.

BE-Webdesign commented 7 years ago

Going to breathe some life back into this endeavor, after I touch up meta boxes.

gziolo commented 6 years ago

I updated the list of all components with the actual status. I omitted edit-post which is going to be moved into its own folder soon. This list is huge. @mtias do we want to keep this issue open?

mtias commented 6 years ago

Closing for now.