Skip to content

docs: 测试驱动的文档(test-agent → ✅ + 真实示例)#201

Merged
yourtion merged 3 commits into
mainfrom
feat/docs-driven-by-test
Jul 8, 2026
Merged

docs: 测试驱动的文档(test-agent → ✅ + 真实示例)#201
yourtion merged 3 commits into
mainfrom
feat/docs-driven-by-test

Conversation

@yourtion

@yourtion yourtion commented Jul 8, 2026

Copy link
Copy Markdown
Owner

背景

erest 的文档生成与测试脚手架在 src 层是联动的(.success() 翻转 tested → ✅;.takeExample() 回填真实示例),但 examples 和 README 都没体现这套「测试即文档」的实践:

  • examples/docs/generate.js 只装配实例 + genDocs,不跑请求 → 文档全是 ❌、无示例(mock 模式)
  • examples/test/api.test.js 跑了 .takeExample() 但 afterAll 不调 genDocs → 测试与文档脱节
  • README 完全没文档化 takeExample / tested / ✅ 的语义和联动

改动

1. 新增 examples/docs/generate-from-test.js — 测试驱动文档脚本

在同一 ERest 实例上跑 test-agent 真实请求(.success().takeExample()),让文档通过测试变绿:

  • 被测路由显示 ✅(tested 标记翻转),未测的保持 ❌
  • 「使用示例」段落的 output 是真实响应(非 mock)
pnpm --filter erest-example docs:test    # 测试驱动文档(✅ + 真实示例)
pnpm --filter erest-example docs         # 对比:mock 文档(全 ❌、无示例)

2. README 新增「测试驱动的文档」章节 + 「测试脚手架」节补充 .takeExample(name) 说明

文档化 tested(✅) + takeExample 与 genDocs 的联动机制,含完整代码示例。

3. examples/README 能力表 / 目录结构 / 文档生成节补充 docs:test

不改动

  • examples/docs/generate.js(mock 文档,保留作对比)
  • examples/test/api.test.js(纯测试,保留)
  • src/(erest 源码)

验证

  • pnpm --filter erest-example docs:test 跑通,输出 6/9 个路由通过测试变绿 ✅
  • 产出的 markdown 标题带 ✅、含「使用示例」段落(真实种子数据)
  • pnpm --filter erest-example test 仍 13/13 全绿
  • oxlint 0 error(与现有 generate.js 同样的 1 个 __dirname warning)

yourtion added 2 commits July 8, 2026 22:07
用同一 ERest 实例跑 test-agent 真实请求(.success().takeExample()),
让文档通过测试变绿(✅)并用真实响应填充示例。与现有 generate.js(mock 模式)对比。

运行:npm run docs:test(vs npm run docs 的 mock 模式)
产出:docs/out-from-test/,6/9 路由 ✅
- README「测试脚手架」节补充 .takeExample(name) 语义
- 新增「测试驱动的文档」章节:讲 tested(✅) + takeExample 与 genDocs 的联动
- examples/README 能力表 + 目录结构 + 文档生成节补充 docs:test
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.47%. Comparing base (1a5d8cc) to head (a3b01e1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #201   +/-   ##
=======================================
  Coverage   92.47%   92.47%           
=======================================
  Files          28       28           
  Lines        2883     2883           
  Branches      747      747           
=======================================
  Hits         2666     2666           
  Misses        215      215           
  Partials        2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yourtion yourtion merged commit 0e09ae8 into main Jul 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant