当用户需要编写一个单元测试时,触发该 skill,编写单元测试。
66
80%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.agents/skills/system/test-case/SKILL.md用户需要编写一个单元测试时,触发该 skill,编写单元测试。
packages 里的测试,写在 FastGPT/packages/xxx/test 目录下,子路径对应 packages 的目录结构。例如:
packages/global/common/error/s3.ts文件,对应的测例文件路径为 packages/test/global/common/error/s3.test.ts。
并且,可以通过 @fastgpt 来导入 packages 里的文件。 例如:
import { s3 } from '@fastgpt/global/common/error/s3';projects 里的测试,写在 FastGPT/projects/app/test 目录下,子路径对应 projects 的目录结构。
projects/app/src/pages/api/core/dataset/collection/create.ts文件,对应的测例文件路径为 projects/app/test/api/core/dataset/collection/create.test.ts。
// FastGPT/packages/service/common/geo/index.ts
import type { NextApiRequest } from 'next';
// 同时导出一个依赖给 FastGPT/packages/service/test/common/geo/index.test.ts 使用
export type { NextApiRequest } from 'next';尽量不要 mock,而是完整的运行其逻辑进行测试。
mock 对应的 API 请求进行测试。
一、任务准备
二、测例编写
不同测例文件,可以并行进行编写。
三、结果验证
pnpm test <file-path> <test-name>来运行测试并检查覆盖率,确保每个文件的覆盖率达到 90% 以上。# 运行所有测试
pnpm test
# 运行指定测试文件(file-path 填完整文件路径)
pnpm test <file-path>
# 运行指定测试文件的指定测试
pnpm test <file-path> <test-name>dc97c08
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.