Skip to content

Commit cb90bf2

Browse files
committed
docs: merging guide conflicts
1 parent ebfb565 commit cb90bf2

File tree

6 files changed

+142
-150
lines changed

6 files changed

+142
-150
lines changed

blog/vitest-3.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ head:
1010
content: website
1111
- - meta
1212
- property: og:title
13-
content: Announcing Vitest 3.0
13+
content: Vitest 3.0 发布了!
1414
- - meta
1515
- property: og:image
1616
content: https://vitest.dev/og-vitest-3.jpg
@@ -25,7 +25,7 @@ head:
2525
content: summary_large_image
2626
---
2727

28-
# Vitest 3.0 is out!
28+
# Vitest 3.0 发布了!
2929

3030
_January 17, 2025_
3131

guide/browser/config.md

+90-90
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Browser Config Reference
1+
# 浏览器配置参考
22

3-
You can change the browser configuration by updating the `test.browser` field in your [config file](/config/). An example of a simple config file:
3+
我们可以通过更新 [配置文件](/config/) 中的 `test.browser` 字段来更改浏览器配置。一个简单的配置文件示例如下:
44

55
```ts [vitest.config.ts]
66
import { defineConfig } from 'vitest/config'
@@ -21,10 +21,10 @@ export default defineConfig({
2121
})
2222
```
2323

24-
Please, refer to the ["Config Reference"](/config/) article for different config examples.
24+
请参阅 ["配置参考"](/config/) 文章以获取不同的配置示例。
2525

2626
::: warning
27-
_All listed options_ on this page are located within a `test` property inside the configuration:
27+
此页面上列出的 _所有选项_ 都位于配置中的 `test` 属性内:
2828

2929
```ts [vitest.config.js]
3030
export default defineConfig({
@@ -37,35 +37,35 @@ export default defineConfig({
3737

3838
## browser.enabled
3939

40-
- **Type:** `boolean`
41-
- **Default:** `false`
40+
- **类型:** `boolean`
41+
- **默认值:** `false`
4242
- **CLI:** `--browser`, `--browser.enabled=false`
4343

44-
Run all tests inside a browser by default. Note that `--browser` only works if you have at least one [`browser.instances`](#browser-instances) item.
44+
默认情况下在浏览器中运行所有测试。请注意,`--browser` 仅在我们至少有一个 [`browser.instances`](#browser-instances) 项时有效。
4545

4646
## browser.instances
4747

48-
- **Type:** `BrowserConfig`
49-
- **Default:** `[{ browser: name }]`
48+
- **类型:** `BrowserConfig`
49+
- **默认值:** `[{ browser: name }]`
5050

51-
Defines multiple browser setups. Every config has to have at least a `browser` field. The config supports your providers configurations:
51+
定义多个浏览器设置。每个配置必须至少有一个 `browser` 字段。配置支持我们的提供者配置:
5252

53-
- [Configuring Playwright](/guide/browser/playwright)
54-
- [Configuring WebdriverIO](/guide/browser/webdriverio)
53+
- [配置 Playwright](/guide/browser/playwright)
54+
- [配置 WebdriverIO](/guide/browser/webdriverio)
5555

5656
::: tip
57-
To have a better type safety when using built-in providers, you should reference one of these types (for provider that you are using) in your [config file](/config/):
57+
为了在使用内置提供者时获得更好的类型安全性,我们应该在 [配置文件](/config/) 中引用以下类型之一(针对我们使用的提供者):
5858

5959
```ts
6060
/// <reference types="@vitest/browser/providers/playwright" />
6161
/// <reference types="@vitest/browser/providers/webdriverio" />
6262
```
6363
:::
6464

65-
In addition to that, you can also specify most of the [project options](/config/) (not marked with a <NonProjectOption /> icon) and some of the `browser` options like `browser.testerHtmlPath`.
65+
除此之外,我们还可以指定大多数 [项目选项](/config/)(未标记为 <NonProjectOption /> 图标的选项)和一些 `browser` 选项,例如 `browser.testerHtmlPath`
6666

6767
::: warning
68-
Every browser config inherits options from the root config:
68+
每个浏览器配置都从根配置继承选项:
6969

7070
```ts{3,9} [vitest.config.ts]
7171
export default defineConfig({
@@ -76,9 +76,9 @@ export default defineConfig({
7676
testerHtmlPath: './custom-path.html',
7777
instances: [
7878
{
79-
// will have both setup files: "root" and "browser"
79+
// 将同时具有 "root" "browser" 的设置文件
8080
setupFile: ['./browser-setup-file.js'],
81-
// implicitly has "testerHtmlPath" from the root config // [!code warning]
81+
// 隐式具有根配置中的 "testerHtmlPath" // [!code warning]
8282
// testerHtmlPath: './custom-path.html', // [!code warning]
8383
},
8484
],
@@ -87,12 +87,12 @@ export default defineConfig({
8787
})
8888
```
8989

90-
During development, Vitest supports only one [non-headless](#browser-headless) configuration. You can limit the headed project yourself by specifying `headless: false` in the config, or by providing the `--browser.headless=false` flag, or by filtering projects with `--project=chromium` flag.
90+
在开发过程中,Vitest 仅支持一个 [非无头](#browser-headless) 配置。我们可以通过在配置中指定 `headless: false`,或提供 `--browser.headless=false` 标志,或使用 `--project=chromium` 标志过滤项目来限制有头项目。
9191

92-
For more examples, refer to the ["Multiple Setups" guide](/guide/browser/multiple-setups).
92+
有关更多示例,请参阅 ["多设置" 指南](/guide/browser/multiple-setups)
9393
:::
9494

95-
List of available `browser` options:
95+
可用的 `browser` 选项列表:
9696

9797
- [`browser.headless`](#browser-headless)
9898
- [`browser.locators`](#browser-locators)
@@ -101,66 +101,66 @@ List of available `browser` options:
101101
- [`browser.screenshotDirectory`](#browser-screenshotdirectory)
102102
- [`browser.screenshotFailures`](#browser-screenshotfailures)
103103

104-
By default, Vitest creates an array with a single element which uses the [`browser.name`](#browser-name) field as a `browser`. Note that this behaviour will be removed with Vitest 4.
104+
默认情况下,Vitest 创建一个包含单个元素的数组,该元素使用 [`browser.name`](#browser-name) 字段作为 `browser`。请注意,此行为将在 Vitest 4 中移除。
105105

106-
Under the hood, Vitest transforms these instances into separate [test projects](/advanced/api/test-project) sharing a single Vite server for better caching performance.
106+
在底层,Vitest 将这些实例转换为共享单个 Vite 服务器的单独 [测试项目](/advanced/api/test-project),以获得更好的缓存性能。
107107

108-
## browser&#46;name <Badge type="danger">deprecated</Badge> {#browser-name}
108+
## browser&#46;name <Badge type="danger">已弃用</Badge> {#browser-name}
109109

110-
- **Type:** `string`
110+
- **类型:** `string`
111111
- **CLI:** `--browser=safari`
112112

113113
::: danger
114-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.instances`](#browser-instances) option instead.
114+
API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
115115
:::
116116

117-
Run all tests in a specific browser. Possible options in different providers:
117+
在特定浏览器中运行所有测试。不同提供者中的可能选项:
118118

119119
- `webdriverio`: `firefox`, `chrome`, `edge`, `safari`
120120
- `playwright`: `firefox`, `webkit`, `chromium`
121-
- custom: any string that will be passed to the provider
121+
- 自定义:任何将传递给提供者的字符串
122122

123123
## browser.headless
124124

125-
- **Type:** `boolean`
126-
- **Default:** `process.env.CI`
125+
- **类型:** `boolean`
126+
- **默认值:** `process.env.CI`
127127
- **CLI:** `--browser.headless`, `--browser.headless=false`
128128

129-
Run the browser in a `headless` mode. If you are running Vitest in CI, it will be enabled by default.
129+
`headless` 模式下运行浏览器。如果我们在 CI 中运行 Vitest,则默认启用此模式。
130130

131131
## browser.isolate
132132

133-
- **Type:** `boolean`
134-
- **Default:** `true`
133+
- **类型:** `boolean`
134+
- **默认值:** `true`
135135
- **CLI:** `--browser.isolate`, `--browser.isolate=false`
136136

137-
Run every test in a separate iframe.
137+
在单独的 iframe 中运行每个测试。
138138

139139
## browser.testerHtmlPath
140140

141-
- **Type:** `string`
141+
- **类型:** `string`
142142

143-
A path to the HTML entry point. Can be relative to the root of the project. This file will be processed with [`transformIndexHtml`](https://vite.dev/guide/api-plugin#transformindexhtml) hook.
143+
HTML 入口点的路径。可以是相对于项目根目录的路径。此文件将通过 [`transformIndexHtml`](https://vite.dev/guide/api-plugin#transformindexhtml) 钩子进行处理。
144144

145145
## browser.api
146146

147-
- **Type:** `number | { port?, strictPort?, host? }`
148-
- **Default:** `63315`
147+
- **类型:** `number | { port?, strictPort?, host? }`
148+
- **默认值:** `63315`
149149
- **CLI:** `--browser.api=63315`, `--browser.api.port=1234, --browser.api.host=example.com`
150150

151-
Configure options for Vite server that serves code in the browser. Does not affect [`test.api`](#api) option. By default, Vitest assigns port `63315` to avoid conflicts with the development server, allowing you to run both in parallel.
151+
配置为浏览器提供代码的 Vite 服务器的选项。不影响 [`test.api`](#api) 选项。默认情况下,Vitest 分配端口 `63315` 以避免与开发服务器冲突,允许我们同时运行两者。
152152

153-
## browser.provider <Badge type="warning">experimental</Badge> {#browser-provider}
153+
## browser.provider <Badge type="warning">实验性</Badge> {#browser-provider}
154154

155-
- **Type:** `'webdriverio' | 'playwright' | 'preview' | string`
156-
- **Default:** `'preview'`
155+
- **类型:** `'webdriverio' | 'playwright' | 'preview' | string`
156+
- **默认值:** `'preview'`
157157
- **CLI:** `--browser.provider=playwright`
158158

159-
::: danger ADVANCED API
160-
The 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.
159+
::: danger 高级 API
160+
提供者 API 是高度实验性的,可能会在补丁之间发生变化。如果我们只需要在浏览器中运行测试,请改用 [`browser.instances`](#browser-instances) 选项。
161161
:::
162162

163-
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:
163+
运行浏览器测试时使用的提供者路径。Vitest 提供了三个提供者,分别是 `preview`(默认)、`webdriverio` `playwright`。自定义提供者应使用 `default` 导出,并具有以下形状:
164164

165165
```ts
166166
export interface BrowserProvider {
@@ -173,22 +173,22 @@ export interface BrowserProvider {
173173
openPage: (sessionId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>
174174
getCDPSession?: (sessionId: string) => Promise<CDPSession>
175175
close: () => Awaitable<void>
176-
initialize(
176+
initialize: (
177177
ctx: TestProject,
178178
options: BrowserProviderInitializationOptions
179-
): Awaitable<void>
179+
) => Awaitable<void>
180180
}
181181
```
182182

183-
## browser.providerOptions <Badge type="danger">deprecated</Badge> {#browser-provideroptions}
183+
## browser.providerOptions <Badge type="danger">已弃用</Badge> {#browser-provideroptions}
184184

185-
- **Type:** `BrowserProviderOptions`
185+
- **类型:** `BrowserProviderOptions`
186186

187187
::: danger
188-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.instances`](#browser-instances) option instead.
188+
API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.instances`](#browser-instances) 选项。
189189
:::
190190

191-
Options that will be passed down to provider when calling `provider.initialize`.
191+
调用 `provider.initialize` 时传递给提供者的选项。
192192

193193
```ts
194194
import { defineConfig } from 'vitest/config'
@@ -207,7 +207,7 @@ export default defineConfig({
207207
```
208208

209209
::: tip
210-
To have a better type safety when using built-in providers, you should reference one of these types (for provider that you are using) in your [config file](/config/):
210+
为了在使用内置提供者时获得更好的类型安全性,我们应该在 [配置文件](/config/) 中引用以下类型之一(针对我们使用的提供者):
211211

212212
```ts
213213
/// <reference types="@vitest/browser/providers/playwright" />
@@ -217,78 +217,78 @@ To have a better type safety when using built-in providers, you should reference
217217

218218
## browser.ui
219219

220-
- **Type:** `boolean`
221-
- **Default:** `!isCI`
220+
- **类型:** `boolean`
221+
- **默认值:** `!isCI`
222222
- **CLI:** `--browser.ui=false`
223223

224-
Should Vitest UI be injected into the page. By default, injects UI iframe during development.
224+
是否应将 Vitest UI 注入页面。默认情况下,在开发期间注入 UI iframe
225225

226226
## browser.viewport
227227

228-
- **Type:** `{ width, height }`
229-
- **Default:** `414x896`
228+
- **类型:** `{ width, height }`
229+
- **默认值:** `414x896`
230230

231-
Default iframe's viewport.
231+
默认 iframe 的视口。
232232

233233
## browser.locators
234234

235-
Options for built-in [browser locators](/guide/browser/locators).
235+
内置 [浏览器定位器](/guide/browser/locators) 的选项。
236236

237237
### browser.locators.testIdAttribute
238238

239-
- **Type:** `string`
240-
- **Default:** `data-testid`
239+
- **类型:** `string`
240+
- **默认值:** `data-testid`
241241

242-
Attribute used to find elements with `getByTestId` locator.
242+
用于通过 `getByTestId` 定位器查找元素的属性。
243243

244244
## browser.screenshotDirectory
245245

246-
- **Type:** `string`
247-
- **Default:** `__snapshots__` in the test file directory
246+
- **类型:** `string`
247+
- **默认值:** 测试文件目录中的 `__snapshots__`
248248

249-
Path to the screenshots directory relative to the `root`.
249+
相对于 `root` 的屏幕截图目录路径。
250250

251251
## browser.screenshotFailures
252252

253-
- **Type:** `boolean`
254-
- **Default:** `!browser.ui`
253+
- **类型:** `boolean`
254+
- **默认值:** `!browser.ui`
255255

256-
Should Vitest take screenshots if the test fails.
256+
如果测试失败,Vitest 是否应截取屏幕截图。
257257

258258
## browser.orchestratorScripts
259259

260-
- **Type:** `BrowserScript[]`
261-
- **Default:** `[]`
260+
- **类型:** `BrowserScript[]`
261+
- **默认值:** `[]`
262262

263-
Custom scripts that should be injected into the orchestrator HTML before test iframes are initiated. This HTML document only sets up iframes and doesn't actually import your code.
263+
在测试 iframe 初始化之前应注入到编排器 HTML 中的自定义脚本。此 HTML 文档仅设置 iframe,并不实际导入我们的代码。
264264

265-
The script `src` and `content` will be processed by Vite plugins. Script should be provided in the following shape:
265+
脚本的 `src` `content` 将由 Vite 插件处理。脚本应提供以下形状:
266266

267267
```ts
268268
export interface BrowserScript {
269269
/**
270-
* If "content" is provided and type is "module", this will be its identifier.
270+
* 如果提供了 "content" 并且类型为 "module",则这将是其标识符。
271271
*
272-
* If you are using TypeScript, you can add `.ts` extension here for example.
272+
* 如果我们使用的是 TypeScript,可以在此处添加 `.ts` 扩展名。
273273
* @default `injected-${index}.js`
274274
*/
275275
id?: string
276276
/**
277-
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
277+
* 要注入的 JavaScript 内容。如果类型为 "module",则此字符串由 Vite 插件处理。
278278
*
279-
* You can use `id` to give Vite a hint about the file extension.
279+
* 我们可以使用 `id` Vite 提供文件扩展名的提示。
280280
*/
281281
content?: string
282282
/**
283-
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
283+
* 脚本的路径。此值由 Vite 解析,因此它可以是节点模块或文件路径。
284284
*/
285285
src?: string
286286
/**
287-
* If the script should be loaded asynchronously.
287+
* 脚本是否应异步加载。
288288
*/
289289
async?: boolean
290290
/**
291-
* Script type.
291+
* 脚本类型。
292292
* @default 'module'
293293
*/
294294
type?: string
@@ -297,31 +297,31 @@ export interface BrowserScript {
297297

298298
## browser.testerScripts
299299

300-
- **Type:** `BrowserScript[]`
301-
- **Default:** `[]`
300+
- **类型:** `BrowserScript[]`
301+
- **默认值:** `[]`
302302

303303
::: danger
304-
This API is deprecated an will be removed in Vitest 4. Please, use [`browser.testerHtmlPath`](#browser-testerhtmlpath) field instead.
304+
API 已弃用,并将在 Vitest 4 中移除。请改用 [`browser.testerHtmlPath`](#browser-testerhtmlpath) 字段。
305305
:::
306306

307-
Custom scripts that should be injected into the tester HTML before the tests environment is initiated. This is useful to inject polyfills required for Vitest browser implementation. It is recommended to use [`setupFiles`](#setupfiles) in almost all cases instead of this.
307+
在测试环境初始化之前应注入到测试器 HTML 中的自定义脚本。这对于注入 Vitest 浏览器实现所需的 polyfill 非常有用。在几乎所有情况下,建议使用 [`setupFiles`](#setupfiles) 代替此选项。
308308

309-
The script `src` and `content` will be processed by Vite plugins.
309+
脚本的 `src` `content` 将由 Vite 插件处理。
310310

311311
## browser.commands
312312

313-
- **Type:** `Record<string, BrowserCommand>`
314-
- **Default:** `{ readFile, writeFile, ... }`
313+
- **类型:** `Record<string, BrowserCommand>`
314+
- **默认值:** `{ readFile, writeFile, ... }`
315315

316-
Custom [commands](/guide/browser/commands) that can be imported during browser tests from `@vitest/browser/commands`.
316+
可以从 `@vitest/browser/commands` 导入的自定义 [命令](/guide/browser/commands)
317317

318318
## browser.connectTimeout
319319

320-
- **Type:** `number`
321-
- **Default:** `60_000`
320+
- **类型:** `number`
321+
- **默认值:** `60_000`
322322

323-
The timeout in milliseconds. If connection to the browser takes longer, the test suite will fail.
323+
超时时间(以毫秒为单位)。如果连接到浏览器的时间超过此时间,测试套件将失败。
324324

325325
::: info
326-
This is the time it should take for the browser to establish the WebSocket connection with the Vitest server. In normal circumstances, this timeout should never be reached.
326+
这是浏览器与 Vitest 服务器建立 WebSocket 连接所需的时间。在正常情况下,此超时不应被触发。
327327
:::

0 commit comments

Comments
 (0)