ci: 更新 Playwright 配置以使用预览服务器

- 将 baseURL 固定为 http://localhost:4173,不再根据环境变量区分 CI 和本地环境
- 修改启动命令为先构建再启动预览服务器
- 设置 reuseExistingServer 为 true,优化服务器重用逻辑

(cherry picked from commit df6ffb99c8)
This commit is contained in:
严浩
2025-09-09 23:09:32 +08:00
parent 56d8a3aa49
commit 306ed9a527

View File

@@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test'
import process from 'node:process' import process from 'node:process'
// const runningInVSCode = process.env.TERM_PROGRAM === 'vscode' // const runningInVSCode = process.env.TERM_PROGRAM === 'vscode'
const baseURL = process.env.CI ? 'http://localhost:4173' : 'http://localhost:4730' const baseURL = 'http://localhost:4173'
/** /**
* Read environment variables from file. * Read environment variables from file.
@@ -106,8 +106,8 @@ export default defineConfig({
* Use the preview server on CI for more realistic testing. * Use the preview server on CI for more realistic testing.
* Playwright will re-use the local server if there is already a dev-server running. * Playwright will re-use the local server if there is already a dev-server running.
*/ */
command: process.env.CI ? 'pnpm run preview' : 'pnpm run dev', command: 'pnpm run build-only; pnpm run preview',
port: Number(new URL(baseURL).port), port: Number(new URL(baseURL).port),
reuseExistingServer: !process.env.CI, reuseExistingServer: true /* !process.env.CI */,
}, },
}) })