본문으로 건너뛰기
cccskills
무료GitHub에 공개

test-case

Write unit tests for FastGPT code, covering normal behavior, edge cases, and errors. It guides test placement, limits mocks that replace real dependencies, and checks TypeScript errors and coverage, the share of code exercised by tests.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

当用户需要编写一个单元测试时,触发该 skill,编写单元测试。

설치 방법 보기

이럴 때 유용합니다

  • Adding unit tests for individual functions
  • Testing edge cases and error handling
  • Testing functions that make API requests
  • Running selected tests and checking coverage

포함된 파일(1)

  • SKILL.md3.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

When to Use This Skill

用户需要编写一个单元测试时,触发该 skill,编写单元测试。

测试文件位置

packages 测试

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 测试

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。

测试文件规则

通用规则

  1. 每个文件,对应一个测试文件。每个函数对应不同的 describe 块。
  2. 需覆盖 100% 行数和分支。
  3. 测试文件尽可能不要引入第三方依赖库,使用较为原生的方式进行检查。如果需要引入第三方依赖库,则从对应文件里 export 依赖库给 test 使用。例如:
// 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';
  1. 尽量减少函数 mock,如果是系统上原生可运行的函数,则无需 mock,只需要 mock 那些无法本地直接运行的依赖(比如需要远程服务,API 密钥之类的)
  2. 对于 type.ts, constants.ts, schema.ts, *.schema.ts 文件,以及静态数据,直接跳过忽略。
  3. 根据 vitest.config.mts 文件配置,跳过不需要测试的文件。
  4. Mock.ts 文件里,包含了全局 mock 的内容,在编写测试时,请勿重复 mock。理论上,测试里可以 mock 运行各类 infra。

基础函数文件测试

尽量不要 mock,而是完整的运行其逻辑进行测试。

带 API 请求的函数

mock 对应的 API 请求进行测试。

编写流程

一、任务准备

  1. 获取所需要编写的测试文件。
  2. 创建任务清单,来逐个完成每个文件的测例编写。

二、测例编写

不同测例文件,可以并行进行编写。

  1. 检查对应的 .test.ts 测试文件,如果没有则创建。
  2. 思考和分析代码后编写测试样例。
  3. 检查 TS 错误,确保无 ts 报错。
  4. 完成所有测试文件编写

三、结果验证

  1. 调用pnpm test <file-path> <test-name>来运行测试并检查覆盖率,确保每个文件的覆盖率达到 90% 以上。
  2. 如果测试不通过,则根据错误信息检查代码逻辑或者测试用例。
  3. 如需二次修改,则回到”二、测例编写“。

单测包含哪些场景

  1. 基础场景
  2. 复杂场景
  3. 边界值
  4. 安全边界情况(死循环、系统崩溃、超大数据等)
  5. 异常场景

常用命令

# 运行所有测试
pnpm test

# 运行指定测试文件(file-path 填完整文件路径)
pnpm test <file-path>

# 运行指定测试文件的指定测试
pnpm test <file-path> <test-name>

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Integrate new FastGPT resources, such as AgentSkill or Plugin, with permission management. Choose an integration guide based on resource hierarchy and permission inheritance, locate the relevant code, and review a checklist for missing implementation steps.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Adding permission support to a new FastGPT resource
  • Choosing an integration path based on permission inheritance
  • Finding code locations for permission definitions and checks
labring/FastGPT3만2026년 10월 19일 업데이트

Develop and review FastGPT APIs with consistent input and output checks, TypeScript types, and OpenAPI documentation. It guides the use of Zod schemas, definitions that describe and validate data, alongside permission checks and reusable structures.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Adding a new FastGPT API route
  • Changing API inputs or responses
  • Reviewing API validation and documentation
labring/FastGPT3만2026년 10월 19일 업데이트

Keep FastGPT build and test workflows aligned across GitHub Actions and Forgejo Actions. Adapt registry destinations, credentials, proxy settings, and platform-specific steps so the corresponding workflows support the internal network environment.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Synchronizing CI changes across GitHub and Forgejo
  • Adapting image builds for an internal network
  • Checking pull requests for missing workflow updates
labring/FastGPT3만2026년 10월 19일 업데이트

Retire a FastGPT workflow node while preserving existing workflows. The skill guides changes to templates, execution handlers, and interface references so the node disappears from creation menus but still loads, runs, and displays a replacement notice.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Retiring a FastGPT workflow node
  • Hiding a node from creation menus
  • Preserving existing workflows during node retirement
labring/FastGPT3만2026년 10월 19일 업데이트

doc-i18n

무료

Translate FastGPT documentation from Chinese into natural English for North American readers. Follow the shared product glossary, preserve document structure and code, synchronize navigation files, and check for missing translations or English pages that need updates.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Updating English docs after changes to Chinese pages
  • Translating a specified documentation folder
  • Synchronizing English navigation with translated pages
labring/FastGPT3만2026년 10월 19일 업데이트

Deploy FastGPT on your own server using its official installation script and Docker Compose, which runs its services together. Check service health and access, investigate deployment problems, and receive the access URL, initial login details, and next steps.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Setting up FastGPT on your own server
  • Checking service health after deployment
  • Investigating port conflicts or container startup failures
labring/FastGPT3만2026년 10월 19일 업데이트

labring의 스킬 모두 보기

이 스킬의 문제 신고