The playwright.config.ts file in the example package defines the test environment for running Playwright tests alongside a local web server. Key configurations include:
- Test Directories: Tests are located in
./tests/playwright/specs and results are stored in ./tests/playwright/results. - Timeouts: Global test timeout is set to 30 seconds, and
expect assertions have a 10-second timeout. - CI Behavior: On CI,
forbidOnly is enabled, retries is set to 2, and workers is set to 1 to prevent parallel execution issues. - Reporting: Uses the
html reporter, saving reports to ./tests/playwright/report. - Base URL: The
baseURL is configured to http://localhost:4173/ to match the web server port. - Web Server: Automatically starts the local development server using
yarn preview --port 4173 before running tests. It reuses the existing server if not running in a CI environment.
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
import { resolve } from 'path';
const playwrightDir = (partialPath: string) =>
resolve(__dirname, './tests/playwright', partialPath);
const WEB_SERVER_PORT = 4173;
const config: PlaywrightTestConfig = {
testDir: playwrightDir('./specs'),
outputDir: playwrightDir('./results'),
timeout: 30 * 1000,
expect: {
timeout: 10000,
},
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 1,
workers: process.env.CI ? 1 : undefined,
reporter: [
[
'html',
{
outputFolder: playwrightDir('./report'),
open: process.env.CI ? 'never' : 'on-failure',
},
],
],
use: {
actionTimeout: 0,
baseURL: `http://localhost:${WEB_SERVER_PORT}/`,
trace: 'retain-on-failure',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
webServer: {
command: `yarn preview --port ${WEB_SERVER_PORT}`,
port: WEB_SERVER_PORT,
reuseExistingServer: !process.env.CI,
},
};
export default config;