/* 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 } from '@playwright/test'; import { browserChannel, contextOptions, projectViewports, } from './scripts/browser-environment.mjs'; import { runtimeOptions } from './scripts/playwright-runtime.mjs'; import { findDevService } from './scripts/dev-service.mjs'; if ( !process.argv.includes('--list') && !process.env.PW_TARGET && !process.env.PW_BASE_URL ) { const existing = await findDevService(); if (existing) { process.env.PW_TARGET = 'remote'; process.env.PW_BASE_URL = existing; } } const runtime = runtimeOptions({ defaultPort: 4176, defaultWorkers: 1 }); const { target, baseURL, isCI, headless, workers, outputDir, reportDir } = runtime; if ( isCI && process.argv.some((argument) => ['--headed', '--debug', '--ui'].includes(argument), ) ) throw new Error('CI requires headless non-interactive tests'); const viewports = runtime.extended ? projectViewports : projectViewports.slice(0, 2); // UI_VISUAL_OFFSCREEN=0 仅限人工本地可视化调试时临时使用。 // Agent、CI、无头/自动化环境禁止设置该值,必须保持默认离屏模式 // (或 UI_VISUAL_OFFSCREEN=1),避免弹出 UI 或依赖显示环境。 // 离屏不能保证系统启动时不激活窗口;公共 fixture 探测到前台或状态不明时停止。 const listOnly = process.argv.includes('--list'); export default defineConfig({ testDir: './e2e', testMatch: '**/*.spec.js', outputDir, fullyParallel: false, workers, forbidOnly: isCI || runtime.requireAll, failOnFlakyTests: isCI, retries: isCI ? 1 : 0, timeout: 30000, expect: { timeout: 5000 }, reporter: listOnly ? [['list']] : [ ['list'], ['html', { outputFolder: reportDir, open: 'never' }], ...(isCI ? [['junit', { outputFile: `${outputDir}/junit.xml` }]] : []), ['./scripts/playwright-reporter.mjs'], ], metadata: { platform: process.platform, node: process.version, target, baseURL: baseURL.href, runId: runtime.runId, }, use: { baseURL: baseURL.href, headless, launchOptions: { args: runtime.launchArgs }, ...contextOptions('desktop'), screenshot: { mode: 'only-on-failure', scale: 'css' }, trace: 'retain-on-failure', video: runtime.video ? 'retain-on-failure' : 'off', }, projects: viewports.map((name) => ({ name: `chrome-${name}`, use: { ...contextOptions(name), channel: browserChannel }, })), webServer: target === 'remote' ? undefined : { command: target === 'local-dist' ? `node scripts/preview-dist.mjs --port ${baseURL.port || 80}` : `npm run dev -- --host 127.0.0.1 --port ${baseURL.port || 80} --strictPort`, url: baseURL.href, reuseExistingServer: false, timeout: 30000, }, });