[ PROMPT_NODE_25572 ]
test-detect
[ SKILL_DOCUMENTATION ]
# 测试检测 (Test Detect)
自动检测当前项目中的测试框架并运行正确的测试。
## 工作流
### 第一步:检测测试框架
按顺序检查以下文件(第一个匹配项胜出):
| 检查 | 框架 | 运行命令 |
|-------|-----------|-------------|
| 存在 `vitest.config.*` 或 devDeps 中有 `vitest` | **Vitest** | `npx vitest run` |
| 存在 `jest.config.*` 或 devDeps 中有 `jest` | **Jest** | `npx jest` |
| 存在 `playwright.config.*` | **Playwright** | `npx playwright test` |
| 存在 `cypress.config.*` | **Cypress** | `npx cypress run` |
| 存在 `pytest.ini`, `conftest.py` 或 `pyproject.toml` (含 `[tool.pytest]`) | **pytest** | `python -m pytest` |
| 存在 `go.mod` | **Go test** | `go test ./...` |
| 存在 `Cargo.toml` | **Rust/cargo** | `cargo test` |
| 存在 `mix.exs` | **ExUnit** | `mix test` |
| `Gemfile` 中有 `rspec` | **RSpec** | `bundle exec rspec` |
| `package.json` 有 `scripts.test` | **npm test** | `npm test` |
在继续之前报告检测到的框架。
### 第二步:解析参数
检查 `$ARGUMENTS` 以确定模式:
- **无参数** 或 **"all"**: 运行完整测试套件(第三步)
- **文件路径** (例如 `src/auth/login.ts`): 运行该文件的测试(第四步)
- **"generate" + 文件路径** (例如 `generate src/utils.ts`): 生成测试(第五步)
### 第三步:运行完整测试套件
运行检测到的测试命令。完成后:
- 报告测试总数、通过数、失败数、跳过数
- 如果测试失败,显示前 3 条失败信息及文件:行号引用
- 建议: "运行 `/test-detect ` 以调查特定失败"
### 第四步:运行特定文件的测试
给定源文件路径,查找其测试文件:
**搜索策略** (按顺序尝试):
1. `__tests__/.test.` (Jest 约定)
2. `.test.` (同目录)
3. `.spec.` (替代约定)
4. `test/_test.` (Go/Python 约定)
5. `tests/test_.` (pytest 约定)
6. `_test.go` (Go 约定)
使用 Glob 查找匹配项。如果找到,仅运行该测试文件:
| 框架 | 命令 |
|-----------|---------|
| Vitest | `npx vitest run ` |
| Jest | `npx jest ` |
| Playwright | `npx playwright test ` |
| pytest | `python -m pytest ` |
| Go | `go test -run .//` |
| Cargo | `cargo test ` |
如果未找到测试文件,询问: "未找到该文件的测试。需要我生成它们吗?运行 `/test-detect gene