Skip to content

测试结构:npm run test:e2e 从不被执行,而无测试的恰是仓库自己认定最脆弱的那几个模块 #50

Description

@SongshGeo

测试套件形状是好的(12 个 vitest 文件、0.4s、pre-push 跑),但它覆盖的和最该覆盖
的不是同一批文件,而 e2e 套件根本没有人跑。

一、npm run test:e2e 在任何地方都不会被执行

package.json 里有:

"test:e2e": "node test/e2e/background-flash.mjs"
  • .github/workflows/ci.yml:跑 lint / test / check:content /
    i18n:manifest / setup:content / astro sync / check / build。没有 e2e。
  • lefthook.yml:pre-commit 跑 lint + format,pre-push 跑 npm test。没有 e2e。
  • vitest.config.ts 的注释明确说 e2e 不归它管,「belongs in an e2e suite」——
    但那个 suite 没有被接到任何地方。

它测的是 #33 / #34 / #36 那一组背景闪烁的回归。也就是说:三个还开着的视觉 bug,
有一个现成的自动化验收脚本,而它只在有人手敲命令时才运行。

要么把它接进 CI(Playwright 已经是 devDependency,需要 npx playwright install chromium 一步),要么就承认它是手动工具,在 test/e2e/README.md
package.json 里写清楚它不是 CI 的一部分。现在是第三种状态:看起来像 CI 的一
部分,其实不是。

二、没有测试的,恰好是仓库自己认定最脆弱的那几个

eslint.config.js 的注释点名了本仓最需要盯的代码:「path resolution, remark AST
surgery, recursive deletes」。三样东西对应的文件,全部没有单元测试:

无测试的模块 行数 是什么
src/utils/contentLayout.js 170 path resolution,23 个文件 import 它,全仓被依赖最多
src/utils/obsidian-links.js 275 remark AST surgery,wiki link 解析(曾经全部 404)
src/utils/rehype-callouts.js 147 rehype AST surgery
src/utils/remark-obsidian-callouts.js 94 remark AST surgery
src/utils/remark-revive-directives.js 57 remark AST surgery(19:15 时间戳那个坑)
scripts/setup-content.mjs 751 recursive deletes + 重试 + 复制兜底
src/content/loaders/newsLoader.ts 175 自定义 loader
src/utils/siteConfig.ts 84 站点身份 + 关于页
src/utils/libraryEntries.ts 28
src/utils/pageRelations.ts 49

render-markdown.test.ts 确实会间接走过这四个 markdown 插件,但它的定位是
sanitize 的安全边界测试(文件头注释写得很清楚),不是插件行为测试。插件各自的
边界条件——嵌套 callout、带别名的 wiki link、指向不存在条目的链接——没有直接
断言。

建议

按风险排序补三块,其余顺其自然:

  1. contentLayout.jsfindContentRoot —— 它要在三种 vault 形状里探测,
    是「每个新贡献者第一个撞到的报错」(它自己的注释这么写的)。三种形状各一个
    fixture 目录,三个断言。
  2. obsidian-links.js —— 给定一个 index,[[名字]] / [[目录/名字|别名]] /
    指向不存在条目的链接,各断言一次 href。
  3. newsLoader.ts —— 已经有 publicationsLoader.test.ts 做样板,照抄结构。

setup-content.mjs 的那块建议不补测试,直接按另一个 issue 删掉(六个软链是
content.config.ts 自己证明不需要的)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debt技术债 / 重构

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions