- config.ts: DEFAULT_APP_CODE 改 testspace (统一测试场, 取代 developSystem 静默回落)
- app/login.ts|switch.ts|use.ts|logout.ts|create.ts: help/示例/AI hook 全部标注 testspace 是测试场, developSystem/workSystem 是 JNPF 只读 baseline, 禁止当测试目标
- tests/e2e/{smoke,auth.setup,baseline/template}.spec.ts: fixture 用 process.env.APP_CODE || 'testspace', 不再硬编码 developSystem
testspace app 已在 JNPF 创建 (systemId=841610403778660421), 新会话默认登录后, 自由 CRUD 不会污染 developSystem/workSystem baseline 0 差错基线。
Co-Authored-By: Claude <[email protected]>
79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
/**
|
|
* tests/e2e/baseline/template.spec.ts
|
|
*
|
|
* baseline 复刻的 Playwright E2E 测试模板
|
|
* 复制本文件改 APP_CODE / ENCODE / TARGET_URL 即可
|
|
*
|
|
* 注意: 本文件是模板 — 默认 skip, 防止空跑失败
|
|
* 复刻 baseline 时: 1) 复制为 <enCode>.spec.ts 2) 改 APP_CODE/ENCODE/TARGET_URL 3) 去掉 test.skip()
|
|
*/
|
|
import { test, expect } from '@playwright/test'
|
|
import { execSync } from 'node:child_process'
|
|
|
|
// ========== 配置 ==========
|
|
const APP_CODE = 'developSystem' // 源 app = JNPF 只读 baseline (仅 form info / export 用, 不要写)
|
|
const ENCODE = 'leaveApply' // 源表单 enCode
|
|
const CLONE_ENCODE = `${ENCODE}_clone` // 克隆 enCode
|
|
const TARGET_APP = process.env.TARGET_APP || 'testspace' // 目标 app = 统一测试场 (默认; 改 tds 也行, 但别用 developSystem/workSystem)
|
|
const TARGET_URL = `http://127.0.0.1:13880/web/#/${CLONE_ENCODE}` // 实际访问 URL
|
|
// 注: TARGET_URL 取决于 nginx 配置, 调整时改这里
|
|
|
|
// ========== 1. 拉克隆 id ==========
|
|
function getCloneId(): string {
|
|
const out = execSync(`npx tsx src/cli.ts form list --appCode=${TARGET_APP}`, {
|
|
cwd: process.cwd(),
|
|
encoding: 'utf-8',
|
|
})
|
|
const m = out.match(new RegExp(`"enCode":"${CLONE_ENCODE}"[\\s\\S]*?"id":"([^"]+)"`))
|
|
if (!m) throw new Error(`克隆表单 ${CLONE_ENCODE} 不存在, 请先跑 baseline 脚本`)
|
|
return m[1]
|
|
}
|
|
|
|
// ========== 2. 拉原表单字段集 (作为 0 差对比基准) ==========
|
|
async function getOriginalFields(): Promise<string[]> {
|
|
const out = execSync(`npx tsx src/cli.ts form info --id=${process.env.ORIGINAL_ID} --appCode=${APP_CODE}`, {
|
|
encoding: 'utf-8',
|
|
})
|
|
const info = JSON.parse(out)
|
|
const formData = JSON.parse(info.data.formData || '[]')
|
|
return formData.fields?.map((f: any) => f.__vModel__) ?? []
|
|
}
|
|
|
|
// ========== 3. 浏览器 0 视觉差测试 ==========
|
|
test.skip(`baseline: ${APP_CODE}/${ENCODE} 复刻 0 视觉差 (TEMPLATE, skip)`, async ({ page }) => {
|
|
const cloneId = getCloneId()
|
|
|
|
// 拿原表单字段名列表
|
|
const originalFields = await getOriginalFields()
|
|
expect(originalFields.length).toBeGreaterThan(0)
|
|
|
|
// 打开克隆的表单
|
|
await page.goto(TARGET_URL)
|
|
await page.waitForLoadState('networkidle')
|
|
|
|
// 检查每个原字段都在
|
|
for (const field of originalFields) {
|
|
// 字段以 f_ 开头, 渲染成 a-input / a-select / ...
|
|
const selector = `[data-field="${field}"], input[id*="${field}"], [name="${field}"]`
|
|
const count = await page.locator(selector).count()
|
|
expect(count, `字段 ${field} 缺失`).toBeGreaterThan(0)
|
|
}
|
|
|
|
// 截图 (用于 visual diff)
|
|
await page.screenshot({
|
|
path: `screenshots/${APP_CODE}/${ENCODE}.png`,
|
|
fullPage: true,
|
|
})
|
|
})
|
|
|
|
// ========== 4. 提交测试 (基础功能验证) ==========
|
|
test.skip(`baseline: ${APP_CODE}/${ENCODE} 提交按钮存在 (TEMPLATE, skip)`, async ({ page }) => {
|
|
const cloneId = getCloneId()
|
|
await page.goto(TARGET_URL)
|
|
await page.waitForLoadState('networkidle')
|
|
|
|
// 提交按钮存在
|
|
const submitBtn = page.locator('button:has-text("提交"), button:has-text("保存")')
|
|
await expect(submitBtn).toBeVisible()
|
|
})
|