ci: 完善项目持续集成配置并添加 Playwright 测试

This commit is contained in:
严浩
2025-09-09 15:36:24 +08:00
parent 7c04f69d1a
commit 706c60ddb8
11 changed files with 1173 additions and 212 deletions

View File

@@ -1,5 +1,8 @@
import process from 'node:process'
import { defineConfig, devices } from '@playwright/test'
import process from 'node:process'
// const runningInVSCode = process.env.TERM_PROGRAM === 'vscode'
const baseURL = process.env.CI ? 'http://localhost:4173' : 'http://localhost:4730'
/**
* Read environment variables from file.
@@ -11,7 +14,7 @@ import { defineConfig, devices } from '@playwright/test'
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
testDir: './e2e/playwright',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
@@ -34,13 +37,13 @@ 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.CI ? 'http://localhost:4173' : 'http://localhost:5173',
baseURL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
/* Only on CI systems run the tests headless */
headless: !!process.env.CI,
headless: !!process.env.CI || process.env.HEADLESS === 'true',
},
/* Configure projects for major browsers */
@@ -104,7 +107,7 @@ export default defineConfig({
* 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,
port: Number(new URL(baseURL).port),
reuseExistingServer: !process.env.CI,
},
})