1
0
Files
nex/frontend/playwright.config.ts
lanyuanxiaoyao 59179094ed feat: E2E 测试集成真实后端
- Playwright 双 webServer 模式自动启动 Go 后端 + Vite 前端
- 后端使用临时 SQLite 数据库隔离,固定端口 19026
- vite.config.ts proxy target 动态读取环境变量
- 新增 sql.js 依赖用于 SQLite 统计数据 seed
- 新增 e2e/fixtures.ts 共享工具模块(API seed + SQLite seed)
- 拆分测试文件 5→7(providers/models/stats/navigation/validation)
- 删除旧文件 crud.spec.ts/sidebar.spec.ts/stats-cards.spec.ts
- E2E 测试尚有部分用例需调试修复
2026-04-22 00:31:35 +08:00

56 lines
1.5 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const E2E_PORT = 19026
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nex-e2e-'))
const dbPath = path.join(tempDir, 'test.db')
const logPath = path.join(tempDir, 'log')
fs.mkdirSync(logPath, { recursive: true })
process.env.NEX_BACKEND_PORT = String(E2E_PORT)
process.env.NEX_E2E_TEMP_DIR = tempDir
const backendDir = path.resolve(__dirname, '..', 'backend')
export default defineConfig({
testDir: './e2e',
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:5173',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
globalSetup: './e2e/global-setup.ts',
globalTeardown: './e2e/global-teardown.ts',
webServer: [
{
command: `go run cmd/server/main.go --server-port ${E2E_PORT} --database-path "${dbPath}" --log-path "${logPath}" --log-level warn`,
url: `http://localhost:${E2E_PORT}/health`,
timeout: 60_000,
reuseExistingServer: false,
cwd: backendDir,
},
{
command: 'bun run dev',
url: 'http://localhost:5173',
reuseExistingServer: false,
},
],
})