vitest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<skill_doc>
<trigger_keywords>
<skill_doc>
<trigger_keywords>
Trigger Keywords
触发关键词
Activate this skill when the user mentions any of:
Core: Vitest, Vite Test, vi.mock, vi.fn, describe, it, test, expect
Configuration: vitest.config.ts, in-source testing, coverage
Comparison: Jest replacement, faster than Jest
</trigger_keywords>
当用户提及以下任意内容时激活此技能:
核心:Vitest, Vite Test, vi.mock, vi.fn, describe, it, test, expect
配置:vitest.config.ts, 源码内测试, coverage
对比:Jest替代方案, 比Jest更快
</trigger_keywords>
⛔ Forbidden Patterns
⛔ 禁用模式
- NO Global: Do not use
jestorjest.fn(). Usejest.mock()andvi.fn().vi.mock() - NO CommonJS require: Vitest is ESM-first. Use statements.
import - NO Slow TypeScript Compilation: Vitest compiles via Vite (esbuild), so avoid adding heavy steps in the test runner itself.
tsc - NO : Use
module.exportsor named exports in your test files or mocks.export default
- 禁止使用全局对象:不要使用
jest或jest.fn()。请使用jest.mock()和vi.fn()。vi.mock() - 禁止使用CommonJS的require:Vitest优先支持ESM。请使用语句。
import - 禁止缓慢的TypeScript编译:Vitest通过Vite(esbuild)进行编译,因此请避免在测试运行器中添加繁重的步骤。
tsc - 禁止使用:在测试文件或模拟文件中请使用
module.exports或具名导出。export default
🤖 Agent Tool Strategy
🤖 Agent工具策略
- Config Check: Look for or
vitest.config.tsto understand the environment (globals enabled? environment: jsdom?).vite.config.ts - Migration: If the user is moving from Jest, highlight that most APIs are identical, just replace the global object.
- Mocking: Use and
vi.spyOnfor isolating dependencies.vi.mock - UI: Mention for a visual test runner experience.
vitest ui
- 配置检查:查找或
vitest.config.ts以了解环境(是否启用全局变量?环境为jsdom?)。vite.config.ts - 迁移指导:如果用户正从Jest迁移,需强调大多数API完全相同,只需替换全局对象即可。
- 模拟操作:使用和
vi.spyOn来隔离依赖项。vi.mock - UI界面:推荐使用以获得可视化测试运行器体验。
vitest ui
Quick Reference (30 seconds)
快速参考(30秒)
Vitest Specialist - "Vite Native Unit Testing".
Philosophy:
- Shared Config: Uses your existing .
vite.config.ts - Fast: Powered by esbuild.
- Compatible: API is 95% compatible with Jest.
Workflow:
- Write tests in .
*.test.ts - Run for watch mode.
vitest - Run for CI.
vitest run
Vitest专家 - "Vite原生单元测试"
设计理念:
- 共享配置:使用现有的。
vite.config.ts - 极速运行:由esbuild驱动。
- 高度兼容:API与Jest的兼容性达95%。
工作流程:
- 在中编写测试用例。
*.test.ts - 运行进入监听模式。
vitest - 运行用于CI环境。
vitest run
Resources
资源
- Examples: See for detailed code patterns.
examples/examples.md - References: See for official documentation links. </skill_doc>
references/reference.md
- 示例:查看获取详细代码模式。
examples/examples.md - 参考文档:查看获取官方文档链接。 </skill_doc>
references/reference.md