Skip to content

Commit 2944f74

Browse files
committed
docs(en): merging all conflicts
2 parents a060a86 + a141f9d commit 2944f74

27 files changed

Lines changed: 2303 additions & 0 deletions

.vitepress/config.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,62 @@ export default ({ mode }: { mode: string }) => {
723723
],
724724
},
725725
{
726+
<<<<<<< HEAD
726727
text: '浏览器模式',
728+
=======
729+
text: 'Learn',
730+
collapsed: false,
731+
items: [
732+
{
733+
text: 'Writing Tests',
734+
link: '/guide/learn/writing-tests',
735+
docFooterText: 'Writing Tests | Learn',
736+
},
737+
{
738+
text: 'Using Matchers',
739+
link: '/guide/learn/matchers',
740+
docFooterText: 'Using Matchers | Learn',
741+
},
742+
{
743+
text: 'Testing Async Code',
744+
link: '/guide/learn/async',
745+
docFooterText: 'Testing Async Code | Learn',
746+
},
747+
{
748+
text: 'Setup and Teardown',
749+
link: '/guide/learn/setup-teardown',
750+
docFooterText: 'Setup and Teardown | Learn',
751+
},
752+
{
753+
text: 'Mock Functions',
754+
link: '/guide/learn/mock-functions',
755+
docFooterText: 'Mock Functions | Learn',
756+
},
757+
{
758+
text: 'Snapshot Testing',
759+
link: '/guide/learn/snapshots',
760+
docFooterText: 'Snapshot Testing | Learn',
761+
},
762+
{
763+
text: 'Testing in Practice',
764+
link: '/guide/learn/testing-in-practice',
765+
docFooterText: 'Testing in Practice | Learn',
766+
},
767+
{
768+
text: 'Debugging Tests',
769+
link: '/guide/learn/debugging-tests',
770+
docFooterText: 'Debugging Tests | Learn',
771+
},
772+
{
773+
text: 'Writing Tests with AI',
774+
link: '/guide/learn/writing-tests-with-ai',
775+
docFooterText: 'Writing Tests with AI | Learn',
776+
},
777+
],
778+
},
779+
{
780+
text: 'Browser Mode',
781+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
727782
collapsed: false,
728783
items: [
729784
{
@@ -796,6 +851,7 @@ export default ({ mode }: { mode: string }) => {
796851
collapsed: true,
797852
items: [
798853
{
854+
<<<<<<< HEAD
799855
text: '模拟日期',
800856
link: '/guide/mocking/dates',
801857
},
@@ -825,6 +881,37 @@ export default ({ mode }: { mode: string }) => {
825881
},
826882
{
827883
text: '模拟类',
884+
=======
885+
text: 'Dates',
886+
link: '/guide/mocking/dates',
887+
},
888+
{
889+
text: 'Functions',
890+
link: '/guide/mocking/functions',
891+
},
892+
{
893+
text: 'Globals',
894+
link: '/guide/mocking/globals',
895+
},
896+
{
897+
text: 'Modules',
898+
link: '/guide/mocking/modules',
899+
},
900+
{
901+
text: 'File System',
902+
link: '/guide/mocking/file-system',
903+
},
904+
{
905+
text: 'Requests',
906+
link: '/guide/mocking/requests',
907+
},
908+
{
909+
text: 'Timers',
910+
link: '/guide/mocking/timers',
911+
},
912+
{
913+
text: 'Classes',
914+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
828915
link: '/guide/mocking/classes',
829916
},
830917
],

api/browser/interactivity.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ await originalUserEvent.keyboard('{/Shift}') // 没有放开 shift 键,因为
4040
这种行为更有用,因为我们并没有模拟键盘,而是实际按下了 Shift 键,所以保留原来的行为会在字段中键入时造成意想不到的问题。
4141
:::
4242

43+
::: warning
44+
With `playwright` and `webdriverio` providers, interactions are performed by the underlying browser driver. That means some interaction state, like pressed keys or pointer position and the resulting hover state, can persist between tests in the same file.
45+
46+
Vitest resets unreleased keyboard state automatically before starting each test case, but pointer position and the resulting hover state are not reset automatically since resetting pointer position can be expensive.
47+
48+
This applies both to `userEvent.*` calls and locator shortcuts like `locator.click()` or `locator.hover()`, because they use the same underlying interaction state.
49+
50+
If your tests depend on a neutral hover state, reset it explicitly, for example in `beforeEach`:
51+
52+
```ts
53+
import { beforeEach } from 'vitest'
54+
import { userEvent } from 'vitest/browser'
55+
56+
beforeEach(async () => {
57+
await userEvent.unhover(document.body)
58+
})
59+
```
60+
:::
61+
4362
## userEvent.click
4463

4564
```ts

config/coverage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ npx vitest --coverage.enabled --coverage.provider=istanbul
133133

134134
你可以在 Vitest UI 模式中查看代码覆盖率报告。更多详情请参阅 [Vitest UI Coverage](/guide/coverage#vitest-ui)
135135

136+
::: tip AI coding agents
137+
When Vitest detects it is running inside an AI coding agent, it automatically adds the `text-summary` reporter and sets `skipFull: true` on the `text` reporter to reduce output and minimize token usage.
138+
:::
139+
136140
## coverage.reportOnFailure {#coverage-reportonfailure}
137141

138142
- **类型:** `boolean`

config/experimental.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,41 @@ export default {
477477

478478
如果禁用模块运行器,Vitest 会使用原生 [Node.js 模块加载器](https://nodejs.org/api/module.html#customization-hooks) 来转换文件,以支持 `import.meta.vitest``vi.mock``vi.hoisted` 功能。
479479

480+
<<<<<<< HEAD
480481
如果你不使用这些特性,可禁用此功能以提升性能。
482+
=======
483+
If you don't use these features, you can disable this to improve performance.
484+
485+
## experimental.preParse <Version type="experimental">4.1.3</Version> {#experimental-preparse}
486+
487+
- **Type:** `boolean`
488+
- **Default:** `false`
489+
490+
Parses test specifications before running them. This applies the [`.only`](/api/test#test-only) modifier, the [`-t`](/config/testnamepattern) test name pattern, [`--tags-filter`](/guide/test-tags#syntax), [test lines](/api/advanced/test-specification#testlines), and [test IDs](/api/advanced/test-specification#testids) across all files without executing them. For example, if only a single test is marked with `.only`, Vitest will skip all other tests in all files.
491+
492+
::: tip
493+
This option is recommended when using [`.only`](/api/test#test-only), the [`-t`](/config/testnamepattern) flag, or [`--tags-filter`](/guide/test-tags#syntax).
494+
495+
Enabling it unconditionally may slow down your test runs due to the additional parsing step.
496+
:::
497+
498+
::: warning
499+
Pre-parsing uses static analysis (AST parsing) instead of executing your test files. This means that test names, tags, and modifiers (`.only`, `.skip`, `.todo`) must be statically analyzable. Dynamic test names (e.g., names stored in variables or returned from function calls) and non-literal tags will not be resolved correctly.
500+
501+
```ts
502+
// ✅ works — static string literal
503+
test('adds numbers', () => {})
504+
505+
// ✅ works — static tags
506+
test('my test', { tags: ['unit'] }, () => {})
507+
508+
// ❌ won't match correctly — dynamic name
509+
const name = getName()
510+
test(name, () => {})
511+
512+
// ❌ won't match correctly — dynamic tags
513+
const tags = getTags()
514+
test('my test', { tags }, () => {})
515+
```
516+
:::
517+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16

config/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,14 @@ export default defineConfig(configEnv => mergeConfig(
7979

8080
由于 Vitest 使用 Vite 的配置,我们也可以使用 [Vite](https://vitejs.dev/config/) 中的任何配置选项。例如,使用 `define` 来定义全局变量,或者使用 `resolve.alias` 来定义别名——这些选项应该在顶级定义,而不是在 `test` 属性内部。
8181

82+
<<<<<<< HEAD
8283
[项目](/guide/projects) 配置中不支持的配置选项旁边会显示 <CRoot /> 图标。这意味着它们只能在 Vitest 根配置文件中进行设置。
84+
=======
85+
## Automatic Dependency Installation
86+
87+
Vitest will prompt you to install certain dependencies if they are not already installed. You can disable this behavior by setting the `VITEST_SKIP_INSTALL_CHECKS=1` environment variable.
88+
89+
## Config Options
90+
91+
Configuration options that are not supported inside a [project](/guide/projects) config have <CRoot /> icon next to them. This means they can only be set in the root Vitest config.
92+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16

guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,10 @@ watch 模式下重新运行测试时清除终端屏幕(默认值:`true`)
963963
- **Config:** [experimental.vcsProvider](/config/experimental#experimental-vcsprovider)
964964

965965
Custom provider for detecting changed files. (default: `git`)
966+
967+
### experimental.preParse
968+
969+
- **CLI:** `--experimental.preParse`
970+
- **Config:** [experimental.preParse](/config/experimental#experimental-preparse)
971+
972+
Parse test specifications before running them. This will apply `.only` flag and test name pattern across all files without running them. (default: `false`)

guide/coverage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,12 @@ export function ignored() { // [!code error]
510510

511511
<img alt="html coverage in Vitest UI" img-light src="/ui-coverage-1-light.png">
512512
<img alt="html coverage in Vitest UI" img-dark src="/ui-coverage-1-dark.png">
513+
514+
## Coverage in Agent Environments
515+
516+
When Vitest detects it is running inside an AI coding agent, it automatically adjusts the default `text` reporter to reduce output and minimize token usage:
517+
518+
- `skipFull: true` is set on the `text` reporter, so files with 100% coverage are omitted from the terminal output.
519+
- The [`text-summary`](/config/coverage#coverage-reporter) reporter is added automatically, so the agent always sees a concise totals table even when `skipFull` hides all individual files.
520+
521+
These adjustments only apply when the `text` reporter is already part of the active reporter list (it is included in the default). Explicitly configured reporters are never removed.

guide/extending-matchers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ When using the global `expect` with concurrent tests, `this.task` is `undefined`
156156

157157
断言是否以 [`soft`](/api/expect#soft) 方式调用。您无需手动处理该逻辑,Vitest 始终会捕获错误。
158158

159+
## `assertion` <Advanced /> <Version type="experimental">4.1.4</Version> {#assertion}
160+
161+
The underlying [Chai assertion](https://www.chaijs.com/guide/plugins/) object. This is the same instance that Chai plugins receive, giving you access to Chai's flag system and chainable methods. This can be useful for building custom matchers that need to interact with Chai's internals.
162+
159163
::: tip
160164
以上并非全部可用属性,仅列出最实用的部分。其他状态值由 Vitest 内部使用。
161165
:::

guide/features.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,25 @@ import FeaturesList from '../.vitepress/components/FeaturesList.vue'
1717

1818
<div h-2 />
1919

20+
<<<<<<< HEAD
2021
与 Vite 的配置、转换器、解析器和插件通用,将会使用应用中的相同配置来运行测试。
22+
=======
23+
::: tip
24+
This page is a high-level overview of Vitest's capabilities. If you're new to Vitest, we recommend reading the [Learn](/guide/learn/writing-tests) tutorial first for a hands-on introduction.
25+
:::
26+
27+
## Shared Config between Test, Dev and Build
28+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
2129
2230
了解更多信息 [配置 Vitest](/guide/#configuring-vitest)
2331

32+
<<<<<<< HEAD
2433
## 监听模式(watch mode) {#watch-mode}
34+
=======
35+
Learn more at [Configuring Vitest](/config/).
36+
37+
## Watch Mode
38+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
2539
2640
```bash
2741
$ vitest

guide/index.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
2+
<<<<<<< HEAD
23
title: 快速起步 | 指南
4+
=======
5+
title: Getting Started | Guide
6+
next:
7+
text: Writing Tests
8+
link: /guide/learn/writing-tests
9+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
310
---
411

512
# 快速起步 {#getting-started}
@@ -95,10 +102,17 @@ Test Files 1 passed (1)
95102
如果使用 Bun 作为软件包管理器,请确保使用 `bun run test` 命令而不是 `bun test` 命令,否则 Bun 将运行自己的测试运行程序。
96103
:::
97104

105+
<<<<<<< HEAD
98106
了解更多关于 Vitest 的使用,请参考 [API 索引](/api/test) 部分。
107+
=======
108+
Your first test is passing! Continue to [Writing Tests](/guide/learn/writing-tests) to learn about organizing tests, reading test output, and the core testing patterns you'll use every day.
109+
110+
To run tests once without watching for file changes, use `vitest run`. You can also pass additional flags like `--reporter` or `--coverage`. For a full list of CLI options, run `npx vitest --help` or see the [CLI guide](/guide/cli).
111+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
99112
100113
## 配置 Vitest {#configuring-vitest}
101114

115+
<<<<<<< HEAD
102116
Vitest 的主要优势之一是它与 Vite 的统一配置。如果存在,`vitest` 将读取你的根目录 `vite.config.ts` 以匹配插件并设置为你的 Vite 应用。例如,你的 Vite 有 [resolve.alias](https://cn.vitejs.dev/config/#resolve-alias)[plugins](https://cn.vitejs.dev/guide/using-plugins.html) 的配置将会在 Vitest 中开箱即用。如果你想在测试期间想要不同的配置,你可以:
103117

104118
- 创建 `vitest.config.ts`,优先级将会最高。
@@ -228,6 +242,9 @@ export default defineConfig({
228242
## 自动安装依赖项 {#automatic-dependency-installation}
229243

230244
如果某些依赖项尚未安装,Vitest 会提示您安装。您可以通过设置 `VITEST_SKIP_INSTALL_CHECKS=1` 环境变量来禁用此行为。
245+
=======
246+
Vitest reads your `vite.config.*` by default, so your existing Vite plugins and configuration work out-of-the-box. You can also create a dedicated `vitest.config.*` for test-specific settings. See the [Config Reference](/config/) for details.
247+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
231248
232249
## IDE 集成 {#ide-integrations}
233250

@@ -241,6 +258,7 @@ export default defineConfig({
241258

242259
| 示例 | 源代码 | 演练场 |
243260
|---|---|---|
261+
<<<<<<< HEAD
244262
| `basic` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/basic) | [在线演示](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/) |
245263
| `fastify` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/fastify) | [在线演示](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/fastify?initialPath=__vitest__/) |
246264
| `in-source-test` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test) | [在线演示](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/in-source-test?initialPath=__vitest__/) |
@@ -303,5 +321,23 @@ pnpm link --global # 你可以使用你喜爱的任何包管理工具来设置
303321
然后,回到你的 Vitest 项目并运行 `pnpm link --global vitest`(或者使用你的其他包管理工具来全局链接 `Vitest`)。
304322

305323
## 社区 {#community}
324+
=======
325+
| `basic` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/basic) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/) |
326+
| `fastify` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/fastify) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/fastify?initialPath=__vitest__/) |
327+
| `in-source-test` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/in-source-test?initialPath=__vitest__/) |
328+
| `lit` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/lit) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/lit?initialPath=__vitest__/) |
329+
| `vue` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/vue) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/vue?initialPath=__vitest__/) |
330+
| `marko` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/marko) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/marko?initialPath=__vitest__/) |
331+
| `preact` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/preact) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/preact?initialPath=__vitest__/) |
332+
| `qwik` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/qwik) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/qwik?initialPath=__vitest__/) |
333+
| `react` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/react) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/react?initialPath=__vitest__/) |
334+
| `solid` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/solid) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/solid?initialPath=__vitest__/) |
335+
| `svelte` | [GitHub](https://github.com/vitest-tests/browser-examples/tree/main/examples/svelte) | [Play Online](https://stackblitz.com/fork/github/vitest-tests/browser-examples/tree/main/examples/svelte?initialPath=__vitest__/) |
336+
| `profiling` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/profiling) | Not Available |
337+
| `typecheck` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/typecheck) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/typecheck?initialPath=__vitest__/) |
338+
| `projects` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/projects) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/projects?initialPath=__vitest__/) |
339+
340+
## Community
341+
>>>>>>> a141f9d49fa021ae0f1d6962f9dbc8bce3bbdd16
306342
307343
如果你有疑问或者需要帮助,可以到 [Discord](https://chat.vitest.dev)[GitHub Discussions](https://github.com/vitest-dev/vitest/discussions) 社区来寻求帮助。

0 commit comments

Comments
 (0)