/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { defineConfig, devices } from '@playwright/test'; const target = process.env.PW_TARGET || 'local-dev'; if (!['local-dist', 'local-dev', 'remote'].includes(target)) { throw new Error('PW_TARGET must be local-dist, local-dev or remote'); } if (target === 'remote' && !process.env.PW_BASE_URL) { throw new Error('PW_BASE_URL is required for remote tests'); } const baseURL = new URL(process.env.PW_BASE_URL || 'http://127.0.0.1:4175/'); if ( !['http:', 'https:'].includes(baseURL.protocol) || baseURL.username || baseURL.password || baseURL.search || baseURL.hash ) { throw new Error( 'PW_BASE_URL must be an HTTP(S) URL without credentials, query or hash', ); } if (!baseURL.pathname.endsWith('/')) throw new Error('PW_BASE_URL directory path must end with /'); if ( target !== 'remote' && (baseURL.hostname !== '127.0.0.1' || baseURL.protocol !== 'http:' || baseURL.pathname !== '/') ) { throw new Error('Local targets require http://127.0.0.1:/'); } const isCI = Boolean(process.env.CI && process.env.CI !== 'false'); const headless = process.env.PW_HEADLESS === undefined ? isCI : process.env.PW_HEADLESS === '1'; const viewports = [ ['desktop', 1920, 1080], ['mobile', 360, 800], ]; if (process.env.PW_EXTENDED_LAYOUT === '1') { viewports.push( ['tablet', 768, 1024], ['desktop-boundary', 1024, 768], ['laptop-hd', 1366, 768], ['laptop-wxga', 1440, 900], ['qhd', 2560, 1440], ['uhd', 3840, 2160], ); } export default defineConfig({ testDir: './e2e', testMatch: '**/*.spec.js', outputDir: 'test-results', fullyParallel: false, workers: 1, forbidOnly: isCI || process.env.PW_REQUIRE_ALL === '1', failOnFlakyTests: isCI, retries: isCI ? 1 : 0, timeout: 30000, expect: { timeout: 5000 }, reporter: [ ['list'], ['html', { outputFolder: 'playwright-report', open: 'never' }], ...(isCI ? [['junit', { outputFile: 'test-results/junit.xml' }]] : []), ], metadata: { platform: process.platform, node: process.version, target, baseURL: baseURL.href, }, use: { baseURL: baseURL.href, headless, launchOptions: process.env.UI_VISUAL_OFFSCREEN === '1' ? { args: [ '--window-position=-32000,-32000', '--disable-backgrounding-occluded-windows', ], } : {}, locale: 'zh-CN', timezoneId: 'Asia/Shanghai', deviceScaleFactor: 1, colorScheme: 'light', reducedMotion: 'reduce', trace: 'retain-on-failure', screenshot: 'only-on-failure', video: process.env.PW_VIDEO === '1' ? 'retain-on-failure' : 'off', }, projects: viewports.map(([name, width, height]) => ({ name: `chrome-${name}`, use: { ...(name === 'mobile' ? devices['Pixel 5'] : devices['Desktop Chrome']), channel: 'chrome', viewport: { width, height }, }, })), webServer: target === 'remote' ? undefined : { command: target === 'local-dist' ? `npm run preview -- --host 127.0.0.1 --port ${baseURL.port || 80}` : `npm run dev -- --host 127.0.0.1 --port ${baseURL.port || 80} --strictPort`, url: baseURL.href, reuseExistingServer: false, timeout: 30000, }, });