* browser.ts 重构: runBrowserTest 派发 form/workflow 2 module
- 新增 fetchWorkflowSchema (镜像 web workFlow/template.ts getInfo)
- 新增 runWorkflowBrowserChecks (workflow 专属 7 检查, 镜像 Form.vue schemas)
- 7 检查: 页面加载 / 9列表列 / 新增+5类型dropdown / AI建流程 / form模态框 ≥6字段 / 必填 fullName+category+icon / formItem label 完整性
* 路由策略: workflow 走静态路径 onlineDev/flowEngine (vs form 走 menuList 解析)
- 静态路径无 menu 后缀 hash 漂移风险
* 向后兼容: --formId alias, --id 通用, --module form|workflow
* 修 '新增' vs '新建' locale 漂移 (中英/zh-TW 都覆盖)
* 帮助文本加 Prerequisites 段 (testspace 需先建 type=2 menu 'tcbflowdesign')
实测:
testspace: 7/7 PASS, 8.4s (9/9 列 + 7/7 form label)
workSystem form 回归: 7/7 PASS, 8.8s
错误处理: 错误 module 拒绝 / form 缺 formId 拒绝 / workflow 缺 id 允许 (跑 UI 检查)
架构:
- 镜像 web 端 flowEngine/{index,Form}.vue 渲染契约, 0 自创逻辑
- webapi 镜像 (loadWorkflow.getInfo) 拿 schema, 跟 form module 走同一 webapi-loader 模式
- storage snapshot 复用 (~/.dacli-snapshots/<appCode>.json), 一次性 login 跨 module 共享
129 lines
4.3 KiB
TypeScript
129 lines
4.3 KiB
TypeScript
/**
|
|
* tc-b-browser.spec.ts — TC-B 浏览器真实行为验证自动化 (v0.21+, 2026-07-12)
|
|
*
|
|
* 目的: 集成 `dacli test browser` (playwright) 进 vitest, 跟 TC-C 联动:
|
|
* - TC-C 静态分析通过 → 不跑 TC-B (避免冗余)
|
|
* - TC-C FAIL → 跑 TC-B 找具体 DOM 异常
|
|
*
|
|
* 5 form · workSystem (实测 7/7 PASS):
|
|
* - hesuanjiancedengji, testcustomer, testreceivable, yaofangguanli, baomingguanli
|
|
*
|
|
* 跑法: npx vitest run tests/integration/drift/tc-b-browser.spec.ts
|
|
* 集成: 可入 CI (需 docker playwright + chromium)
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll } from 'vitest'
|
|
import { execFile } from 'child_process'
|
|
import { promisify } from 'util'
|
|
import { existsSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
|
|
const execFileP = promisify(execFile)
|
|
const DACLI_ROOT = resolve(__dirname, '../../../')
|
|
|
|
// 5 form · workSystem
|
|
const FORMS = [
|
|
{ enCode: 'hesuanjiancedengji', formId: '469038006062344581', expectPass: 7 },
|
|
{ enCode: 'testcustomer', formId: '468842471892247429', expectPass: 7 },
|
|
{ enCode: 'testreceivable', formId: '468826463014018501', expectPass: 7 },
|
|
{ enCode: 'yaofangguanli', formId: '468849844170057541', expectPass: 7 },
|
|
{ enCode: 'baomingguanli', formId: '468848215723140933', expectPass: 7 },
|
|
]
|
|
|
|
interface BrowserResult {
|
|
check: string
|
|
status: 'PASS' | 'FAIL'
|
|
}
|
|
|
|
interface BrowserOutput {
|
|
module: string
|
|
formId: string
|
|
appCode: string
|
|
realUrl: string
|
|
totalChecks: number
|
|
pass: number
|
|
fail: number
|
|
duration: number
|
|
results: BrowserResult[]
|
|
}
|
|
|
|
async function runBrowser(formId: string, appCode = 'workSystem'): Promise<BrowserOutput> {
|
|
let stdout = ''
|
|
try {
|
|
const r = await execFileP('npx', [
|
|
'tsx', 'src/cli.ts', 'test', 'browser',
|
|
'--module=form',
|
|
`--formId=${formId}`,
|
|
`--appCode=${appCode}`,
|
|
'--json',
|
|
], {
|
|
cwd: DACLI_ROOT,
|
|
maxBuffer: 50 * 1024 * 1024,
|
|
})
|
|
stdout = r.stdout
|
|
} catch (e: any) {
|
|
// FAIL render exit code=1, 但 stdout 仍有 JSON
|
|
stdout = e.stdout || ''
|
|
}
|
|
if (!stdout) throw new Error(`browser ${formId} 返回空 stdout`)
|
|
return JSON.parse(stdout)
|
|
}
|
|
|
|
describe('TC-B 浏览器真实行为验证 (playwright, 跟 render 互补)', () => {
|
|
beforeAll(() => {
|
|
const tokenFile = `${process.env.HOME}/.dacli-token/token.json`
|
|
if (!existsSync(tokenFile)) {
|
|
throw new Error(`dacli 未登录, 请先: cd ${DACLI_ROOT} && npx tsx src/cli.ts app login --account=admin --password=123456 --appCode=workSystem`)
|
|
}
|
|
// snapshot 文件应在 (dacli test browser 第一次跑会生成)
|
|
const snap = `${process.env.HOME}/.dacli-snapshots/workSystem.json`
|
|
if (!existsSync(snap)) {
|
|
console.warn(`⚠️ storage snapshot 不存在 (${snap}), 测试会先 login 拿 snapshot (~8s 额外耗时)`)
|
|
}
|
|
})
|
|
|
|
describe.each(FORMS)('form $enCode (formId=$formId)', ({ formId, expectPass }) => {
|
|
let output: BrowserOutput
|
|
|
|
beforeAll(async () => {
|
|
output = await runBrowser(formId)
|
|
}, 60000)
|
|
|
|
it(`总通过数 = ${expectPass} (7 检查 baseline 已知状态)`, () => {
|
|
expect(output.pass).toBe(expectPass)
|
|
})
|
|
|
|
it(`失败数 = ${7 - expectPass}`, () => {
|
|
expect(output.fail).toBe(7 - expectPass)
|
|
})
|
|
|
|
it('realUrl 形如 model/<enCode-with-suffix>', () => {
|
|
// URL 必须含 6 字符 hash suffix (8a3aa, f568d 等), 不能只是 enCode
|
|
expect(output.realUrl).toMatch(/model\/[a-z_0-9]+[0-9a-f]{4,8}$/)
|
|
})
|
|
|
|
const expectedChecks = [
|
|
'页面加载 (Vue 接管)',
|
|
'列表 table 渲染',
|
|
'新增 button 存在',
|
|
'form 编辑页',
|
|
'命名约定',
|
|
'dict select 字段可达',
|
|
'formItem label 完整性',
|
|
]
|
|
|
|
it.each(expectedChecks)('检查 "%s" 存在', (checkSubstr) => {
|
|
const found = output.results.find(r => r.check.includes(checkSubstr))
|
|
expect(found).toBeDefined()
|
|
expect(['PASS', 'FAIL']).toContain(found!.status)
|
|
})
|
|
})
|
|
|
|
describe('TC-B 跟 TC-C 联动 (Round 4 后续)', () => {
|
|
it.skip('placeholder: TC-C FAIL → 跑 TC-B (Round 4 实现)', () => {
|
|
// 思路: 先 `dacli test render --module=form --formId=X` 看结果
|
|
// 如果 FAIL 才调 browser (避免冗余 30s 浏览器调用)
|
|
// 当前先 skip, 等 Round 4 跑多 form 跑通再实现
|
|
})
|
|
})
|
|
}) |