// dacli/tests/e2e/verify-form-e2e.spec.ts /** * verify-form e2e (5 case) * * 注: workSystem 路由 404 已知,这些 case 主要验证 verify-form.ts 子进程能 spawn + 返 JSON * (用 --verify=warn 兜底场景) */ import { test, expect } from '@playwright/test' import { spawn } from 'node:child_process' import { join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' // ROOT = dacli/ 项目根 (此文件位于 dacli/tests/e2e/) const ROOT = resolve(fileURLToPath(import.meta.url), '../../..') async function runVerifyCli(args: string[], cwd = ROOT): Promise<{ ok: boolean; code: number; output: string }> { return new Promise(resolve => { const child = spawn('npx', ['tsx', 'tests/e2e/verify-form.ts', ...args], { cwd }) let output = '' child.stdout.on('data', d => { output += d.toString() }) child.stderr.on('data', d => { output += d.toString() }) child.on('close', code => resolve({ ok: code === 0, code, output })) }) } test.describe('verify-form e2e (5 case)', () => { test('1. nonexistent formId → 返 ok=false (路由 404)', async () => { const r = await runVerifyCli([ '--formId=999999999999999999', '--enCode=nonexist', '--appCode=workSystem', ]) expect(r.output).toContain('"ok": false') expect(r.code).toBe(1) }, 60_000) test('2. 无效 appCode → 返 ok=false', async () => { const r = await runVerifyCli([ '--formId=585398402720727621', '--enCode=paymentapply', '--appCode=nonexist_app', ]) expect(r.output).toContain('"ok": false') }, 60_000) test('3. paymentapply + --menuEnCode=fksqzy → 8 步有输出 (workSystem 路由 404 fail)', async () => { const r = await runVerifyCli([ '--formId=585398402720727621', '--enCode=paymentapply', '--appCode=workSystem', '--menuEnCode=fksqzy', ]) // workSystem 路由 404 已知, 验证 JSON 输出格式正确 expect(r.output).toContain('---JSON-START---') expect(r.output).toContain('---JSON-END---') expect(r.output).toMatch(/"name":\s*"(open-browser|login|open-list|check-list)"/) }, 120_000) test('4. 缺 formId 参数 → exit 2', async () => { const r = await runVerifyCli(['--enCode=x', '--appCode=workSystem']) expect(r.code).toBe(2) expect(r.output).toContain('用法:') }, 30_000) test('5. 5 张 form 并行 (压力测, 检查 stdout 隔离)', async () => { const forms = [ ['585398402720727621', 'paymentapply'], ['1589964488616407041', 'leaveApply'], ['585077579715707205', 'caigouhetong'], ['623163913990570181', 'staffinform'], ['624163990351643525', 'ruzhishenq'], ] const results = await Promise.all(forms.map(([id, ec]) => runVerifyCli(['--formId=' + id, '--enCode=' + ec, '--appCode=workSystem']) )) // 5 个都返 JSON (workSystem 路由 404 已知, 但 stdout 协议必须 OK) for (const r of results) { expect(r.output).toContain('---JSON-START---') expect(r.output).toContain('---JSON-END---') } }, 180_000) })