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 Test Utils: Create standard set of lifecycle utilities #22804

Open
4 tasks
aduth opened this issue Jun 1, 2020 · 1 comment
Open
4 tasks

E2E Test Utils: Create standard set of lifecycle utilities #22804

aduth opened this issue Jun 1, 2020 · 1 comment
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

Comments

@aduth
Copy link
Member

aduth commented Jun 1, 2020

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 and afterEach (or beforeAll and afterAll) 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:

  • It assumes that the developer understands that side effects from activation steps can linger beyond the test file and bleed into other tests, such that they take the action to implement the tear-down.
  • In cases where arguments must be provided, it requires that the arguments be provided consistently (prone to typos, etc). This can be especially problematic when attempting to "unset" a temporary state to the default value, where if assigned as an assumed literal value, it's likely to break if that default ever changes, since there's no single source of truth (example, where "large" is the assumed default)

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...

beforeAll( () => {
  activateFoo( 'bar' );
} );

afterAll( () => {
  deactivateFoo( 'bar' );
} );

...it can be expressed as:

useFoo( 'bar' );

...where useFoo is implemented as:

function useFoo( arg ) {
  beforeAll( () => {
    activateFoo( arg );
  } );

  afterAll( () => {
    deactivateFoo( arg );
  } );
}

Task:

Implement full lifecycle utilities for common end-to-end test state:

  • activatePlugin, deactivatePluginusePlugin
  • setBrowserViewportuseBrowserViewport
  • setPostFormatusePostFormat
  • setUpResponseMockinguseResponseMocks
@aduth aduth added [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Tool] E2E Test Utils /packages/e2e-test-utils labels Jun 1, 2020
@aduth
Copy link
Member Author

aduth commented Jun 3, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant