SuperAPI AI 工具集

testing

测试与质量

查看项目

更新于 10-15 21:38

技能介绍

用途:为 Epicenter 项目中的测试文件提供统一约定,覆盖编写、审查、删除与精简测试的场景。

主要能力:提供按需加载的参考文档,包括负类型测试(@ts-expect-error、bun:test 类型策略、禁用 as any)见 references/type-testing.md;测试 setup 架构见 references/setup-pattern.md;测试组织结构见 references/test-structure.md;审计笼统断言、透传 getter、停滞的假实现等见 references/honest-tests.md;删除或精简测试见 references/test-deletion-grill.md。

Result 断言:断言 wellcrafted Result 时使用 wellcrafted/testing 的 expectOk 和 expectErr,例如: import { expectErr, expectOk } from 'wellcrafted/testing'; const data = expectOk(await service.doThing()); const error = expectErr(await service.doThing({ invalid: true })); 避免本地助手克隆、expect(error).toBeNull() 成功检查及 if (error) throw 解包。此规则不适用于普通响应体、UI 快照或仅有 error 属性的对象。

测试与基准:.test.ts 用 expect() 断言行为,运行于 bun test;.bench.ts 仅测量报告,运行于 bun bench,无断言要求。单文件二者只取其一。基准放在包内 src/benchmarks/,测试与被测模块同目录。bun test 默认只发现 *.test.ts。

文件头注释:每个 .test.ts 必须以 JSDoc 块开头,说明测试内容与关键行为。

命名规则:测试名必须为行为断言,说明失败时什么坏了,包含条件,不使用 should、correctly 等填充词。模式为 {action} {outcome} [condition]。

文件拆分:模块有不同行为方面时拆分为 {module}.test.ts、{module}.types.test.ts、{module}.{scenario}.test.ts;文件超约 500 行、关注点真正不同、setup 需求不同时拆分;会产生少于 3 个测试或共享同一 setup 时不拆分。

长文件用注释分隔逻辑区块。

限制:资料未提供其他平台支持、收费或价格信息。