本项目包含严格的单元测试,用于验证平台迁移和代码结构的正确性。
platform-migration.test.js这是一个综合性的平台迁移测试套件,包含以下测试类别:
platforms 目录存在zhipu 目录存在zhipu 子目录完整(questionAnswer, knowledgeLib, dataExport)deepseek 目录保持存在# 运行平台迁移测试
node tests/platform-migration.test.js
🚀 开始平台迁移测试...
🏗️ 测试目录结构...
🛣️ 测试路由配置...
📁 测试文件完整性...
📦 测试导入路径...
🔨 测试构建兼容性...
📊 测试结果汇总:
总测试数: 23
通过: 23
失败: 0
成功率: 100.00%
📋 详细结果:
1. ✅ platforms 目录存在
2. ✅ zhipu 目录存在
3. ✅ zhipu 子目录完整
...
🎉 所有测试通过!平台迁移成功。
当前测试覆盖了以下关键方面:
问题描述: 智谱AI平台切换后,所有按钮都会重定向到404页面。
根本原因:
/questionAnswer、/knowledgeLib、/dataExport)修复内容:
更新 src/pages/layout/components/Nav.tsx 中的智谱AI菜单项路径:
/questionAnswer → /zhipu/questionAnswer/knowledgeLib → /zhipu/knowledgeLib/dataExport → /zhipu/dataExport更新 src/pages/layout/index.tsx 中的默认路径切换逻辑:
/questionAnswer 改为 /zhipu/questionAnswer验证结果:
要添加新的测试用例,请在 PlatformMigrationTests 类中添加新的测试方法:
testNewFeature() {
console.log('\n🔍 测试新功能...');
// 测试逻辑
const result = someTestLogic();
this.collector.addResult(
'新功能测试',
result,
result ? '' : '测试失败的原因'
);
}
然后在 runAllTests() 方法中调用新测试:
runAllTests() {
console.log('🚀 开始平台迁移测试...\n');
this.testDirectoryStructure();
this.testRouterConfiguration();
this.testFileIntegrity();
this.testImportPaths();
this.testBuildCompatibility();
this.testNewFeature(); // 添加新测试
// 输出结果
this.collector.printResults();
}
建议在 CI/CD 流程中包含这些测试:
# .github/workflows/test.yml
name: Platform Migration Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install
- run: node tests/platform-migration.test.js
- run: npm run build