In our test environments, we send our emails to test inboxes on self-hosted Squirrelmail servers to avoid sending test emails to inbox service providers such as Gmail. Many important flows require the user to check their email, click on an actionable link, redirect to the web application, and then continue to a download or verification success page. We test these features manually by entering our Squirrelmail email addresses into the necessary forms, clicking some buttons, and following email links to validate that everything is working as expected. We can do this every time on new code changes to make sure we haven't regressed anywhere, but it would be nice to automate these steps into an end-to-end (E2E) test that we can run again when we want. Specifically, we'd like to write
E2E tests with Cypress, so that we don't have to manually test these potentially slow and confusing email flows in our own web browser every time. Before getting into the post, here are some articles you might be interested in reading first. If you've never written E2E tests before or want a refresher on how to think when writing E2E tests, you might want to see this blog post before you start. If you are unfamiliar with using Cypress to write E2E tests in general, we strongly recommend that you check out our thousand foot overview on implementing Cypress tests for your web applications. This will give you a better idea of the Cypress API. This article assumes you are familiar with some of the Cypress functions such as cy.task()to run arbitrary code that we define in a Node server to help us process emails. Also, if the last code snippets with TypeScript are a bit confusing, it might clear things up to see our blog post on how we typed our Cypress tests.