🚀 快速开始 - 运行测试

🚀 快速开始 - 运行测试

快速开始(推荐)

cd puax-mcp-server

# 使用完整的测试套件(自动处理所有事情)
node test-all.js

备选方案

方案 A:自动管理服务器(推荐)

特点: 自动启动服务器、运行测试、关闭服务器

# 运行所有测试(自动处理)
node test-with-server.js

# 运行特定测试
node test-with-server.js test/unit

方案 B:检查+引导(交互式)

特点: 检查服务器,提供交互式选项

# 检查服务器并引导
node run-with-server.js

# 生成报告
node test-report.js

方案 C:手动方式(传统)

特点: 完全手动控制

# 终端 1: 启动服务器
npm start

# 终端 2: 运行测试
npm test

# 运行特定测试套件
npm run test:unit       # 单元测试
npm run test:http       # HTTP测试
npm run test:sse        # SSE测试
npm run test:tools      # 工具测试
npm run test:integration # 集成测试
npm run test:coverage   # 覆盖率

📊 测试选项对比

方式命令优点缺点适用场景
完整套件node test-all.js✅ 全自动、有引导-初学者、完整测试
自动管理node test-with-server.js✅ 自动启停服务器⏱️ 稍慢日常开发
检查引导node run-with-server.js✅ 有提示、交互式⏱️ 需手动操作学习、不确定时
手动npm start + npm test✅ 完全控制⚠️ 多终端高级用户、调试
快速验证npm test✅ 快速⚠️ 需提前启动已运行服务器时

🎯 选择建议

如果你是第一次运行测试

node test-all.js

如果你正在开发

# 每次测试(自动启停)
node test-with-server.js

# 持续开发(监听模式)
npm run test:watch

如果你在 CI/CD 环境

# 启动服务器
npm start &

# 等待服务器就绪
npx wait-on http://localhost:23333/health

# 运行测试
npm test

如果你只想快速验证

# 确保服务器在运行
npm start &

# 快速测试
node run-with-server.js

📋 测试文件

测试文件测试数说明
test/unit/server.test.js5HTTP基础端点
test/http/endpoint.test.js11HTTP端点完整测试
test/sse/transport.test.js9SSE传输测试
test/tools/tools.test.js11MCP工具测试
test/integration/mcp-flow.test.js6集成流程测试
总计42+全功能覆盖

🔧 常见问题

测试全部跳过(显示 skipped)

正常现象! 这说明服务器未运行。

解决: 使用 node test-all.jsnode test-with-server.js

测试超时

原因: 服务器响应慢

解决: 增加超时时间:

npx jest --testTimeout=30000

端口被占用

解决:

# 终止所有node进程
taskkill /F /IM node.exe

# 重新运行
node test-all.js

✅ 验证安装

# 1. 验证测试配置
node verify-tests.js

# 2. 应该看到:
# ✅ Jest 配置
# ✅ 测试环境设置  
# ✅ 单元测试文件 (5 个用例)
# ...
# ✅ 总共 42+ 个测试用例
# ✅ 测试套件已准备就绪!

🎉 成功标志

当你看到以下输出时,说明测试成功:

Test Suites: 5 passed, 5 total
Tests:       42 passed, 42 total
Snapshots:   0 total
Time:        XX.XXX s

🎉 所有测试通过!

🔄 实际工作流程

日常开发

# 1. 每次提交前
node test-with-server.js

# 2. 修改代码
# ...

# 3. 再次测试
node test-with-server.js

每次提交前

# 1. 运行完整测试
node test-all.js

# 2. 检查覆盖率
npm run test:coverage

# 3. 提交代码
git add . && git commit -m "feat: xxx" && git push

部署前

# 1. 构建
npm run build

# 2. 完整测试
node test-all.js

# 3. 覆盖率
npm run test:coverage

# 4. 覆盖率检查(确保 > 80%)
# ...

# 5. 部署
npm publish  # 或你的部署命令

📚 完整文档

  • 测试用例文档 - 详细测试说明
  • 测试套件总结 - 覆盖总结
  • 测试运行总结 - 结果统计
  • README_测试说明.md - 完整测试指南

🆘 需要帮助?

# 显示帮助
node test-all.js --help

# 或查看文档
cat README_测试说明.md

🎊 快速开始(一句话)

cd puax-mcp-server && node test-all.js

祝你好运!


文档版本: 1.2.0 最后更新: 2026-01-02

← 返回目录