Features: - Combat system with AP/EP hit calculation and three-layer defense - Auto-combat/farming mode - Item system with stacking support - Skill system with levels, milestones, and parent skill sync - Shop system with dynamic pricing - Inventory management with bulk selling - Event system - Game loop with offline earnings - Save/Load system Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.2 KiB
2.2 KiB
Vitest 模块解析问题解决方案
诊断结果
经过深入排查,发现 Vitest 在当前环境中存在以下问题:
- "No test suite found" 错误:Vitest 无法正确识别 ESM 模块中的 describe/test 块
- 版本兼容性:即使升级到 Vitest 4.0,问题依然存在
- 配置问题:尝试了多种配置方式均无效
可能的根本原因
- Node.js v22.13.1 兼容性问题:较新的 Node.js 版本可能与 Vitest 1.x 存在兼容性问题
- ESM 模块解析:虽然 package.json 设置了
"type": "module",但 Vitest 的模块转换器可能有问题 - Windows 路径问题:在 Windows 环境下路径解析可能存在问题
推荐的解决方案
方案 1:切换到 Jest(推荐)
Jest 是更成熟的测试框架,对 Node.js 和 Windows 的支持更好:
npm install -D jest @vue/test-utils@vue3 jest-environment-jsdom
创建 jest.config.js:
export default {
testEnvironment: 'node',
transform: {},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1'
},
testMatch: ['**/tests/**/*.spec.{js,mjs}']
}
方案 2:降级 Node.js 版本
使用 Node.js LTS 版本(如 v18 或 v20)而不是最新的 v22:
nvm install 20
nvm use 20
方案 3:使用 Vitest 的 CommonJS 模式
- 移除 package.json 中的
"type": "module" - 将所有测试文件改用 CommonJS 语法(require)
- 将配置文件改为
.cjs扩展名
方案 4:使用 Bun Test
Bun 是一个新的 JavaScript 运行时,内置测试功能:
npm install -D bun
bun test tests/
测试文件建议
无论使用哪个方案,建议创建一个简单的测试先验证环境:
// tests/simple.test.js
import { describe, it, expect } from 'vitest' // 或从 'jest'
describe('环境验证', () => {
it('应该能够运行基础测试', () => {
expect(1 + 1).toBe(2)
})
})
当前项目状态
- ✅ 代码修复已完成
- ✅ 测试计划已制定
- ✅ 测试基础设施已创建
- ⚠️ 测试框架配置存在问题
建议优先选择方案 1(Jest)或方案 2(降级 Node.js),这两个方案最有可能解决问题。