test(config): 更新 Playwright 配置以适应 VSCode 环境

- 添加代码判断是否在 VSCode 中运行,并设置相应的 baseURL
- 修改 webServer 配置,仅在 VSCode 环境中启动本地服务器
- 优化配置文件结构,提高可读性和维护性
This commit is contained in:
严浩
2025-08-15 16:33:27 +08:00
parent b4c2711da6
commit ee58de3146

View File

@@ -1,6 +1,11 @@
import { defineConfig, devices } from '@playwright/test';
import process from 'node:process';
const runningInVSCode = process.env.TERM_PROGRAM === 'vscode';
const baseURL = runningInVSCode
? 'http://localhost:4173'
: process.env.BASE_URL || 'https://vue-ts-example.oo1.dev';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
@@ -66,7 +71,7 @@ export default defineConfig({
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASE_URL || 'https://vue-ts-example.oo1.dev',
baseURL,
/* Only on CI systems run the tests headless */
headless: !!process.env.CI || process.env.HEADLESS === 'true',
@@ -76,16 +81,13 @@ export default defineConfig({
},
// /* Run your local dev server before starting the tests */
// webServer: {
// /**
// * Use the dev server by default for faster feedback loop.
// * 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.
// */
// command: process.env.CI ? 'npm run preview' : 'npm run dev',
// port: process.env.CI ? 4173 : 5173,
// reuseExistingServer: !process.env.CI,
// },
webServer: runningInVSCode
? {
command: 'npm run build-only; npm run preview',
port: 4173,
reuseExistingServer: true,
}
: undefined,
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',