Skip to content

E2E: Eliminate side effects via DB snapshots #61719

@WunderBart

Description

@WunderBart

What problem does this address?

Improves the individual E2E test isolation to the point where side effects are no longer happening.

What is your proposed solution?

This can be achieved by exporting the database after the global setup is complete and importing it for each test within the page fixture. An example implementation can be found in WooCommerce Blocks, introduced in woocommerce/woocommerce#46125. It's using wp db API to manage the DB snapshots, which has been working reliably, taking an acceptable ~1s for the DB import step.

As rightfully pointed out by @youknowriad here, though, we might not want to use the wp CLI directly as it would mean we can't run the tests against any URL. However, working around it with a dedicated REST API call might be possible. Another notable limitation of this approach is that using hooks other than beforeEach would need to be eslint-banned (via the no-hooks rule) as they either won't have an effect (afterEach, afterAll) or will work for the first test of the current suite only (beforeAll). IMO though, the latter isn't really that much of a limitation since it simplifies the test writing flow.

While I know how to import/export the DB via the wp CLI directly, I'm not sure how to approach it with a REST call. Any ideas? 😄

cc: @Mamaduka @kevin940726 @youknowriad @oandregal @gigitux @danielwrobert @nerrad

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions