import { defineConfig, devices } from '@playwright/test'; import * as dotenv from 'dotenv'; import * as path from 'path'; // Read from default .env.test file if present dotenv.config({ path: path.resolve(__dirname, '.env.test') }); const STOREFRONT_URL = process.env.STOREFRONT_URL || 'http://localhost:4005'; const ADMIN_URL = process.env.ADMIN_URL || 'http://localhost:5050'; const BACKEND_URL = process.env.API_URL || 'http://localhost:4001/api'; /** * Playwright E2E configuration for Canina Monorepo. * Covers Next.js Storefront (port 4005) and Vite Admin Panel (port 5050). */ export default defineConfig({ testDir: './tests', timeout: 60000, expect: { timeout: 10000, }, fullyParallel: false, workers: 2, retries: 0, reporter: [ ['html', { open: 'never' }], ['list'] ], use: { baseURL: STOREFRONT_URL, actionTimeout: 15000, navigationTimeout: 45000, screenshot: 'only-on-failure', video: 'retain-on-failure', trace: 'retain-on-failure', locale: 'fa-IR', timezoneId: 'Asia/Tehran', }, projects: [ // 1. Setup project for Admin Authentication State { name: 'admin-setup', testMatch: /fixtures\/admin-auth\.setup\.ts/, use: { baseURL: ADMIN_URL, }, }, // 2. Storefront on Desktop Chromium { name: 'chromium-desktop', testMatch: /(storefront|security)\/.*\.spec\.ts/, use: { ...devices['Desktop Chrome'], baseURL: STOREFRONT_URL, viewport: { width: 1440, height: 900 }, }, }, // 3. Storefront on Mobile Safari (iPhone 14) { name: 'mobile-safari', testMatch: /(storefront|security)\/.*\.spec\.ts/, use: { ...devices['iPhone 14'], baseURL: STOREFRONT_URL, }, }, // 4. Admin Panel Flow on Desktop Chromium (Requires admin-setup) { name: 'admin-chromium', testMatch: /admin\/.*\.spec\.ts/, dependencies: ['admin-setup'], use: { ...devices['Desktop Chrome'], baseURL: ADMIN_URL, viewport: { width: 1440, height: 900 }, storageState: './playwright/.auth/admin.json', }, }, ], // Auto-start webServers if not already running on local ports webServer: [ { command: 'npm run dev:backend', url: 'http://127.0.0.1:4001/api/docs', reuseExistingServer: true, timeout: 120000, }, { command: 'npm run dev:frontend', url: 'http://localhost:4005', reuseExistingServer: true, timeout: 120000, }, { command: 'npm run dev:admin', url: 'http://localhost:5050', reuseExistingServer: true, timeout: 120000, }, ], });