Increasing E2E performance and speeding up tests. #27
Sidsector9
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello folks!
For a while, I have been experimenting with E2E tests for Restricted Site Access, trying to find ways to minimise the time it takes for the entire Cypress suite to finish.
Initial implementation
Here, the test application state was set up entirely by navigating through UI. The flow for each test was somewhat:
Problem:
The navigation between pages and the page reloads wasted a lot of time. In fact, even Cypress considers building up state using UI as an anti-pattern.
1st experiment to avoid UI
To achieve this, I made use of the custom cy.wpCli() command. What this does is runs WP-CLI under the hood.
Problem:
@wordpress/env
it would be:wp-env run tests-cli "wp option update key value"
. The issue here is the chain of commands: FromNode > bash > PHP
. This took way lot of time to execute within Cypress.2nd experiment to avoid UI
@wordpress/env
allows you to mount plugins using the.wp-env.json
config file. In this approach I created a simple plugin what I call as a seeder plugin. The sole responsibility of this plugin is to "seed data" through rest routes, which are called just before running tests.For example, if we have a test file for verifying plugin activation/deactivation as
activation-deactivation.test.js
, the seeder plugin registers a routewp-json/rsa/v1/seed/activation-deactivation
to set state applicable for the test.The routes are called using the Cypress command - cy.request() just before running assertions. All it does it make an HTTP request to the route and the app state is ready within a fraction of a second.
Earlier, the test suite took over 1:10 minutes and with the latest approach, it finishes between 29-34 seconds.
Let me know your thoughts on this, if we can find more ways to improvise this.
cc: @10up/open-source-practice
Beta Was this translation helpful? Give feedback.
All reactions