E2E Test Utils: Create standard set of lifecycle utilities #22804
Labels
[Tool] E2E Test Utils
/packages/e2e-test-utils
[Type] Automated Testing
Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
[Type] Task
Issues or PRs that have been broken down into an individual action to take
Related: #22712
Background:
In end-to-end tests, it's quite common to need to establish some temporary environment state relevant for the duration of that test file. For example, a plugin should be activated while a test is being run. In code, this usually presents itself as a pair of
beforeEach
andafterEach
(orbeforeAll
andafterAll
) Jest setup and teardown methods, containing the "enable"/"activate" and "disable"/"deactivate" steps respectively.Evidenced by #22712, this can be error-prone for a couple reasons:
Another disadvantage is that in lieu of setting the expectation that a developer implement this themselves, many common "state" are reset universally after every test, regardless of whether it's expected the state was modified for the test (example).
Proposal:
The changes in #22712 present a possible pattern for utilities which implement the full lifecycle of a testing state, taking advantage of the fact that Jest lifecycle methods can be called from utilities, not exclusively within the test itself.
Thus, instead of the general pattern...
...it can be expressed as:
...where
useFoo
is implemented as:Task:
Implement full lifecycle utilities for common end-to-end test state:
activatePlugin
,deactivatePlugin
→usePlugin
setBrowserViewport
→useBrowserViewport
setPostFormat
→usePostFormat
setUpResponseMocking
→useResponseMocks
The text was updated successfully, but these errors were encountered: