The apps/next/playwright.config.ts file defines the end-to-end (e2e) testing configuration for the Next.js application. It is configured to run tests in parallel, handle retries in CI environments, and automatically manage a local development server for testing.
Key Configuration Settings
- Test Directory: Tests are located in
./e2e. - Parallelism:
fullyParallel is enabled to run tests in parallel. - CI Behavior:
forbidOnly: Disallows .only in test cases when process.env.CI is set.retries: Performs 2 retries in CI, otherwise 0.workers: Limits to 1 worker in CI to prevent resource contention.reuseExistingServer: Set to true in local environments to avoid starting a new server if one is already running.
- Base URL: The application is expected to be running at
http://localhost:3000. - Tracing: Playwright traces are captured
on-first-retry. - Web Server: The configuration automatically starts the app using
yarn dev and waits for http://localhost:3000 to be ready before running tests.
import { defineConfig, devices } from '@playwright/test'
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
webServer: {
command: 'yarn dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
})