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

⛔ 禁用模式

  1. NO
    jest
    Global
    : Do not use
    jest.fn()
    or
    jest.mock()
    . Use
    vi.fn()
    and
    vi.mock()
    .
  2. NO CommonJS require: Vitest is ESM-first. Use
    import
    statements.
  3. NO Slow TypeScript Compilation: Vitest compiles via Vite (esbuild), so avoid adding heavy
    tsc
    steps in the test runner itself.
  4. NO
    module.exports
    : Use
    export default
    or named exports in your test files or mocks.
  1. 禁止使用
    jest
    全局对象
    :不要使用
    jest.fn()
    jest.mock()
    。请使用
    vi.fn()
    vi.mock()
  2. 禁止使用CommonJS的require:Vitest优先支持ESM。请使用
    import
    语句。
  3. 禁止缓慢的TypeScript编译:Vitest通过Vite(esbuild)进行编译,因此请避免在测试运行器中添加繁重的
    tsc
    步骤。
  4. 禁止使用
    module.exports
    :在测试文件或模拟文件中请使用
    export default
    或具名导出。

🤖 Agent Tool Strategy

🤖 Agent工具策略

  1. Config Check: Look for
    vitest.config.ts
    or
    vite.config.ts
    to understand the environment (globals enabled? environment: jsdom?).
  2. Migration: If the user is moving from Jest, highlight that most APIs are identical, just replace the global object.
  3. Mocking: Use
    vi.spyOn
    and
    vi.mock
    for isolating dependencies.
  4. UI: Mention
    vitest ui
    for a visual test runner experience.
  1. 配置检查:查找
    vitest.config.ts
    vite.config.ts
    以了解环境(是否启用全局变量?环境为jsdom?)。
  2. 迁移指导:如果用户正从Jest迁移,需强调大多数API完全相同,只需替换全局对象即可。
  3. 模拟操作:使用
    vi.spyOn
    vi.mock
    来隔离依赖项。
  4. 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:
  1. Write tests in
    *.test.ts
    .
  2. Run
    vitest
    for watch mode.
  3. Run
    vitest run
    for CI.

Vitest专家 - "Vite原生单元测试"
设计理念:
  • 共享配置:使用现有的
    vite.config.ts
  • 极速运行:由esbuild驱动。
  • 高度兼容:API与Jest的兼容性达95%。
工作流程:
  1. *.test.ts
    中编写测试用例。
  2. 运行
    vitest
    进入监听模式。
  3. 运行
    vitest run
    用于CI环境。

Resources

资源

  • Examples: See
    examples/examples.md
    for detailed code patterns.
  • References: See
    references/reference.md
    for official documentation links. </skill_doc>
  • 示例:查看
    examples/examples.md
    获取详细代码模式。
  • 参考文档:查看
    references/reference.md
    获取官方文档链接。 </skill_doc>