Files
spark-store/.agents/workflows/testing.md
momen cef68a95d9 chore: add comprehensive documentation and testing infrastructure
## 文档(全部中文)
- AGENTS.md - 完整的 AI 编码指南(中文版)
- CONTRIBUTING.md - 贡献指南
- DEVELOPMENT.md - 开发文档
- DEPLOYMENT.md - 部署文档
- TESTING.md - 测试文档
- TROUBLESHOOTING.md - 问题排查指南
- FAQ.md - 常见问题
- WORKFLOW.md - 标准开发流程文档
## AI 工作流(9个详细工作流)
- feature-development.md - 新功能开发流程
- bug-fix.md - Bug 修复流程
- code-review.md - 代码审查流程
- testing.md - 测试编写流程
- release.md - 发布流程
- refactoring.md - 代码重构流程
- documentation.md - 文档更新流程
- performance-optimization.md - 性能优化流程
- security-audit.md - 安全审计流程
## 测试基础设施
- vitest.config.ts - Vitest 单元测试配置
- playwright.config.ts - Playwright E2E 测试配置
- src/__tests__/setup.ts - 测试环境设置
- src/__tests__/unit/downloadStatus.test.ts - 示例单元测试
- e2e/basic.spec.ts - 示例 E2E 测试
## CI/CD
- .github/workflows/test.yml - 新建测试 CI 工作流
- .github/workflows/build.yml - 更新构建工作流,添加测试步骤
## Issue 模板
- 更新 bug_report.md 为标准 Bug 报告模板
- 更新 help_wanted.md 为标准功能请求模板
## 配置更新
- package.json - 添加测试依赖和 7 个新的 npm 脚本
- .gitignore - 添加测试相关忽略项
## 新增 npm 脚本
- test - 运行单元测试
- test:watch - 监听模式
- test:coverage - 生成覆盖率报告
- test:e2e - 运行 E2E 测试
- test:e2e:ui - E2E UI 模式
- test:e2e:debug - E2E 调试模式
- test:all - 运行所有测试
## 新增测试依赖
- @playwright/test ^1.40.0
- @testing-library/jest-dom ^6.1.5
- @testing-library/vue ^8.0.1
- @vitest/coverage-v8 ^1.0.0
- @vue/test-utils ^2.4.3
- jsdom ^23.0.1
- vitest ^1.0.0
2026-03-10 00:42:56 +08:00

109 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: 测试编写流程
---
## 工作流说明
此工作流指导如何为新功能或 Bug 修复编写测试。
## 步骤
### 1. 确定测试范围
分析需要测试的功能点:
- 单元测试:测试独立函数/组件
- 集成测试:测试模块间交互
- E2E 测试:测试完整用户流程
### 2. 编写单元测试Vitest
`src/__tests__/unit/` 目录下创建测试文件:
```typescript
import { describe, it, expect } from "vitest";
import { someFunction } from "@/modules/example";
describe("someFunction", () => {
it("should return expected result", () => {
const result = someFunction(input);
expect(result).toBe(expected);
});
});
```
### 3. 编写组件测试
```typescript
import { describe, it, expect } from "vitest";
import { mount } from "@vue/test-utils";
import AppCard from "@/components/AppCard.vue";
describe("AppCard", () => {
it("should render app name", () => {
const wrapper = mount(AppCard, {
props: {
app: {
name: "Test App",
pkgname: "test-app",
},
},
});
expect(wrapper.text()).toContain("Test App");
});
});
```
### 4. 编写 E2E 测试Playwright
`e2e/` 目录下创建测试文件:
```typescript
import { test, expect } from "@playwright/test";
test("install app from store", async ({ page }) => {
await page.goto("http://localhost:3344");
await page.click("text=Test App");
await page.click('button:has-text("安装")');
await expect(page.locator(".install-progress")).toBeVisible();
});
```
### 5. 运行测试
```bash
# 运行单元测试
npm run test
# 运行测试并监听
npm run test:watch
# 运行 E2E 测试
npm run test:e2e
# 生成覆盖率报告
npm run test:coverage
```
### 6. 确保测试通过
- 所有单元测试必须通过
- E2E 测试覆盖主要用户流程
- 测试覆盖率不低于 70%
### 7. 提交代码
测试通过后,提交代码并创建 PR。
## 注意事项
- ⚠️ 不要测试第三方库的功能
- ⚠️ 保持测试独立性和可重复性
- ⚠️ 使用有意义的测试名称
- ⚠️ Mock 外部依赖APM 命令、API 调用)
## 相关文档
- [TESTING.md](../../TESTING.md) - 测试框架和规范
- [DEVELOPMENT.md](../../DEVELOPMENT.md) - 开发文档