测试分析服务器

一个用于分析JavaScript/TypeScript项目单元测试设置、检查覆盖率和生成全面测试报告的模型上下文协议(MCP)服务器。

  • by giri-jeedigunta
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 giri-jeedigunta/hello-mcp

使用说明

测试分析仪MCP服务器

一个模型上下文协议(MCP)服务器,提供用于分析单元测试设置、检查覆盖率和为JavaScript/TypeScript项目生成全面测试报告的工具。

特性

  • 🔍 框架检测:自动检测杰斯特、维特、摩卡、赛普拉斯和剧作家
  • 📊 覆盖率分析:带有视觉反馈的详细覆盖指标
  • 📁 测试发现:查找并分析项目中的所有测试文件
  • 🎯 智能推荐:可采取行动的见解,以改进您的测试策略
  • 🚀 前端聚焦:针对React、Vue、Angular和其他前端框架进行了优化

安装

服务器已在MCP设置中配置:

/Users/venkatagiribabu.jeedigunta/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

可用工具

1. analyze_test_setup

分析存储库的完整单元测试设置。

参数:

  • repoPath (必填):要分析的存储库路径

退货:

  • 框架名称(jest、vitest、mocha等)
  • 找到的测试文件列表
  • 总测试计数
  • 测试结构(套件、测试、挂钩)
  • 覆盖配置
  • 测试依赖关系
  • 摘要报告

2. check_coverage

使用详细指标检查存储库的测试覆盖率。

参数:

  • repoPath (必填):存储库的路径
  • runTests (可选,默认值:false):是否运行测试以生成新的覆盖率数据

退货:

  • 线路覆盖率
  • 报表覆盖率
  • 功能覆盖率
  • 分行覆盖率
  • 视觉状态指示器(✅ 很好,⚠️ 公平,❌ 差)
  • 总体覆盖情况总结

3. get_test_summary

生成全面的测试分析报告。

参数:

  • repoPath (必填):存储库的路径

退货:

  • 完整的测试设置概述
  • 带有视觉反馈的覆盖率指标
  • 分类依赖关系
  • 可采取行动的建议
  • Markdown格式的报告

示例查询

以下是当此MCP服务器处于活动状态时,您可以与Claude一起使用的示例查询:

基本分析

"Analyze the test setup for the project at /Users/me/projects/my-react-app"

"Check what testing framework is being used in /path/to/project"

"Find all test files in my current project"

覆盖率分析

"Check the test coverage for /Users/me/projects/my-app"

"Run tests and get fresh coverage data for the project at /path/to/repo"

"What's the current test coverage status? Is it meeting the thresholds?"

综合报告

"Give me a complete test analysis report for /Users/me/projects/frontend-app"

"Generate a test summary with recommendations for improving coverage"

"Analyze the testing setup and suggest improvements"

具体咨询

"How many tests are in the project at /path/to/repo?"

"What testing dependencies are installed in this project?"

"Is coverage reporting configured properly?"

"Which test files have been created in this project?"

支持的测试框架

单元测试

  • 开玩笑 -通过jest.config.js、package.json检测
  • 速度 -通过vitest.config.js、vite.config.js检测
  • 摩卡 -通过.mocharc.js、.mocharc.json检测

E2E测试

  • 柏树 -通过cypress.config.js、cypress.json检测到
  • 剧作家 -通过playwright.config.js检测到

支持的覆盖工具

  • Jest覆盖范围 (内置)
  • 纽约/伊斯坦布尔 (.nycrc、.nycrc.json)
  • C8 (V8覆盖率)
  • Vitest覆盖范围 (@vitest/coverage-c8,@vitest/goverage伊斯坦布尔)

测试文件模式

服务器会自动检测与这些模式匹配的测试文件:

  • **/*.test.{js,jsx,ts,tsx}
  • **/*.spec.{js,jsx,ts,tsx}
  • **/__tests__/**/*.{js,jsx,ts,tsx}
  • test/**/*.{js,jsx,ts,tsx} (摩卡)
  • cypress/integration/**/* (柏树)
  • cypress/e2e/**/* (柏树)
  • **/*.cy.{js,jsx,ts,tsx} (柏树组件测试)
  • tests/**/*.{js,jsx,ts,tsx} (剧作家)
  • e2e/**/*.{js,jsx,ts,tsx} (E2E测试)

覆盖阈值

服务器根据这些阈值评估覆盖率:

  • ✅ 好:覆盖率≥80%
  • ⚠️ 公平的:覆盖率≥60%
  • ❌ 贫穷的:覆盖率<60%

输出示例

测试设置分析

{
  "framework": "jest",
  "testFiles": ["src/__tests__/utils.test.js", "src/components/Button.test.tsx"],
  "testCount": 25,
  "testStructure": {
    "suites": 10,
    "tests": 25,
    "hooks": ["beforeEach", "afterEach"]
  },
  "dependencies": ["jest@29.5.0", "@testing-library/react@14.0.0"]
}

覆盖范围报告

Coverage Summary:
- Lines: 85.5% ✅ Good
- Statements: 84.2% ✅ Good
- Functions: 78.9% ⚠️ Fair
- Branches: 72.3% ⚠️ Fair

Overall: ⚠️ Fair

建议

## Recommendations

- 🟡 Branch coverage is below 80%. Add tests for different code paths.
- 🟡 Function coverage could be improved. Consider testing utility functions.
- ✅ Line coverage is good! Keep maintaining high standards.

高级用法

分析多个项目

您可以按顺序分析多个项目:

"First analyze tests for /project1, then compare with /project2"

CI/CD集成思想

"Check if the coverage meets our 80% threshold for CI"
"Generate a test report for the pull request review"

测试改进工作流程

1. "Analyze current test setup"
2. "Check which files have low coverage"
3. "Suggest test cases for uncovered branches"
4. "Re-run coverage after adding tests"

故障排除

未检测到框架

  • 确保package.json存在于存储库中
  • 检查测试框架是否在devDependencies中
  • 验证配置文件是否存在

未找到覆盖率数据

  • 使用运行测试 runTests: true 参数
  • 确保在测试框架中配置了覆盖率
  • 运行测试后检查覆盖目录是否存在

未找到测试文件

  • 验证测试文件是否遵循常见的命名模式
  • 检查测试是否在排除的目录中(node_modules、dist、build)
  • 确保文件扩展名匹配(.test.js、.spec.ts等)

发展

添加新框架

要支持其他测试框架,请更新 frameworks 服务器实现中的数组具有:

  • 框架名称
  • 配置文件模式
  • 测试文件模式

扩展覆盖范围支持

服务器可以通过以下方式扩展以支持其他覆盖格式:

  • 向添加新的文件模式 coverageFiles 数组
  • 为特定的覆盖率格式实现解析器
  • 支持更多报道记者

许可证

国际协调委员会

作者

吉里-https://github.com/giri-jeedigunta/

Cline MCP截图