How to set up E2E testing with Playwright
End to end testing ensures your entire app flow is fully functioning.
Below is a basic guide on setting up E2E testing with NextJS, Resend, and Playwright.
1. Create an endpoint.
For simplicity, we’ll create a GET endpoint that sends an email to the testing account, delivered@resend.dev
on fetch.
2. Write the test spec file.
Create a test spec file at e2e/app.spec.ts
. You can test in two ways:
Option 1: Call the Resend API
Calling the Resend API tests the entire API flow, including Resend’s API responses, but counts towards your account’s sending quota.
Option 2: Mock a response
Mocking the response lets you test your app’s flow without calling the Resend API and impacting your account’s sending quota.
However you test, it’s important to test using a test email address (e.g., delivered@resend.dev) so your tests don’t impact your deliverability. Resend’s test accounts run through the entire API flow without harming your reputation.
3. Create a Playwright config file.
Write your config file, paying special attention to a few properties:
testDir
: the directory containing your test filesoutputDir
: the directory to store test resultswebServer
: provide instructions for Playwright to run your app before starting the testsprojects
: an array of the browsers you want to test
See the Playwright docs for more help.
4. Run the test.
You can run the test by installing Playwright and running the tests.
Playwright will run the tests in the browsers of your choice and show you the results.
Example repo
See the full source code.
Was this page helpful?