Writing Integration Tests with Playwright
Learn how to write integration tests using Playwright, a powerful end-to-end testing framework
All versions of Nextbase Starter Kit come with Playwright installed. Playwright is a powerful end-to-end testing framework that allows you to write integration tests for your application.
Configuration
Playwright is configured in the playwright.config.js
file.
As you can see, the configuration file is quite simple. The playwright projects are configured in this manner:
- Projects which setup authentication are configured in the
with-auth
project. - Projects which test logged in users are configured in the
Logged In Users (Desktop Chrome)
project. - Projects which test logged out users are configured in the
Logged Out Users (Desktop Chrome)
project.
The Logged In Users (Desktop Chrome)
project is configured to use the with-auth
project as a dependency. This means that the with-auth
project will run first, and then the Logged In Users (Desktop Chrome)
project will run.
However, the tests themselves run in parallel in each project.
Running tests
Playwright runs in NODE_ENV=test
mode. It also relies on .env.test
for environment variables.
Now, .env.test is configured to use local supabase which is setup by running pnpm supabase start
command.
The pnpm supabase start
command sets up a local supabase instance using docker.
- The supabase api url is available at http://localhost:54321/ (This is the most important url)
- The supabase db url is at http://localhost:54322/
- The supabase studio is available at http://localhost:54323/ (You can use this to use the UI interface )
- The supabase inbucket instance is available at http://localhost:54324/ (We use this for testing emails)
Now that supabase is running locally. All we need to do is to run playwright.
Running playwright with UI
Running playwright in headless mode
Since playwright has been configured to start the local dev server, you don't need to run pnpm dev
separately.
Writing tests
All the test cases are written in the e2e
folder. The e2e
folder is divided into two folders:
- Tests which require a user logged in need to be named
test-case.user.spec.ts
- Tests which don't require a user logged in need to be named
test-case.spec.ts
Create Organization Test case example
This is an example of a test case which requires a user to be logged in.