vitest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVitest is a next-generation testing framework powered by Vite. It provides a Jest-compatible API with native ESM, TypeScript, and JSX support out of the box. Vitest shares the same config, transformers, resolvers, and plugins with your Vite app.
Key Features:
- Vite-native: Uses Vite's transformation pipeline for fast HMR-like test updates
- Jest-compatible: Drop-in replacement for most Jest test suites
- Smart watch mode: Only reruns affected tests based on module graph
- Native ESM, TypeScript, JSX support without configuration
- Multi-threaded workers for parallel test execution
- Built-in coverage via V8 or Istanbul
- Snapshot testing, mocking, and spy utilities
The skill is based on Vitest 3.x, generated at 2026-01-28.
Vitest 是由 Vite 驱动的下一代测试框架。它提供与 Jest 兼容的 API,原生支持 ESM、TypeScript 和 JSX,无需额外配置。Vitest 与你的 Vite 应用共享相同的配置、转换器、解析器和插件。
核心特性:
- 基于Vite原生:使用Vite的转换流水线实现类HMR的快速测试更新
- 兼容Jest:可直接替代大多数Jest测试套件
- 智能监听模式:基于模块图谱仅重新运行受影响的测试
- 原生支持ESM、TypeScript和JSX,无需配置
- 多线程工作器支持并行测试执行
- 通过V8或Istanbul提供内置覆盖率统计
- 支持快照测试、模拟和间谍工具
本技能基于 Vitest 3.x 版本生成,生成日期为2026年1月28日。
Core
核心功能
| Topic | Description | Reference |
|---|---|---|
| Configuration | Vitest and Vite config integration, defineConfig usage | core-config |
| CLI | Command line interface, commands and options | core-cli |
| Test API | test/it function, modifiers like skip, only, concurrent | core-test-api |
| Describe API | describe/suite for grouping tests and nested suites | core-describe |
| Expect API | Assertions with toBe, toEqual, matchers and asymmetric matchers | core-expect |
| Hooks | beforeEach, afterEach, beforeAll, afterAll, aroundEach | core-hooks |
| 主题 | 描述 | 参考文档 |
|---|---|---|
| 配置 | Vitest 与 Vite 配置集成,defineConfig 的使用 | core-config |
| 命令行界面(CLI) | 命令行界面,命令及选项 | core-cli |
| 测试API | test/it 函数,skip、only、concurrent 等修饰符 | core-test-api |
| Describe API | 使用 describe/suite 分组测试及嵌套测试套件 | core-describe |
| Expect API | 包含 toBe、toEqual、匹配器和非对称匹配器的断言 | core-expect |
| 钩子函数 | beforeEach、afterEach、beforeAll、afterAll、aroundEach | core-hooks |
Features
扩展功能
| Topic | Description | Reference |
|---|---|---|
| Mocking | Mock functions, modules, timers, dates with vi utilities | features-mocking |
| Snapshots | Snapshot testing with toMatchSnapshot and inline snapshots | features-snapshots |
| Coverage | Code coverage with V8 or Istanbul providers | features-coverage |
| Test Context | Test fixtures, context.expect, test.extend for custom fixtures | features-context |
| Concurrency | Concurrent tests, parallel execution, sharding | features-concurrency |
| Filtering | Filter tests by name, file patterns, tags | features-filtering |
| 主题 | 描述 | 参考文档 |
|---|---|---|
| 模拟 | 使用 vi 工具类实现模拟函数、模块、计时器、日期 | features-mocking |
| 快照测试 | 使用 toMatchSnapshot 和内联快照进行快照测试 | features-snapshots |
| 覆盖率 | 通过 V8 或 Istanbul 提供代码覆盖率统计 | features-coverage |
| 测试上下文 | 测试夹具、context.expect、test.extend 自定义夹具 | features-context |
| 并发 | 并发测试、并行执行、分片 | features-concurrency |
| 过滤 | 按名称、文件模式、标签过滤测试 | features-filtering |
Advanced
进阶功能
| Topic | Description | Reference |
|---|---|---|
| Vi Utilities | vi helper: mock, spyOn, fake timers, hoisted, waitFor | advanced-vi |
| Environments | Test environments: node, jsdom, happy-dom, custom | advanced-environments |
| Type Testing | Type-level testing with expectTypeOf and assertType | advanced-type-testing |
| Projects | Multi-project workspaces, different configs per project | advanced-projects |
| 主题 | 描述 | 参考文档 |
|---|---|---|
| Vi 工具类 | vi 辅助工具:mock、spyOn、假计时器、hoisted、waitFor | advanced-vi |
| 测试环境 | 测试环境:node、jsdom、happy-dom、自定义环境 | advanced-environments |
| 类型测试 | 使用 expectTypeOf 和 assertType 进行类型级测试 | advanced-type-testing |
| 多项目 | 多项目工作区,每个项目可配置不同的设置 | advanced-projects |