Skip to content

Commit 4f107b0

Browse files
committed
docs: update content
1 parent d969e98 commit 4f107b0

File tree

7 files changed

+16
-175
lines changed

7 files changed

+16
-175
lines changed

api/expect.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
type Awaitable<T> = T | PromiseLike<T>
77
```
88
9-
<<<<<<< HEAD
10-
`expect` 用于创建断言。在这种情况下, `assertions` 是可以调用来断言语句的函数。 Vitest 默认提供 `chai` 断言,并且还在 `chai` 之上构建了与 `Jest` 兼容的断言。
11-
=======
12-
`expect` is used to create assertions. In this context `assertions` are functions that can be called to assert a statement. Vitest provides `chai` assertions by default and also `Jest` compatible assertions built on top of `chai`. Unlike `Jest`, Vitest supports a message as the second argument - if the assertion fails, the error message will be equal to it.
9+
`expect` 用于创建断言。在此上下文中,`断言` 是可以被调用来验证一个语句的函数。Vitest 默认提供 `chai` 断言,并且还提供了基于 `chai` 构建的与 `Jest` 兼容的断言。与 `Jest` 不同的是,Vitest 支持将消息作为第二个参数——如果断言失败,错误信息将等于该消息。
1310
1411
```ts
1512
export interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
@@ -22,7 +19,6 @@ export interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersConta
2219
not: AsymmetricMatchersContaining
2320
}
2421
```
25-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
2622

2723
例如,此代码断言 `input` 值等于 `2`。 如果不是,assertions 将抛出错误,并且测试将失败。
2824

config/index.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ export default defineConfig({
106106

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

109-
<<<<<<< HEAD
110-
不支持在[工作区](/guide/workspace)项目配置中的配置选项旁边会有 <NonProjectOption /> 标志。
111-
=======
112-
Configuration options that are not supported inside a [workspace](/guide/workspace) project config have <NonProjectOption /> sign next to them. This means they can only be set in the root Vitest config.
113-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
109+
不支持在[工作区](/guide/workspace)项目配置中的配置选项旁边会有 <NonProjectOption /> 标志。这意味着这些选项只能在根 Vitest 配置中设置。
114110
:::
115111

116112
### include
@@ -686,15 +682,9 @@ export default defineConfig({
686682

687683
### watch<NonProjectOption />
688684

689-
<<<<<<< HEAD
690685
- **类型:** `boolean`
691-
- **默认值:** `!process.env.CI`
686+
- **默认值:** `!process.env.CI && process.stdin.isTTY`
692687
- **命令行终端:** `-w`, `--watch`, `--watch=false`
693-
=======
694-
- **Type:** `boolean`
695-
- **Default:** `!process.env.CI && process.stdin.isTTY`
696-
- **CLI:** `-w`, `--watch`, `--watch=false`
697-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
698688

699689
启动监听模式
700690

guide/browser/config.md

+6-37
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,8 @@ export default defineConfig({
110110
- **类型:** `string`
111111
- **CLI:** `--browser=safari`
112112

113-
<<<<<<< HEAD
114-
::: danger
115-
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
116-
=======
117113
::: danger DEPRECATED
118-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.instances`](#browser-instances) option instead.
119-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
114+
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
120115
:::
121116

122117
在特定浏览器中运行所有测试。不同提供者中的可能选项:
@@ -155,25 +150,13 @@ HTML 入口点的路径。可以是相对于项目根目录的路径。此文件
155150

156151
配置为浏览器提供代码的 Vite 服务器的选项。不影响 [`test.api`](#api) 选项。默认情况下,Vitest 分配端口 `63315` 以避免与开发服务器冲突,允许我们同时运行两者。
157152

158-
<<<<<<< HEAD
159-
## browser.provider <Badge type="warning">实验性</Badge> {#browser-provider}
160-
=======
161153
## browser.provider {#browser-provider}
162-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
163154

164155
- **类型:** `'webdriverio' | 'playwright' | 'preview' | string`
165156
- **默认值:** `'preview'`
166157
- **CLI:** `--browser.provider=playwright`
167158

168-
<<<<<<< HEAD
169-
::: danger 高级 API
170-
提供者 API 是高度实验性的,可能会在补丁之间发生变化。如果我们只需要在浏览器中运行测试,请改用 [`browser.instances`](#browser-instances) 选项。
171-
:::
172-
173-
运行浏览器测试时使用的提供者路径。Vitest 提供了三个提供者,分别是 `preview`(默认)、`webdriverio``playwright`。自定义提供者应使用 `default` 导出,并具有以下形状:
174-
=======
175-
Path to a provider that will be used when running browser tests. Vitest provides three providers which are `preview` (default), `webdriverio` and `playwright`. Custom providers should be exported using `default` export and have this shape:
176-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
159+
在运行浏览器测试时使用的提供者路径。Vitest 提供了三个提供者,分别是 `preview`(默认)、`webdriverio``playwright`。自定义提供者应使用 `default` 导出,并具有以下形状:
177160

178161
```ts
179162
export interface BrowserProvider {
@@ -193,25 +176,16 @@ export interface BrowserProvider {
193176
}
194177
```
195178

196-
<<<<<<< HEAD
197-
## browser.providerOptions <Badge type="danger">已弃用</Badge> {#browser-provideroptions}
198-
=======
199179
::: danger ADVANCED API
200-
The custom provider API is highly experimental and can change between patches. If you just need to run tests in a browser, use the [`browser.instances`](#browser-instances) option instead.
180+
自定义提供者 API 高度实验性,并且可能在补丁版本之间发生变化。如果你只需要在浏览器中运行测试,请改用 [`browser.instances`](#browser-instances) 选项。
201181
:::
202182

203-
## browser.providerOptions <Badge type="danger">deprecated</Badge> {#browser-provideroptions}
204-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
183+
## browser.providerOptions <Badge type="danger">已弃用</Badge> {#browser-provideroptions}
205184

206185
- **类型:** `BrowserProviderOptions`
207186

208-
<<<<<<< HEAD
209-
::: danger
210-
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
211-
=======
212187
::: danger DEPRECATED
213-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.instances`](#browser-instances) option instead.
214-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
188+
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
215189
:::
216190

217191
调用 `provider.initialize` 时传递给提供者的选项。
@@ -326,13 +300,8 @@ export interface BrowserScript {
326300
- **类型:** `BrowserScript[]`
327301
- **默认值:** `[]`
328302

329-
<<<<<<< HEAD
330-
::: danger
331-
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.testerHtmlPath`](#browser-testerhtmlpath) 字段。
332-
=======
333303
::: danger DEPRECATED
334-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.testerHtmlPath`](#browser-testerhtmlpath) field instead.
335-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
304+
此 API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.testerHtmlPath`](#browser-testerhtmlpath) 字段。
336305
:::
337306

338307
在测试环境初始化之前应注入到测试器 HTML 中的自定义脚本。这对于注入 Vitest 浏览器实现所需的 polyfill 非常有用。在几乎所有情况下,建议使用 [`setupFiles`](#setupfiles) 代替此选项。

guide/cli.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ outline: deep
99

1010
### `vitest`
1111

12-
<<<<<<< HEAD
13-
在当前目录中启动 Vitest。在开发环境会自动进入监听(`watch`)模式,在 CI 环境会自动进入运行(`run`)模式。
14-
=======
15-
Start Vitest in the current directory. Will enter the watch mode in development environment and run mode in CI (or non-interactive terminal) automatically.
16-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
12+
在当前目录启动 Vitest。在开发环境中会自动进入监听模式,而在 CI 环境(或非交互式终端)中会自动运行测试模式。
1713

1814
你可以通过添加参数作为过滤器来运行测试文件,比如:
1915

@@ -54,11 +50,7 @@ $ vitest basic/foo.test.ts:10-25 # ❌
5450

5551
### `vitest watch`
5652

57-
<<<<<<< HEAD
5853
运行所有测试套件,监听变化并在变化时重新运行测试。与没有参数的情况下调用 `vitest` 一样。在 CI 环境中,此命令将回退到 `vitest run`
59-
=======
60-
Run all test suites but watch for changes and rerun tests when they change. Same as calling `vitest` without an argument. Will fallback to `vitest run` in CI or when stdin is not a TTY (non-interactive environment).
61-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
6254

6355
### `vitest dev`
6456

guide/index.md

+1-23
Original file line numberDiff line numberDiff line change
@@ -181,32 +181,11 @@ export default defineConfig({
181181

182182
## 支持工作空间
183183

184-
<<<<<<< HEAD
185-
使用 [Vitest Workspaces](/guide/workspace) 在同一项目中运行不同的项目配置。你可以在`vitest.workspace`文件中定义工作区的文件和文件夹列表。该文件支持 `js` / `ts` / `json` 扩展名。此功能非常适合配合 monorepo 使用。
186-
=======
187-
Run different project configurations inside the same project with [Vitest Workspaces](/guide/workspace). You can define a list of files and folders that define your workspace in `vitest.config` file.
188-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
184+
在同一个项目中使用 [Vitest 工作区](/guide/workspace)运行不同的项目配置。你可以在 `vitest.config` 文件中定义一个包含文件和文件夹的列表来指定你的工作区。
189185

190186
```ts [vitest.config.ts]
191187
import { defineConfig } from 'vitest/config'
192188

193-
<<<<<<< HEAD
194-
export default defineWorkspace([
195-
// 你可以用一个 glob 模式列表来定义你的工作空间
196-
// Vitest 希望一系列配置文件
197-
// 或者包含一个配置文件的目录
198-
'packages/*',
199-
'tests/*/vitest.config.{e2e,unit}.ts',
200-
// 你甚至可以在同一个 "vitest" 进程中以不同的配置
201-
// 运行相同的测试
202-
{
203-
test: {
204-
name: 'happy-dom',
205-
root: './shared_tests',
206-
environment: 'happy-dom',
207-
setupFiles: ['./setup.happy-dom.ts'],
208-
},
209-
=======
210189
export default defineConfig({
211190
test: {
212191
workspace: [
@@ -234,7 +213,6 @@ export default defineConfig({
234213
},
235214
},
236215
],
237-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
238216
},
239217
})
240218
```

guide/mocking.md

-4
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,7 @@ test('can feed dogs', () => {
701701
```
702702
:::
703703

704-
<<<<<<< HEAD
705704
现在,当我们创建一个新的 `Dog` 类实例时,它的 `speak` 方法(与 `feed` 并列)已经被模拟:
706-
=======
707-
Now, when we create a new instance of the `Dog` class its `speak` method (alongside `feed` and `greet`) is already mocked:
708-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
709705

710706
```ts
711707
const Cooper = new Dog('Cooper')

guide/workspace.md

+5-85
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ Vitest 提供了在单个 Vitest 进程中定义多个项目配置的方法。
1414

1515
## 定义工作空间
1616

17-
<<<<<<< HEAD
18-
工作区必须在其根目录中包含一个 `vitest.workspace``vitest.projects` 文件(位于与我们的根配置文件相同的文件夹中,或者如果不存在,则位于工作目录中)。请注意,`projects` 只是一个别名,不会改变此功能的行为或语义。Vitest 支持此文件的 `ts``js``json` 扩展名。
19-
20-
自Vitest 3起,我们也可以在根配置文件中定义工作区。在这种情况下,如果存在,Vitest将忽略根目录下的 `vitest.workspace` 文件。
21-
=======
22-
Since Vitest 3, you can define a workspace in your root [config](/config/). In this case, Vitest will ignore the `vitest.workspace` file in the root, if one exists.
17+
从 Vitest 3 开始,你可以在根 [配置](/config/) 中定义工作区。在这种情况下,如果根目录下存在 `vitest.workspace` 文件,Vitest 将会忽略它。
2318

2419
```ts [vitest.config.ts]
2520
import { defineConfig } from 'vitest/config'
@@ -31,22 +26,14 @@ export default defineConfig({
3126
})
3227
```
3328

34-
If you are using an older version, a workspace must include `vitest.workspace` or `vitest.projects` file in its root directory (located in the same folder as your root configuration file or working directory if it doesn't exist). Note that `projects` is just an alias and does not change the behavior or semantics of this feature. Vitest supports `ts`, `js`, and `json` extensions for this file.
35-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
29+
如果你使用的是较早的版本,工作区必须在其根目录中包含 `vitest.workspace``vitest.projects` 文件(如果不存在,则位于根配置文件所在的文件夹或工作目录中)。请注意,`projects` 只是一个别名,并不会改变此功能的行为或语义。Vitest 支持该文件的 `ts``js``json` 扩展名。
3630

3731
::: tip NAMING
3832
:::
3933

4034
工作区是一系列内联配置、文件或引用我们项目的全局模式的列表。例如,如果我们有一个名为 `packages` 的文件夹,其中包含了我们的项目,我们可以直接创建一个工作区文件,或者在根配置中定义一个数组:
4135

4236
:::code-group
43-
<<<<<<< HEAD
44-
45-
```ts [vitest.workspace.ts]
46-
export default ['packages/*']
47-
```
48-
=======
49-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
5037
```ts [vitest.config.ts <Version>3.0.0</Version>]
5138
import { defineConfig } from 'vitest/config'
5239

@@ -72,13 +59,6 @@ Vitest 不会将根目录下的 `vitest.config` 文件视为工作区项目,
7259
你还可以使用项目的配置文件引用项目:
7360

7461
:::code-group
75-
<<<<<<< HEAD
76-
77-
```ts [vitest.workspace.ts]
78-
export default ['packages/*/vitest.config.{e2e,unit}.ts']
79-
```
80-
=======
81-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
8262
```ts [vitest.config.ts <Version>3.0.0</Version>]
8363
import { defineConfig } from 'vitest/config'
8464

@@ -97,41 +77,9 @@ export default [
9777

9878
该模式仅包括具有包含 `e2e``unit``vitest.config` 文件的项目。这些关键字需要在文件扩展名之前出现。
9979

100-
<<<<<<< HEAD
101-
你也可以使用内联配置定义项目。工作区文件同时支持这两种语法。
102-
103-
:::code-group
104-
```ts [vitest.workspace.ts]
105-
import { defineWorkspace } from 'vitest/config'
106-
107-
// defineWorkspace 会提供一个很好的类型提示开发体验
108-
export default defineWorkspace([
109-
// matches every folder and file inside the `packages` folder
110-
'packages/*',
111-
{
112-
// 添加 "extends" 将两个配置合并到一起
113-
extends: './vite.config.js',
114-
test: {
115-
include: ['tests/**/*.{browser}.test.{ts,js}'],
116-
// 在使用内联配置的时候,建议定义一个名称
117-
name: 'happy-dom',
118-
environment: 'happy-dom',
119-
},
120-
},
121-
{
122-
test: {
123-
include: ['tests/**/*.{node}.test.{ts,js}'],
124-
name: 'node',
125-
environment: 'node',
126-
},
127-
},
128-
])
129-
```
130-
=======
131-
You can also define projects using inline configuration. The workspace configuration supports both syntaxes simultaneously.
80+
你也可以使用内联配置来定义项目。工作区配置同时支持这两种语法。
13281

13382
:::code-group
134-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
13583
```ts [vitest.config.ts <Version>3.0.0</Version>]
13684
import { defineConfig } from 'vitest/config'
13785

@@ -195,28 +143,9 @@ export default defineWorkspace([
195143

196144
如果我们不使用内联配置,我们可以在根目录创建一个小的 JSON 文件,或者仅仅在根配置中指定它:
197145

198-
<<<<<<< HEAD
199-
:::code-group
200-
201-
=======
202-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
203146
```json [vitest.workspace.json]
204147
["packages/*"]
205148
```
206-
<<<<<<< HEAD
207-
```ts [vitest.config.ts <Version>3.0.0</Version>]
208-
import { defineConfig } from 'vitest/config'
209-
210-
export default defineConfig({
211-
test: {
212-
workspace: ['packages/*'],
213-
},
214-
})
215-
```
216-
217-
:::
218-
=======
219-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
220149

221150
工作区项目不支持所有配置属性。为了提高类型安全性,请在项目配置文件中使用 `defineProject` 方法而不是 `defineConfig` 方法:
222151

@@ -376,22 +305,13 @@ export default defineWorkspace([
376305
```
377306
:::
378307

379-
<<<<<<< HEAD
380-
某些配置选项不允许在项目配置中使用。其中最明显的是:
381-
=======
382308
::: danger Unsupported Options
383-
Some of the configuration options are not allowed in a project config. Most notably:
384-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
309+
某些配置选项不允许在项目配置中使用。其中最明显的是:
385310

386311
- `coverage`: 覆盖率是针对整个工作区进行的。
387312
- `reporters`: 仅支持根级别的报告器。
388313
- `resolveSnapshotPath`: 仅支持根级别的解析器。
389314
- 所有其他不影响测试运行器的选项。
390315

391-
<<<<<<< HEAD
392-
::: tip
393-
所有不支持在项目配置中使用的配置选项,在 ["Config"](/config/) 指南中以 <NonProjectOption /> 标记。
394-
=======
395-
All configuration options that are not supported inside a project configuration are marked with a <NonProjectOption /> sign in the ["Config"](/config/) guide. They have to be defined once in the root config file.
396-
>>>>>>> 63d97cc6b11e1655c78a610d385a02a7c04271c0
316+
所有在项目配置中不支持的配置选项在 ["Config"](/config/) 指南中都会标记为 <NonProjectOption />。这些选项必须在根配置文件中定义一次。
397317
:::

0 commit comments

Comments
 (0)