diff --git a/.gitignore b/.gitignore index 7f29f2c..8e13ccd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ src/data/*.json # dacli codegen 输出 (form codegen --out 默认 ./generated/, 不入库) generated/ +.playwright-cli/ diff --git a/src/commands/test/gen.ts b/src/commands/test/gen.ts deleted file mode 100644 index 76042ce..0000000 --- a/src/commands/test/gen.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * commands/testcase/gen.ts — 生成测试脚本 (P1, 暂 stub) - * - * 设计: 从 form schema 生成可重用的 shell/curl 脚本, 用户可手动执行. - * 当前为 stub, 仅 print "TODO" + 列出设计. 后续实现: - * 1. 读 formData.fields + tables - * 2. 推导 sample data (复用 run.ts 的 buildSampleData) - * 3. 输出 shell 脚本 (.sh): - * - POST create + capture id - * - GET info + jq assert - * - PUT update + jq assert - * - DELETE cleanup - * 4. 输出 pytest/python 脚本 (.py) 备用 - */ -import { Command } from 'commander' -import { installAiHelpHook } from '../../core/help.ts' -import { log } from '../../core/log.ts' - -interface GenOpts { - formId: string - output?: string - format?: 'sh' | 'py' -} - -export function buildTestGenCommand(): Command { - const cmd = new Command('gen') - .description('从 form schema 生成可重用的测试脚本 (P1 stub)') - .requiredOption('--formId ', '目标 form id') - .option('--output ', '输出脚本路径 (默认 stdout)') - .option('--format ', '输出格式 (默认 sh)', 'sh') - .action(async (opts: GenOpts) => { - log.warn('testcase gen 暂为 stub (P1, 设计中).') - log.info('计划:') - log.info(' 1. 读 form schema 推导 sample data') - log.info(' 2. 输出 shell 脚本 (POST/GET/PUT/DELETE + jq assert)') - log.info(' 3. 或输出 python 脚本 (pytest 兼容)') - log.info('参考: testcase/run.ts 已实现核心逻辑, 可复用 buildSampleData()') - log.info('') - log.info(`参数: formId=${opts.formId} format=${opts.format} output=${opts.output || 'stdout'}`) - }) - - installAiHelpHook(cmd, { - purpose: '从 form schema 生成可重用的测试脚本 (P1 stub, 设计中)', - required: { '--formId': '目标 form id' }, - optional: { - '--output': '输出脚本路径', - '--format': 'sh / py', - }, - example: [ - 'dacli testcase gen --formId=839877227762942789', - 'dacli testcase gen --formId=839877227762942789 --output=/tmp/test.sh --format=sh', - ], - source: { api: '读取 form schema → 输出可执行 shell/python 脚本' }, - notes: [ - '**P1 stub** (2026-06-25): 复用 `dacli testcase run` 的 buildSampleData 逻辑', - '**vs testcase/run**: run 是直接调 API + 报告. gen 是生成可复用脚本 (用户保存 + CI 集成)', - ], - }) - return cmd -} \ No newline at end of file diff --git a/src/commands/test/generate.ts b/src/commands/test/generate.ts new file mode 100644 index 0000000..d61b87e --- /dev/null +++ b/src/commands/test/generate.ts @@ -0,0 +1,237 @@ +/** + * commands/test/generate.ts — 生成浏览器 E2E 脚本 (覆盖 API 测不到的 vmodel bind) + * + * 思路: + * - 读 form schema (formData + tables) + * - 推导必填字段 + sample data (复用 buildSampleData) + * - 输出 playwright bash 脚本: + * 1. login + * 2. goto /jnpf_app_{appCode}/model/{enCode} + * 3. click 新增 + * 4. fillByLabel 每个必填字段 + * 5. saveModal + * 6. waitRowCountChange (+1) + * 7. 验证: list 含新数据 + * - 输出后用户运行 `playwright -s=tddXX -e