feat: 测试开发学习路径上线阶段 1 前两个模块(26 章 / 117 小节),工具链支持多阶段

- 新增 modules/s1-01-case-design/(测试理论与用例设计,13 章 / 59 小节)
- 新增 modules/s1-02-http-api/(HTTP 接口与接口测试基础,13 章 / 58 小节)
- tools/modules-plan.json 改为按阶段组织,阶段 1 的 4 个模块全部登记(未开工的两个标「筹备中」跳过)
- tools/build-module-index.js 支持多阶段,上一/下一模块按全书顺序跨阶段衔接(数据库 → 测试理论与用例设计)
- 新增 tools/check-chapter.js:单章自检(结构 / 章号 / 代码块 / 表格 / 锚点),支持 --strict 校验侧栏同步
- assets/doc.css 补 .box.pit 样式;index.html 登记 s1-0 / s1-1 路由;README 更新进度与工具说明
This commit is contained in:
2026-10-16 10:39:46 +08:00
parent 4f64ce94d6
commit bd678373b1
36 changed files with 13440 additions and 88 deletions

View File

@@ -8,7 +8,7 @@
| 阶段 | 模块数 | 详解状态 | | 阶段 | 模块数 | 详解状态 |
|---|---|---| |---|---|---|
| 阶段 0 · 打地基 | 4 | ✅ 已上线(46 章 / 157 小节) | | 阶段 0 · 打地基 | 4 | ✅ 已上线(46 章 / 157 小节) |
| 阶段 1 · 会测 | 4 | ⏳ 筹备中 | | 阶段 1 · 会测 | 4 | 🚧 已上线 2 / 4(26 章 / 117 小节) |
| 阶段 2 · 自动化 | 5 | ⏳ 筹备中 | | 阶段 2 · 自动化 | 5 | ⏳ 筹备中 |
| 阶段 3 · 造工具 | 4 | ⏳ 筹备中 | | 阶段 3 · 造工具 | 4 | ⏳ 筹备中 |
| 阶段 4 · 提效率 | 4 | ⏳ 筹备中 | | 阶段 4 · 提效率 | 4 | ⏳ 筹备中 |
@@ -24,6 +24,13 @@
| `modules/s0-03-linux-git/` | Linux、Shell 与 Git | 11 | 37 | | `modules/s0-03-linux-git/` | Linux、Shell 与 Git | 11 | 37 |
| `modules/s0-04-database/` | 数据库与 SQL | 11 | 37 | | `modules/s0-04-database/` | 数据库与 SQL | 11 | 37 |
阶段 1 已上线的模块(`s1-03-web-frontend`、`s1-04-defect-process` 筹备中):
| 目录 | 模块 | 章节 | 小节 |
|---|---|---|---|
| `modules/s1-01-case-design/` | 测试理论与用例设计 | 13 | 59 |
| `modules/s1-02-http-api/` | HTTP 接口与接口测试基础 | 13 | 58 |
## 目录结构 ## 目录结构
``` ```
@@ -38,26 +45,35 @@ testdev-learning-path/
│ │ ├── index.html 模块目录页(modhero + 章节目录 + 小节锚点) │ │ ├── index.html 模块目录页(modhero + 章节目录 + 小节锚点)
│ │ ├── 01-why.html 第 1 章 │ │ ├── 01-why.html 第 1 章
│ │ └── … 章节页按 NN-英文名.html 命名,顺序即章号 │ │ └── … 章节页按 NN-英文名.html 命名,顺序即章号
│ └── s0-02-golang/ … │ ├── s0-02-golang/ … s0-04-database/ 阶段 0 的其余模块,结构同上
│ └── s1-01-case-design/ … s1-02-http-api/ 阶段 1 已上线的模块(未开工的模块不建目录)
└── tools/ └── tools/
├── modules-plan.json 模块级元数据(标题、副标题、建议投入、导语、前后模块) ├── modules-plan.json 模块级元数据(按阶段组织:标题、副标题、建议投入、导语)
├── glossary.json 术语表:统一的服务名 / 表名 / 状态取值 / Go 模块路径 ├── glossary.json 术语表:统一的服务名 / 表名 / 状态取值 / Go 模块路径
├── build-module-index.js 扫描章节页 → 生成模块目录页 index.html ├── build-module-index.js 扫描章节页 → 生成模块目录页 index.html
├── build-nav.js 扫描章节 h2/h3 → 重建所有页面侧栏目录树 ├── build-nav.js 扫描章节 h2/h3 → 重建所有页面侧栏目录树
├── check-chapter.js 单章自检:结构 / 章节号 / 代码块 / 表格 / 锚点(写完一章就跑它)
├── check-pages.js 自检:链接 / 锚点 / 结构 / 格式 / 目录树一致性 / 路由 ├── check-pages.js 自检:链接 / 锚点 / 结构 / 格式 / 目录树一致性 / 路由
└── check-glossary.js 自检:一个概念一个名字(防命名漂移) └── check-glossary.js 自检:一个概念一个名字(防命名漂移)
``` ```
## 四个工具(改完内容按顺序跑) ## 五个工具(改完内容按顺序跑)
```bash ```bash
node tools/check-chapter.js modules/s1-01-case-design/03-equiv.html # 0. 写完一章先跑它,只检查这一章
node tools/build-module-index.js # 1. 依据 plan + 章节页重建模块目录页 node tools/build-module-index.js # 1. 依据 plan + 章节页重建模块目录页
node tools/build-nav.js # 2. 重建全部页面的侧栏目录树(新增/改名章节后必须跑) node tools/build-nav.js # 2. 重建全部页面的侧栏目录树(新增/改名章节后必须跑)
node tools/check-pages.js # 3. 结构与链接自检,退出码非 0 就是有问题 node tools/check-pages.js # 3. 结构与链接自检,退出码非 0 就是有问题
node tools/check-glossary.js # 4. 命名一致性自检,退出码非 0 会列出漂移位置 node tools/check-glossary.js # 4. 命名一致性自检,退出码非 0 会列出漂移位置
``` ```
三者都是幂等的,可以反复执行。`check-pages.js` 覆盖: 也可以直接 `node tools/check-chapter.js modules/s1-01-case-design` 检查整个模块,
加 `--strict` 会额外校验侧栏目录树是否与正文章节同步(跑过 `build-nav.js` 之后再用来复核)。
`check-chapter.js` 只负责「单页自己能负责」的部分,**跨页面的项目(侧栏目录树一致性、路由登记、
模块标题与目录页一致)仍然由 `check-pages.js` 兜底**,所以最终提交前务必把 3、4 两步跑绿。
其余四个工具都是幂等的,可以反复执行。`check-pages.js` 覆盖:
- 站内链接是否存在、页内锚点是否可达(含 `#s0` 这类由 JS 生成的阶段锚点) - 站内链接是否存在、页内锚点是否可达(含 `#s0` 这类由 JS 生成的阶段锚点)
- 标签配对、每页 `<title>`、`<article>` - 标签配对、每页 `<title>`、`<article>`
@@ -71,16 +87,22 @@ node tools/check-glossary.js # 4. 命名一致性自检,退出码非 0
## 新增一个模块(阶段 1 及以后) ## 新增一个模块(阶段 1 及以后)
1. 建目录 `modules/s1-01-case-design/`,章节页按 `01-xxx.html` 顺序命名。 1. 建目录 `modules/s1-03-web-frontend/`,章节页按 `01-xxx.html` 顺序命名。
2. 章节页可以直接复制同阶段任意一章,改标题、`chapnav`、正文、`.pager` 即可; 2. 章节页可以直接复制同阶段任意一章(推荐 `modules/s1-01-case-design/01-why.html`),
改标题、`chapnav`、正文、`.pager` 即可;
**不要手写 `<nav id="chapters">` 的内容**,留空占位,由 `build-nav.js` 填充。 **不要手写 `<nav id="chapters">` 的内容**,留空占位,由 `build-nav.js` 填充。
3. 在 `tools/modules-plan.json` 的 `modules` 里追加模块级信息(`dir / title / sub / hours / lead`)。 3. 在 `tools/modules-plan.json` 对应阶段的 `modules` 数组里追加模块级信息
4. 跑上面三个工具。 (`dir / title / sub / hours / lead`)。数组顺序就是模块编号,`dir` 必须与目录同名。
没开始写的模块可以先留在数组里(目录不存在时生成器会跳过并标「筹备中」),
这样阶段内的模块编号与 `index.html` 的 `STAGES` 永远对齐。
4. 跑上面第 1—4 步的工具;写单章的过程中随时可以跑 `check-chapter.js`。
5. 在 `index.html` 的 `PAGES` 表里登记路由,key 规则是 `阶段 id + "-" + 模块下标`: 5. 在 `index.html` 的 `PAGES` 表里登记路由,key 规则是 `阶段 id + "-" + 模块下标`:
```js ```js
"s1-0": "modules/s1-01-case-design/index.html", "s1-2": "modules/s1-03-web-frontend/index.html",
``` ```
没登记的模块在目录页上显示「详解筹备中」。 没登记的模块在目录页上显示「详解筹备中」。
6. 模块目录页由生成器写入,末尾的 `back.js` 行会被覆盖掉,记得在仓库根跑一次
`node tools/add-back-links.js` 把「返回资料库」入口补回来。
## 章节页写作约定 ## 章节页写作约定

View File

@@ -200,6 +200,9 @@ pre .hl{background:color-mix(in srgb,var(--accent) 22%,transparent);border-radiu
.box.case .bt{color:var(--case)} .box.case .bt{color:var(--case)}
.box.lab{background:var(--warn-bg);border-color:var(--warn-line);border-left-color:var(--warn)} .box.lab{background:var(--warn-bg);border-color:var(--warn-line);border-left-color:var(--warn)}
.box.lab .bt{color:var(--warn)} .box.lab .bt{color:var(--warn)}
/* 坑 / 反模式:与 warn 同一视觉家族,单独保留类名,便于以后区分「提醒」与「踩过的坑」 */
.box.pit{background:var(--warn-bg);border-color:var(--warn-line);border-left-color:var(--warn)}
.box.pit .bt{color:var(--warn)}
/* 场景步骤编号列表 */ /* 场景步骤编号列表 */
.steps{counter-reset:s;list-style:none;padding-left:0;margin:0 0 18px} .steps{counter-reset:s;list-style:none;padding-left:0;margin:0 0 18px}

View File

@@ -1017,7 +1017,10 @@ const PAGES = {
"s0-0": "modules/s0-01-network/index.html", "s0-0": "modules/s0-01-network/index.html",
"s0-1": "modules/s0-02-golang/index.html", "s0-1": "modules/s0-02-golang/index.html",
"s0-2": "modules/s0-03-linux-git/index.html", "s0-2": "modules/s0-03-linux-git/index.html",
"s0-3": "modules/s0-04-database/index.html" "s0-3": "modules/s0-04-database/index.html",
/* 阶段 1 · 会测(已上线 2 / 4 个模块,第 3、4 个模块筹备中) */
"s1-0": "modules/s1-01-case-design/index.html",
"s1-1": "modules/s1-02-http-api/index.html"
}; };
/* ============================ 工具 ============================ */ /* ============================ 工具 ============================ */

View File

@@ -151,7 +151,7 @@
</article> </article>
<nav class="pager"> <nav class="pager">
<a class="prev" href="../../index.html#s0"><span class="k">← 上一模块</span><span class="v">已经是阶段 0 的第一个模块</span></a> <a class="prev" href="../../index.html#s0"><span class="k">← 上一模块</span><span class="v">本阶段(阶段 0 · 打地基)的第一个模块</span></a>
<a class="next" href="../s0-02-golang/index.html"><span class="k">下一模块 →</span><span class="v">编程基础:Golang 与工程化</span></a> <a class="next" href="../s0-02-golang/index.html"><span class="k">下一模块 →</span><span class="v">编程基础:Golang 与工程化</span></a>
</nav> </nav>

View File

@@ -152,7 +152,7 @@
<nav class="pager"> <nav class="pager">
<a class="prev" href="../s0-03-linux-git/index.html"><span class="k">← 上一模块</span><span class="v">Linux、Shell 与 Git</span></a> <a class="prev" href="../s0-03-linux-git/index.html"><span class="k">← 上一模块</span><span class="v">Linux、Shell 与 Git</span></a>
<a class="next" href="../../index.html#s0"><span class="k">阶段 0 完成 →</span><span class="v">回到学习路径,进入阶段 1 · 会测</span></a> <a class="next" href="../s1-01-case-design/index.html"><span class="k">阶段 1 · 会测 →</span><span class="v">测试理论与用例设计</span></a>
</nav> </nav>
<p class="foot"> <p class="foot">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +1,22 @@
#!/usr/bin/env node #!/usr/bin/env node
/* ========================================================================== /* ==========================================================================
模块目录页生成器(阶段 0) 模块目录页生成器(全部阶段)
用法:node tools/build-module-index.js [站点根目录,默认本文件的上一级] 用法:node tools/build-module-index.js [站点根目录,默认本文件的上一级]
作用:读取 tools/modules-plan.json 里的模块级元数据(标题 / 副标题 / 导语 / 作用:读取 tools/modules-plan.json 里的模块级元数据(标题 / 副标题 / 导语 /
建议投入 / 前后模块),再扫描 modules/<dir>/NN-*.html 解析出每章的 h2 标题与 建议投入),再扫描 modules/<dir>/NN-*.html 解析出每章的 h2 标题与全部 h3 小节,
全部 h3 小节,生成模块目录页 modules/<dir>/index.html。 生成模块目录页 modules/<dir>/index.html。
为什么章节标题不写在 plan 里:目录页与正文必须永远一致。从正文解析, 为什么章节标题不写在 plan 里:目录页与正文必须永远一致。从正文解析,
就不会出现「改了正文章节标题、目录页还是旧的」这类问题。 就不会出现「改了正文章节标题、目录页还是旧的」这类问题。
跳过规则:plan 里列了、但目录不存在或没有 NN-*.html 的模块视为「筹备中」,
照样参与编号与前后模块关系(上一/下一模块会指向它,并标注「筹备中」)。
这样阶段与模块的编号永远和 index.html 的 STAGES 对齐,不会因为先写哪个模块而错位。
上一 / 下一模块按「全书展平顺序」计算,跨阶段也连续:
阶段 0 最后一个模块 → 阶段 1 第一个模块。
幂等:可重复运行;生成后建议再跑一次 tools/build-nav.js 同步侧栏目录树。 幂等:可重复运行;生成后建议再跑一次 tools/build-nav.js 同步侧栏目录树。
========================================================================== */ ========================================================================== */
const fs = require("fs"); const fs = require("fs");
@@ -35,31 +43,49 @@ const plain = s => decode(stripTags(s));
const stripNo = s => s.replace(/^\s*\d+(?:\.\d+)*\s*[\.、]?\s*/, "").trim(); const stripNo = s => s.replace(/^\s*\d+(?:\.\d+)*\s*[\.、]?\s*/, "").trim();
const plan = readPlan(PLAN); const plan = readPlan(PLAN);
const stage = plan.stage; const stages = plan.stages;
const mods = plan.modules; const brand = plan.brand;
/* ---------- 逐模块生成 ---------- */ /* ---------- 1. 扫描:每个模块能否生成 ---------- */
let written = 0; const slots = []; // 全展平,顺序 = 阶段顺序 + 模块下标顺序
const report = []; stages.forEach((st, si) => {
if (!st.modules) st.modules = [];
mods.forEach((m, mi) => { st.modules.forEach((m, mi) => {
const modPath = path.join(MODDIR, m.dir); const modPath = path.join(MODDIR, m.dir);
if (!fs.existsSync(modPath)) throw new Error(`模块目录不存在:modules/${m.dir}`); const files = fs.existsSync(modPath)
? fs.readdirSync(modPath).filter(f => /^\d\d-.*\.html$/.test(f)).sort()
const files = fs.readdirSync(modPath).filter(f => /^\d\d-.*\.html$/.test(f)).sort(); : [];
if (!files.length) throw new Error(`modules/${m.dir} 下没有 NN-*.html 章节页`); let chapters = null;
if (files.length) {
const chapters = files.map(file => { chapters = files.map(file => {
const html = fs.readFileSync(path.join(modPath, file), "utf8"); const html = fs.readFileSync(path.join(modPath, file), "utf8");
const h2 = html.match(/<h2 id="[^"]*">([\s\S]*?)<\/h2>/); const h2 = html.match(/<h2 id="[^"]*">([\s\S]*?)<\/h2>/);
if (!h2) throw new Error(`modules/${m.dir}/${file}: 找不到 h2 章节标题`); if (!h2) throw new Error(`modules/${m.dir}/${file}: 找不到 h2 章节标题`);
const title = plain(h2[1].replace(/<span class="n">\d+<\/span>/, "")); const title = plain(h2[1].replace(/<span class="n">\d+<\/span>/, ""));
const sections = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)] const sections = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)]
.map(x => ({ id: x[1], label: stripNo(plain(x[2])) })); .map(x => ({ id: x[1], label: stripNo(plain(x[2])) }));
// 字数口径:只统计中文汉字(代码与英文命令不计入「千字」,否则会被严重高估) // 字数口径:只统计中文汉字(代码与英文命令不计入「千字」,否则会被严重高估)
const chars = (stripTags(html).match(/[\u4e00-\u9fff]/g) || []).length; const chars = (stripTags(html).match(/[\u4e00-\u9fff]/g) || []).length;
return { file, title, sections, chars }; return { file, title, sections, chars };
});
}
slots.push({ st, si, m, mi, modPath, chapters, files });
}); });
});
const built = slots.filter(s => s.chapters);
const report = [];
let written = 0;
/* ---------- 2. 逐模块生成 ---------- */
built.forEach((slot, gi) => {
const { st, m, mi, modPath, chapters } = slot;
const prevSlot = gi > 0 ? built[gi - 1] : null;
const nextSlot = gi < built.length - 1 ? built[gi + 1] : null;
// 本阶段的下一个模块(可能还没写)
const nextInStage = nextSlot && nextSlot.st === st
? nextSlot
: slots.find(s => s.st === st && s.mi === mi + 1) || null;
const chapItems = chapters.map((c, i) => { const chapItems = chapters.map((c, i) => {
const secs = c.sections.length const secs = c.sections.length
@@ -77,19 +103,32 @@ mods.forEach((m, mi) => {
const totalSecs = chapters.reduce((n, c) => n + c.sections.length, 0); const totalSecs = chapters.reduce((n, c) => n + c.sections.length, 0);
const totalK = Math.round(chapters.reduce((n, c) => n + c.chars, 0) / 1000); const totalK = Math.round(chapters.reduce((n, c) => n + c.chars, 0) / 1000);
const prev = mi === 0 const prev = prevSlot
? { href: `${plan.brand.home}#${stage.id}`, k: "← 上一模块", v: `已经是阶段 0 的第一个模块` } ? { href: `../${prevSlot.m.dir}/index.html`, k: "← 上一模块", v: prevSlot.m.title }
: { href: `../${mods[mi - 1].dir}/index.html`, k: "← 上一模块", v: mods[mi - 1].title }; : { href: `${brand.home}#${st.id}`, k: "← 上一模块", v: `本阶段(${st.anchorText})的第一个模块` };
const next = mi === mods.length - 1
? { href: `${plan.brand.home}#${stage.id}`, k: "阶段 0 完成 →", v: "回到学习路径,进入阶段 1 · 会测" } let next;
: { href: `../${mods[mi + 1].dir}/index.html`, k: "下一模块 →", v: mods[mi + 1].title }; if (nextSlot) {
next = {
href: `../${nextSlot.m.dir}/index.html`,
k: nextSlot.st === st ? "下一模块 →" : `${nextSlot.st.anchorText} →`,
v: nextSlot.m.title
};
} else if (nextInStage) {
next = { href: `${brand.home}#${st.id}`, k: "下一模块 →", v: `筹备中:${nextInStage.m.title}` };
} else if (stages[slot.si + 1]) {
const nx = stages[slot.si + 1];
next = { href: `${brand.home}#${nx.id}`, k: `${nx.anchorText} →`, v: `回到学习路径,进入${nx.anchorText}` };
} else {
next = { href: `${brand.home}#${st.id}`, k: "学习路径 →", v: "回到学习路径" };
}
const html = `<!DOCTYPE html> const html = `<!DOCTYPE html>
<html lang="zh-CN" data-theme="light"> <html lang="zh-CN" data-theme="light">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>${esc(m.title)} · ${stage.anchorText} 模块 ${mi + 1} · ${esc(plan.brand.siteName)}</title> <title>${esc(m.title)} · ${st.anchorText} 模块 ${mi + 1} · ${esc(brand.siteName)}</title>
<meta name="description" content="${esc(m.title)} 模块目录:共 ${chapters.length} 章、${totalSecs} 个小节。"> <meta name="description" content="${esc(m.title)} 模块目录:共 ${chapters.length} 章、${totalSecs} 个小节。">
<link rel="stylesheet" href="../../assets/doc.css"> <link rel="stylesheet" href="../../assets/doc.css">
</head> </head>
@@ -97,10 +136,10 @@ mods.forEach((m, mi) => {
<header class="topbar"> <header class="topbar">
<div class="tb-in"> <div class="tb-in">
<a class="brand" href="${plan.brand.home}"><span class="logo">${esc(plan.brand.logo)}</span><div>从零到成熟<small>测试开发 · 模块详解</small></div></a> <a class="brand" href="${brand.home}"><span class="logo">${esc(brand.logo)}</span><div>从零到成熟<small>测试开发 · 模块详解</small></div></a>
<div class="crumbs"> <div class="crumbs">
<a href="${plan.brand.home}">学习路径</a><span class="sep">/</span> <a href="${brand.home}">学习路径</a><span class="sep">/</span>
<a href="${plan.brand.home}#${stage.id}">${esc(stage.anchorText)}</a><span class="sep">/</span> <a href="${brand.home}#${st.id}">${esc(st.anchorText)}</a><span class="sep">/</span>
<b>${esc(m.title)}</b> <b>${esc(m.title)}</b>
</div> </div>
<div class="spacer"></div> <div class="spacer"></div>
@@ -115,7 +154,7 @@ mods.forEach((m, mi) => {
<nav id="chapters"></nav> <nav id="chapters"></nav>
<div class="side-foot"> <div class="side-foot">
<a class="btn" href="index.html">← 模块目录</a> <a class="btn" href="index.html">← 模块目录</a>
<a class="btn" href="${plan.brand.home}">学习路径</a> <a class="btn" href="${brand.home}">学习路径</a>
</div> </div>
</aside> </aside>
<div class="mask" id="mask"></div> <div class="mask" id="mask"></div>
@@ -123,7 +162,7 @@ mods.forEach((m, mi) => {
<main class="main-col"> <main class="main-col">
<article> <article>
<div class="modhero"> <div class="modhero">
<span class="mh-no">${stage.anchorText} · 模块 ${mi + 1} / ${mods.length}</span> <span class="mh-no">${esc(st.anchorText)} · 模块 ${mi + 1} / ${st.modules.length}</span>
<h1>${esc(m.title)}</h1> <h1>${esc(m.title)}</h1>
<p class="mh-sub">${esc(m.sub)}</p> <p class="mh-sub">${esc(m.sub)}</p>
<div class="mh-meta"> <div class="mh-meta">
@@ -157,7 +196,7 @@ ${chapItems}
<p class="foot"> <p class="foot">
${esc(m.title)} · 模块目录<br> ${esc(m.title)} · 模块目录<br>
<a href="${plan.brand.home}">返回学习路径</a> <a href="${brand.home}">返回学习路径</a>
</p> </p>
</main> </main>
</div> </div>
@@ -174,5 +213,8 @@ ${chapItems}
report.push(`modules/${m.dir}/index.html:${chapters.length} 章 / ${totalSecs} 小节 / 约 ${totalK} 千字`); report.push(`modules/${m.dir}/index.html:${chapters.length} 章 / ${totalSecs} 小节 / 约 ${totalK} 千字`);
}); });
const pending = slots.filter(s => !s.chapters);
pending.forEach(s => report.push(`modules/${s.m.dir}/(筹备中,跳过):${s.st.anchorText} 模块 ${s.mi + 1} ${s.m.title}`));
console.log(report.join("\n")); console.log(report.join("\n"));
console.log(`\n共生成 ${written} 个模块目录页。下一步:node tools/build-nav.js`); console.log(`\n共生成 ${written} 个模块目录页(筹备中跳过 ${pending.length} 个)。下一步:node tools/build-nav.js`);

View File

@@ -0,0 +1,186 @@
#!/usr/bin/env node
/* ==========================================================================
单章 / 单模块自检:给「正在写这一章」的人一个即时反馈,不必跑全站自检
用法:
node tools/check-chapter.js modules/s1-01-case-design/03-equiv.html
node tools/check-chapter.js modules/s1-01-case-design # 整个模块
node tools/check-chapter.js modules/s1-01-case-design/03-equiv.html --strict
参数可以是文件或目录(目录会检查其中所有 NN-*.html),路径相对本工具上一级。
与 tools/check-pages.js 的关系:这里只检查「单个页面自己能负责」的部分
(结构、格式、章号、锚点、链接),侧栏目录树一致性等跨页面项目仍然由
check-pages.js 在跑完 build-nav.js 之后统一检查。
--strict 额外要求:本章所有小节都在侧栏目录树里出现(写完并跑过 build-nav.js 之后用)。
========================================================================== */
const fs = require("fs");
const path = require("path");
const root = path.resolve(__dirname, "..");
const args = process.argv.slice(2);
const STRICT = args.includes("--strict");
const targets = args.filter(a => !a.startsWith("--"));
if (!targets.length) {
console.error("用法:node tools/check-chapter.js <章节页或模块目录> [--strict]");
process.exit(2);
}
const ALLOWED_BOX = new Set(["", "note", "tip", "warn", "danger", "ok", "case", "lab", "pit"]);
const TAG_PAIRS = ["div", "section", "article", "aside", "nav", "main", "details", "table",
"ul", "ol", "li", "thead", "tbody", "tr", "td", "th", "pre", "p", "span"];
const problems = [];
const notes = [];
function walkHtml(dir, out = []) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) { if (e.name !== "assets" && e.name !== "tools") walkHtml(p, out); }
else if (e.name.endsWith(".html")) out.push(p);
}
return out;
}
/* 站内 id 索引:用于校验锚点是否真实存在 */
const idIndex = new Map();
for (const p of walkHtml(root)) {
const html = fs.readFileSync(p, "utf8");
const ids = new Set([...html.matchAll(/\sid="([^"]+)"/g)].map(m => m[1]));
if (path.resolve(p) === path.resolve(root, "index.html")) {
[...html.matchAll(/^\s*id:"([^"]+)"/gm)].forEach(m => ids.add(m[1]));
}
idIndex.set(path.resolve(p), ids);
}
/* 展开待检查文件 */
const files = [];
for (const t of targets) {
const p = path.resolve(root, t);
if (!fs.existsSync(p)) { console.error(`路径不存在:${t}`); process.exit(2); }
if (fs.statSync(p).isDirectory()) {
const f = fs.readdirSync(p).filter(x => /^\d\d-.*\.html$/.test(x)).sort();
if (!f.length) { console.error(`${t} 下没有 NN-*.html`); process.exit(2); }
f.forEach(x => files.push(path.join(p, x)));
} else files.push(p);
}
for (const p of files) {
const rel = path.relative(root, p).replace(/\\/g, "/");
const html = fs.readFileSync(p, "utf8");
const markup = html.replace(/<script[\s\S]*?<\/script>/g, "");
const must = (c, m) => { if (!c) problems.push(`${rel}: ${m}`); };
if (!/^modules\/[^/]+\/\d\d-/.test(rel)) {
notes.push(`${rel}:不是章节页,只做结构检查`);
} else {
const chapNo = parseInt(path.basename(rel).slice(0, 2), 10);
const modPath = path.dirname(p);
const modFiles = fs.readdirSync(modPath).filter(f => /^\d\d-.*\.html$/.test(f)).sort();
must(html.includes("<article>"), "缺少 article");
must(html.includes('id="chapters"'), "缺少章节目录侧栏 #chapters");
must(/<h2 id="/.test(html), "缺少 h2 章节标题");
must(html.includes('class="chapnav"'), "缺少章节目录定位条 chapnav");
must(html.includes('class="pager"'), "缺少上一/下一章 pager");
must(html.includes('href="index.html"'), "缺少返回模块目录链接");
must(html.includes('href="../../assets/doc.css"'), "doc.css 路径不对");
must(html.includes('src="../../assets/doc.js"'), "doc.js 路径不对");
must(/assets\/back\.js/.test(html), "缺少返回资料库入口 back.js");
// chapnav:章号 / 总章数 / 小节数
const navPos = html.match(/第 <b class="pos">(\d+)<\/b> \/ (\d+) 章/);
if (!navPos) problems.push(`${rel}: chapnav 缺少「第 N / M 章」`);
else {
if (Number(navPos[1]) !== chapNo) problems.push(`${rel}: chapnav 章号 ${navPos[1]} ≠ 文件名 ${chapNo}`);
if (Number(navPos[2]) !== modFiles.length) problems.push(`${rel}: chapnav 总章数 ${navPos[2]} ≠ 目录实际 ${modFiles.length} 章`);
}
const h3all = html.match(/<h3[ >]/g) || [];
const h3withId = html.match(/<h3 id="/g) || [];
must(h3withId.length === h3all.length, `有 h3 未补 id(${h3withId.length}/${h3all.length})`);
const navSecs = html.match(/本章 (\d+) 小节/);
if (h3all.length && !navSecs) problems.push(`${rel}: 有 ${h3all.length} 个小节但 chapnav 未写「本章 N 小节」`);
if (navSecs && Number(navSecs[1]) !== h3all.length) problems.push(`${rel}: chapnav 小节数 ${navSecs[1]} ≠ 实际 ${h3all.length}`);
// h3 编号与 id
for (const h of html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)) {
if (!/^sec-(x)?\d/.test(h[1]) && !/^sec-\d+-\d+$/.test(h[1])) problems.push(`${rel}: h3 id 命名不规范 ${h[1]}`);
const label = h[2].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
if (!new RegExp(`^${chapNo}\\.\\d+`).test(label)) {
problems.push(`${rel}: h3「${label.slice(0, 30)}」编号与章号不一致(应为 ${chapNo}.x)`);
}
}
// 当前章在目录树里必须是 active(非空目录树时)
const nav = html.match(/<nav id="chapters">([\s\S]*?)<\/nav>/);
if (!nav) problems.push(`${rel}: 缺少 #chapters 目录树`);
else if (nav[1].trim()) {
must(/class="toc-a active"[^>]*aria-current="page"/.test(html), "当前章未在目录树标 active");
const cur = nav[1].match(/<div class="subnav current">([\s\S]*?)<\/div>/);
const curSecs = cur ? (cur[1].match(/class="toc-a lv3"/g) || []).length : 0;
if (STRICT && curSecs !== h3all.length) problems.push(`${rel}: 本章目录树小节 ${curSecs} ≠ 正文 ${h3all.length}(需要重跑 build-nav.js)`);
const rows = (nav[1].match(/class="toc-a( active)?"/g) || []).length;
must(rows === modFiles.length, `目录树章节数 ${rows} ≠ 目录实际 ${modFiles.length}`);
for (const f of modFiles) {
if (f === path.basename(p)) continue;
must(nav[1].includes(`href="${f}"`), `目录树缺少章节 ${f}`);
}
} else {
notes.push(`${rel}:目录树为空,跑 build-nav.js 后会自动填充`);
}
}
must(/<title>[^<]+<\/title>/.test(html), "缺少 title");
must(!/<style[\s>]/.test(markup), "不应出现 <style> 标签");
const inline = (markup.match(/\sstyle="/g) || []).length;
must(!inline, `有 ${inline} 处内联 style`);
// 代码块
const pres = markup.match(/<pre[\s\S]*?<\/pre>/g) || [];
pres.forEach((blk, i) => {
if (!/data-lang=/.test(blk)) problems.push(`${rel}: 第 ${i + 1} 个 <pre> 未标注 data-lang`);
const body = blk.replace(/^<pre[^>]*>/, "").replace(/<\/pre>$/, "");
if (/</.test(body)) problems.push(`${rel}: 第 ${i + 1} 个 <pre> 内有未转义的 <`);
});
// 提示框 / 表格
for (const m of markup.matchAll(/<div class="box([^"]*)"/g)) {
for (const cls of m[1].trim().split(/\s+/).filter(Boolean)) {
if (!ALLOWED_BOX.has(cls)) problems.push(`${rel}: 提示框用了不在规范内的类 box.${cls}`);
}
}
const tables = (markup.match(/<table[\s>]/g) || []).length;
const wrapped = (markup.match(/class="tablewrap"/g) || []).length;
must(tables === wrapped, `表格 ${tables} 个,tablewrap 包裹 ${wrapped} 个`);
// 标签配对
for (const t of TAG_PAIRS) {
const o = (markup.match(new RegExp("<" + t + "(?=[\\s>])", "g")) || []).length;
const c = (markup.match(new RegExp("</" + t + ">", "g")) || []).length;
if (o !== c) problems.push(`${rel}: <${t}> 开合不匹配 ${o}/${c}`);
}
// 残留占位
if (/<!--\s*(MORE|TODO|PART\d|占位)/i.test(html)) problems.push(`${rel}: 有未完成的占位注释`);
// 链接与锚点
const links = [...markup.matchAll(/href="(?!https?:|mailto:)([^"]+)"/g)].map(m => m[1]);
for (const l of new Set(links)) {
const [file, hash] = l.split("#");
const target = file ? path.resolve(path.dirname(p), file) : path.resolve(p);
if (file && !fs.existsSync(target)) { problems.push(`${rel}: 死链 ${l}`); continue; }
if (hash && idIndex.has(target) && !idIndex.get(target).has(hash)) {
problems.push(`${rel}: 锚点不存在 ${l}`);
}
}
const cn = (markup.replace(/<pre[\s\S]*?<\/pre>/g, "").match(/[\u4e00-\u9fff]/g) || []).length;
notes.push(`${rel}:正文汉字约 ${cn},代码块 ${pres.length},表格 ${tables}`);
}
notes.forEach(n => console.log("· " + n));
if (problems.length) {
console.error(`\n发现 ${problems.length} 个问题:`);
problems.forEach(x => console.error(" - " + x));
process.exit(1);
}
console.log(`\nOK:${files.length} 个页面检查通过`);

View File

@@ -1,51 +1,96 @@
/* ========================================================================== /* ==========================================================================
阶段 0 模块元数据 模块元数据(按阶段组织)
用途:tools/build-module-index.js 依据本文件生成每个模块的目录页(index.html)。 用途:tools/build-module-index.js 依据本文件生成每个模块的目录页(index.html)。
章节标题与小节标题不写在这里 —— 目录页直接从章节 HTML 里解析,保证与正文永远一致; 章节标题与小节标题不写在这里 —— 目录页直接从章节 HTML 里解析,保证与正文永远一致;
本文件只维护「模块级」信息:标题、副标题、建议投入、导语、前后模块关系。 本文件只维护「模块级」信息:标题、副标题、建议投入、导语。
新增模块:追加一个对象,然后在 index.html 的 PAGES 表里登记路由。
新增模块:在对应阶段的 modules 里追加一个对象(dir 必须与 modules/ 下的目录同名),
然后在 index.html 的 PAGES 表里登记路由(key = 阶段 id + "-" + 模块在数组里的下标)。
还没开始写的模块照样可以留在数组里:目录不存在或没有章节页时,
build-module-index.js 会跳过它并在输出里标「筹备中」,不会报错。
数组顺序 = 模块编号顺序,不要随意重排。
========================================================================== */ ========================================================================== */
{ {
"stage": {
"id": "s0",
"num": "0",
"title": "打地基",
"sub": "计算机 · Go 工程 · Linux · 数据库",
"anchorText": "阶段 0 · 打地基"
},
"brand": { "brand": {
"logo": "QA", "logo": "QA",
"siteName": "测试开发工程师从零到成熟", "siteName": "测试开发工程师从零到成熟",
"home": "../../index.html" "home": "../../index.html"
}, },
"modules": [ "stages": [
{ {
"dir": "s0-01-network", "id": "s0",
"title": "计算机与网络基础", "num": "0",
"sub": "进程 · TCP · HTTP · 抓包 · 调用链", "title": "打地基",
"hours": "建议投入 18–24 小时", "sub": "计算机 · Go 工程 · Linux · 数据库",
"lead": "<b>模块定位:</b>阶段 0 的第 1 个模块。测试工程师 80% 的争论都发生在「这到底是谁的问题」上,而这类争论几乎都能用系统与网络的知识终结。<br><br><b>学完之后你应该能:</b>给一个「页面报 500 / 接口偶发超时」的现场,在 10 分钟内判断是前端、网络、网关还是后端的问题,并说清判断依据;能对任意一个被测接口画出从浏览器到数据库的调用链。<br><br><b>学习方式:</b>一半时间在敲命令(curl、ss、tcpdump、mitmproxy),一半时间在画图和归因。看懂一次真实抓包,胜过读十篇文章。" "anchorText": "阶段 0 · 打地基",
"modules": [
{
"dir": "s0-01-network",
"title": "计算机与网络基础",
"sub": "进程 · TCP · HTTP · 抓包 · 调用链",
"hours": "建议投入 18–24 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 1 个模块。测试工程师 80% 的争论都发生在「这到底是谁的问题」上,而这类争论几乎都能用系统与网络的知识终结。<br><br><b>学完之后你应该能:</b>给一个「页面报 500 / 接口偶发超时」的现场,在 10 分钟内判断是前端、网络、网关还是后端的问题,并说清判断依据;能对任意一个被测接口画出从浏览器到数据库的调用链。<br><br><b>学习方式:</b>一半时间在敲命令(curl、ss、tcpdump、mitmproxy),一半时间在画图和归因。看懂一次真实抓包,胜过读十篇文章。"
},
{
"dir": "s0-02-golang",
"title": "编程基础:Golang 与工程化",
"sub": "语法 · 错误处理 · 接口与并发 · 工程结构",
"hours": "建议投入 30–40 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 2 个模块,也是整条路线里最不能省的一个。后面的单元测试、接口自动化框架、测试平台后端全部是 Go 代码,这一层没打好,后面只能抄别人的代码改。<br><br><b>学完之后你应该能:</b>独立写出带错误处理、接口依赖注入、超时控制的 Go 程序;读懂一个陌生 Go 服务从 main 到数据库的请求路径;交付一个自己写的测试数据生成与校验 CLI。<br><br><b>学习方式:</b>只读书不动手等于没学。每个知识点都写一个能跑起来的最小程序,最后合成一个 CLI 交付物。"
},
{
"dir": "s0-03-linux-git",
"title": "Linux、Shell 与 Git",
"sub": "命令行 · 日志 · 脚本 · 版本协作",
"hours": "建议投入 20–28 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 3 个模块。测试环境出问题时,能救你的不是界面而是命令行:看进程、翻日志、查端口、起停服务、写脚本,以及用 Git 把这一切留下来。<br><br><b>学完之后你应该能:</b>在没有任何监控的情况下定位「服务为什么起不来」;用一条管道从日志里捞出失败请求 TOP10;写出带 <code>set -euo pipefail</code> 与 <code>trap</code> 的可复用脚本;用 <code>git bisect</code> 找到引入缺陷的那次提交。<br><br><b>学习方式:</b>准备一个 Linux 环境(WSL 或虚拟机均可),所有命令都要真的敲一遍,脚本要真的能跑。"
},
{
"dir": "s0-04-database",
"title": "数据库与 SQL",
"sub": "查询 · 连接 · 校验 · 造数与清理",
"hours": "建议投入 20–26 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 4 个模块。界面上显示「下单成功」不算成功,数据落对了才算。能自己写 SQL 的测试工程师,定位效率和话语权完全不一样。<br><br><b>学完之后你应该能:</b>用 SQL 独立验证一条业务规则(金额对账、状态流转、无孤儿数据、无重复支付);针对一套订单与支付表结构写出 10 条可重复执行的校验 SQL;造出可追溯、可清理的测试数据。<br><br><b>学习方式:</b>找一个能随便造数的开发库,边学边写;每条校验 SQL 都要能说清「结果应该是几行、出现几行说明什么」。"
}
]
}, },
{ {
"dir": "s0-02-golang", "id": "s1",
"title": "编程基础:Golang 与工程化", "num": "1",
"sub": "语法 · 错误处理 · 接口与并发 · 工程结构", "title": "会测",
"hours": "建议投入 30–40 小时", "sub": "测试理论与手工测试基本功",
"lead": "<b>模块定位:</b>阶段 0 的第 2 个模块,也是整条路线里最不能省的一个。后面的单元测试、接口自动化框架、测试平台后端全部是 Go 代码,这一层没打好,后面只能抄别人的代码改。<br><br><b>学完之后你应该能:</b>独立写出带错误处理、接口依赖注入、超时控制的 Go 程序;读懂一个陌生 Go 服务从 main 到数据库的请求路径;交付一个自己写的测试数据生成与校验 CLI。<br><br><b>学习方式:</b>只读书不动手等于没学。每个知识点都写一个能跑起来的最小程序,最后合成一个 CLI 交付物。" "anchorText": "阶段 1 · 会测",
}, "modules": [
{ {
"dir": "s0-03-linux-git", "dir": "s1-01-case-design",
"title": "Linux、Shell 与 Git", "title": "测试理论与用例设计",
"sub": "命令行 · 日志 · 脚本 · 版本协作", "sub": "测试的本质 · 需求分析 · 设计方法 · 评审 · 分层与类型",
"hours": "建议投入 20–28 小时", "hours": "建议投入 22–28 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 3 个模块。测试环境出问题时,能救你的不是界面而是命令行:看进程、翻日志、查端口、起停服务、写脚本,以及用 Git 把这一切留下来。<br><br><b>学完之后你应该能:</b>在没有任何监控的情况下定位「服务为什么起不来」;用一条管道从日志里捞出失败请求 TOP10;写出带 <code>set -euo pipefail</code> 与 <code>trap</code> 的可复用脚本;用 <code>git bisect</code> 找到引入缺陷的那次提交。<br><br><b>学习方式:</b>准备一个 Linux 环境(WSL 或虚拟机均可),所有命令都要真的敲一遍,脚本要真的能跑。" "lead": "<b>模块定位:</b>阶段 1 的第 1 个模块,也是「会测」这件事的地基。用例写得出来,后面的接口测试、自动化、测试平台才有东西可跑;用例写不出来,工具学得再多,也只是把乱点变成自动乱点。<br><br><b>学完之后你应该能:</b>拿到一段需求或一个原型,独立拆出测试点,用等价类、边界值、判定表、场景法把它变成别人能直接执行的用例;组织一次评审,并说清每条用例对应的是哪一类风险。<br><br><b>学习方式:</b>别把这一模块当方法论读。拿你手上正在测的那个功能直接写:每学一种设计方法就回到同一个功能上补一批用例,最后合成一份 30 条以上的用例集,并真的找人评一次。"
}, },
{ {
"dir": "s0-04-database", "dir": "s1-02-http-api",
"title": "数据库与 SQL", "title": "HTTP 接口与接口测试基础",
"sub": "查询 · 连接 · 校验 · 造数与清理", "sub": "请求响应 · 鉴权 · 参数 · 工具 · 用例设计 · 抓包改包",
"hours": "建议投入 20–26 小时", "hours": "建议投入 24–30 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 4 个模块。界面上显示「下单成功」不算成功,数据落对了才算。能自己写 SQL 的测试工程师,定位效率和话语权完全不一样。<br><br><b>学完之后你应该能:</b>用 SQL 独立验证一条业务规则(金额对账、状态流转、无孤儿数据、无重复支付);针对一套订单与支付表结构写出 10 条可重复执行的校验 SQL;造出可追溯、可清理的测试数据。<br><br><b>学习方式:</b>找一个能随便造数的开发库,边学边写;每条校验 SQL 都要能说清「结果应该是几行、出现几行说明什么」。" "lead": "<b>模块定位:</b>阶段 1 的第 2 个模块。界面能点出来的问题只是冰山一角:接口才是业务规则真正落地的地方,也是后面自动化和测试平台要接的那一层。<br><br><b>学完之后你应该能:</b>不看文档也能用 <code>curl</code> 把一次请求完整发出去;能拆开请求与响应,判断 4xx / 5xx 到底该找谁;能处理登录态、构造任意参数,并用抓包改包验证后端是不是真的做了校验;为一个下单接口交出含幂等与越权场景的接口用例集。<br><br><b>学习方式:</b>所有示例都在命令行里自己跑一遍。Postman 可以点,但只有 <code>curl</code> 会告诉你请求到底是什么样子。"
},
{
"dir": "s1-03-web-frontend",
"title": "Web 前端基础与调试",
"sub": "HTML / CSS / JS · DevTools · 缓存与异步 · 埋点与灰度",
"hours": "建议投入 18–24 小时",
"lead": "<b>模块定位:</b>阶段 1 的第 3 个模块。前端是缺陷的入口,也是「责任边界」争论最集中的一层。能读 DOM、能看 Network、能在 Sources 里打断点,你就不需要靠猜和转述。<br><br><b>学完之后你应该能:</b>用 DevTools 复现「只在特定条件下出现」的前端缺陷(缓存、异步渲染、iframe);用控制台与请求记录证明问题出在哪一层;看懂埋点与灰度开关导致的「数据缺失」和「功能不生效」。<br><br><b>学习方式:</b>把浏览器开发者工具当成主战场,每看一个现象都要求自己拿到一份可复现的证据(截图 + 请求记录 + 控制台输出)。"
},
{
"dir": "s1-04-defect-process",
"title": "缺陷管理与测试流程",
"sub": "缺陷生命周期 · 缺陷单 · 分级 · 流程与报告",
"hours": "建议投入 16–22 小时",
"lead": "<b>模块定位:</b>阶段 1 的第 4 个模块。测试的价值最终要靠「说清楚」交付出去:一条能被开发的缺陷单、一份能让产品经理做决定的测试报告、一次说得清风险的发布评审。<br><br><b>学完之后你应该能:</b>写出不需要二次追问的缺陷单;用证据处理「这不是缺陷」的争议;为一个版本走完从需求评审到上线验证的完整流程,并给出明确的发布建议。<br><br><b>学习方式:</b>拿你最近提交的缺陷单和最近一次的测试记录复盘:哪些被开发打回过?哪些风险是上线后才发现的?从这些真实记录里改流程。"
}
]
} }
] ]
} }