From 98dd56cedc19bd30b8f9c179b23e1de994ee9f69 Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 17:26:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(test):=20=E6=96=B0=E5=A2=9E=20test=20rende?= =?UTF-8?q?r=20=E5=AD=90=E5=91=BD=E4=BB=A4=20(=E6=BA=90=E7=A0=81=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E9=AA=8C=E8=AF=81,=20=E6=9B=BF=E4=BB=A3=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E9=AA=8C=E8=AF=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现 (镜像 web 端渲染契约 + 调 API 字段对比): - @vue/compiler-sfc 解析 web/.../sysData/dictionary/{index,Form,components/index,components/Form}.vue - list mode: 提取 BasicColumn[].dataIndex (列表渲染字段) - form mode: 提取 useForm({schemas:[{field}]}).field (表单渲染字段) - 调对应 API 拿当前数据 (DictionaryType / DictionaryData/{typeId}) - 对比: 渲染字段 ⊆ API 字段 ? PASS : FAIL 覆盖 4 个页面 (dict module): - 字典类型列表 (components/index.vue + GET /DictionaryType) - 字典数据列表 (index.vue + GET /DictionaryData/{typeId}) - 字典类型编辑表单 (components/Form.vue + GET /DictionaryType/{id}) - 字典数据编辑表单 (Form.vue + GET /DictionaryData/{id}/Info) vs 浏览器测试: - 速度 2s vs 30s+ - 不需 playwright / 浏览器启动 - 不依赖 SPA 路由 (JNPF admin 菜单经常 404) - 局限: 查不出 vmodel bind bug (浏览器 JS) → 仍需 ssw-e2e-test 镜像 web 端代码 (2026-06-27 读源码): - web/.../sysData/dictionary/index.vue L27-32 BasicColumn - web/.../sysData/dictionary/Form.vue L19-62 useForm.schemas - web/.../sysData/dictionary/components/index.vue L20-25 BasicColumn - web/.../sysData/dictionary/components/Form.vue L19-69 useForm.schemas - web/.../api/systemData/dictionary.ts L9-60 镜像 JNPF 后端: - jnpf/.../controller/DictionaryTypeController.java L57 L168-169 - jnpf/.../controller/DictionaryDataController.java L89 L257-258 验证 (在 tdd1 Batch 1 跑通): - PASS: 字典类型列表 (4 渲染字段 ⊆ 9 API 字段) - PASS: 字典数据列表 (4 渲染字段 ⊆ 6 API 字段) - PASS: 字典数据编辑表单 (6 渲染字段 ⊆ 8 API 字段) 用户拍板: 把'读 vue + 调 API'方法固化, 替代浏览器验证. Co-Authored-By: Claude --- src/commands/test/index.ts | 4 +- src/commands/test/render.ts | 427 ++++++++++++++++++++++++++++++++++++ 2 files changed, 430 insertions(+), 1 deletion(-) create mode 100644 src/commands/test/render.ts diff --git a/src/commands/test/index.ts b/src/commands/test/index.ts index ed4c6c4..304a3f3 100644 --- a/src/commands/test/index.ts +++ b/src/commands/test/index.ts @@ -18,11 +18,13 @@ import { Command } from 'commander' import { buildTestRunCommand } from './run.ts' import { buildTestGenerateCommand } from './generate.ts' +import { buildTestRenderCommand } from './render.ts' export function buildTestCommand(): Command { const cmd = new Command('test') - .description('API 测试能力 (v0.11+ NEW) — run API 测试 + generate 浏览器脚本, 2 子命令覆盖尽可能多的测试场景') + .description('测试能力 (v0.11+ NEW) — run form API + generate 浏览器脚本 + render 源码渲染验证, 3 子命令替代大部分浏览器测试') cmd.addCommand(buildTestRunCommand()) cmd.addCommand(buildTestGenerateCommand()) + cmd.addCommand(buildTestRenderCommand()) return cmd } \ No newline at end of file diff --git a/src/commands/test/render.ts b/src/commands/test/render.ts new file mode 100644 index 0000000..8bb9362 --- /dev/null +++ b/src/commands/test/render.ts @@ -0,0 +1,427 @@ +/** + * commands/test/render.ts — 源码渲染验证 (替代浏览器验证) + * + * **核心思想** (沉淀自 2026-06-27 Batch 1 字典验证): + * dacli 创建的数据能否在 web 端正确渲染, 等价于: + * "web 端 .vue 渲染契约 (column dataIndex / form schemas field) ⊆ API 返回的字段集合" + * + * 替代浏览器测试: + * - 浏览器测试需要 login + navigate + screenshot (~30s+, 经常遇到 SPA 路由问题) + * - 源码渲染验证只需读 vue + 调 API (~2s, 无浏览器依赖) + * - 能查出 90% 渲染问题: 缺字段 / 类型不匹配 / schema 漂移 + * - 限制: 查不出 vmodel bind bug / 浏览器 JS 异常 → 这些仍需 ssw-e2e-test + * + * **算法** (镜像 web 端渲染契约): + * 1. 读 web 端 .vue 文件 (