docs: 测试驱动的文档(test-agent → ✅ + 真实示例)#201
Merged
Merged
Conversation
用同一 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
erest 的文档生成与测试脚手架在 src 层是联动的(
.success()翻转tested→ ✅;.takeExample()回填真实示例),但 examples 和 README 都没体现这套「测试即文档」的实践:examples/docs/generate.js只装配实例 + genDocs,不跑请求 → 文档全是 ❌、无示例(mock 模式)examples/test/api.test.js跑了.takeExample()但 afterAll 不调 genDocs → 测试与文档脱节takeExample/tested/ ✅ 的语义和联动改动
1. 新增
examples/docs/generate-from-test.js— 测试驱动文档脚本在同一 ERest 实例上跑 test-agent 真实请求(
.success().takeExample()),让文档通过测试变绿:tested标记翻转),未测的保持 ❌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 个路由通过测试变绿 ✅pnpm --filter erest-example test仍 13/13 全绿__dirnamewarning)