- 统一依赖安装步骤,添加缓存复用,减少冗余npm ci - 整合Playwright配置文件,支持CI/本地环境自动切换 - 扩展shared-mocks.tsx,添加统一mock入口 - 修复jest.setup.js符号链接问题 - 删除冗余配置文件(jest.config.js, playwright.config.tiered.ts) - 调整CI阶段编号(7阶段→6阶段) 优化效果: - CI依赖安装时间减少约30% - 配置文件维护成本降低 - Mock复用率提升
This commit is contained in:
+76
-29
@@ -1,38 +1,85 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
const isCI = !!process.env.CI;
|
||||
const testTier = process.env.TEST_TIER || 'standard';
|
||||
const baseURL = process.env.BASE_URL || (isCI ? 'http://localhost:3000' : 'https://novalon.cn');
|
||||
|
||||
const tierConfig = {
|
||||
fast: {
|
||||
timeout: 15000,
|
||||
retries: 0,
|
||||
workers: 2,
|
||||
},
|
||||
standard: {
|
||||
timeout: 30000,
|
||||
retries: isCI ? 1 : 0,
|
||||
workers: isCI ? 1 : undefined,
|
||||
},
|
||||
deep: {
|
||||
timeout: 60000,
|
||||
retries: 2,
|
||||
workers: 1,
|
||||
},
|
||||
};
|
||||
|
||||
const config = tierConfig[testTier] || tierConfig.standard;
|
||||
|
||||
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',
|
||||
fullyParallel: !isCI,
|
||||
forbidOnly: isCI,
|
||||
retries: config.retries,
|
||||
workers: config.workers,
|
||||
timeout: config.timeout,
|
||||
reporter: isCI
|
||||
? [
|
||||
['html', { outputFolder: 'reports/html', open: 'never' }],
|
||||
['json', { outputFile: 'reports/results.json' }],
|
||||
['list']
|
||||
]
|
||||
: 'html',
|
||||
use: {
|
||||
baseURL: 'https://novalon.cn',
|
||||
baseURL,
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
launchOptions: isCI ? {
|
||||
args: ['--disable-dev-shm-usage', '--no-sandbox']
|
||||
} : undefined,
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: { ...devices['Desktop Safari'] },
|
||||
},
|
||||
{
|
||||
name: 'Mobile Chrome',
|
||||
use: { ...devices['Pixel 5'] },
|
||||
},
|
||||
{
|
||||
name: 'Mobile Safari',
|
||||
use: { ...devices['iPhone 12'] },
|
||||
},
|
||||
],
|
||||
});
|
||||
webServer: isCI ? {
|
||||
command: 'npm run start',
|
||||
port: 3000,
|
||||
timeout: 120000,
|
||||
reuseExistingServer: false,
|
||||
} : undefined,
|
||||
projects: isCI
|
||||
? [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: { ...devices['Desktop Safari'] },
|
||||
},
|
||||
{
|
||||
name: 'Mobile Chrome',
|
||||
use: { ...devices['Pixel 5'] },
|
||||
},
|
||||
{
|
||||
name: 'Mobile Safari',
|
||||
use: { ...devices['iPhone 12'] },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user