You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/):
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`.
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.
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.
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),以获得更好的缓存性能。
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)钩子进行处理。
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`以避免与开发服务器冲突,允许我们同时运行两者。
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)选项。
161
161
:::
162
162
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:
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)选项。
189
189
:::
190
190
191
-
Options that will be passed down to provider when calling `provider.initialize`.
191
+
调用 `provider.initialize` 时传递给提供者的选项。
192
192
193
193
```ts
194
194
import { defineConfig } from'vitest/config'
@@ -207,7 +207,7 @@ export default defineConfig({
207
207
```
208
208
209
209
::: 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/):
@@ -217,78 +217,78 @@ To have a better type safety when using built-in providers, you should reference
217
217
218
218
## browser.ui
219
219
220
-
-**Type:**`boolean`
221
-
-**Default:**`!isCI`
220
+
-**类型:**`boolean`
221
+
-**默认值:**`!isCI`
222
222
-**CLI:**`--browser.ui=false`
223
223
224
-
Should Vitest UI be injected into the page. By default, injects UI iframe during development.
224
+
是否应将 Vitest UI 注入页面。默认情况下,在开发期间注入 UI iframe。
225
225
226
226
## browser.viewport
227
227
228
-
-**Type:**`{ width, height }`
229
-
-**Default:**`414x896`
228
+
-**类型:**`{ width, height }`
229
+
-**默认值:**`414x896`
230
230
231
-
Default iframe's viewport.
231
+
默认 iframe 的视口。
232
232
233
233
## browser.locators
234
234
235
-
Options for built-in [browser locators](/guide/browser/locators).
235
+
内置 [浏览器定位器](/guide/browser/locators) 的选项。
236
236
237
237
### browser.locators.testIdAttribute
238
238
239
-
-**Type:**`string`
240
-
-**Default:**`data-testid`
239
+
-**类型:**`string`
240
+
-**默认值:**`data-testid`
241
241
242
-
Attribute used to find elements with `getByTestId`locator.
242
+
用于通过 `getByTestId`定位器查找元素的属性。
243
243
244
244
## browser.screenshotDirectory
245
245
246
-
-**Type:**`string`
247
-
-**Default:**`__snapshots__` in the test file directory
246
+
-**类型:**`string`
247
+
-**默认值:**测试文件目录中的 `__snapshots__`
248
248
249
-
Path to the screenshots directory relative to the `root`.
249
+
相对于 `root` 的屏幕截图目录路径。
250
250
251
251
## browser.screenshotFailures
252
252
253
-
-**Type:**`boolean`
254
-
-**Default:**`!browser.ui`
253
+
-**类型:**`boolean`
254
+
-**默认值:**`!browser.ui`
255
255
256
-
Should Vitest take screenshots if the test fails.
256
+
如果测试失败,Vitest 是否应截取屏幕截图。
257
257
258
258
## browser.orchestratorScripts
259
259
260
-
-**Type:**`BrowserScript[]`
261
-
-**Default:**`[]`
260
+
-**类型:**`BrowserScript[]`
261
+
-**默认值:**`[]`
262
262
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,并不实际导入我们的代码。
264
264
265
-
The script `src`and`content`will be processed by Vite plugins. Script should be provided in the following shape:
265
+
脚本的 `src`和`content`将由 Vite 插件处理。脚本应提供以下形状:
266
266
267
267
```ts
268
268
exportinterfaceBrowserScript {
269
269
/**
270
-
* If "content" is provided and type is "module", this will be its identifier.
270
+
* 如果提供了 "content" 并且类型为 "module",则这将是其标识符。
271
271
*
272
-
* If you are using TypeScript, you can add `.ts` extension here for example.
272
+
* 如果我们使用的是 TypeScript,可以在此处添加 `.ts` 扩展名。
273
273
* @default`injected-${index}.js`
274
274
*/
275
275
id?:string
276
276
/**
277
-
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
277
+
* 要注入的 JavaScript 内容。如果类型为 "module",则此字符串由 Vite 插件处理。
278
278
*
279
-
* You can use `id` to give Vite a hint about the file extension.
279
+
* 我们可以使用 `id` 为 Vite 提供文件扩展名的提示。
280
280
*/
281
281
content?:string
282
282
/**
283
-
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
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)字段。
305
305
:::
306
306
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)代替此选项。
308
308
309
-
The script `src`and`content`will be processed by Vite plugins.
309
+
脚本的 `src`和`content`将由 Vite 插件处理。
310
310
311
311
## browser.commands
312
312
313
-
-**Type:**`Record<string, BrowserCommand>`
314
-
-**Default:**`{ readFile, writeFile, ... }`
313
+
-**类型:**`Record<string, BrowserCommand>`
314
+
-**默认值:**`{ readFile, writeFile, ... }`
315
315
316
-
Custom [commands](/guide/browser/commands) that can be imported during browser tests from `@vitest/browser/commands`.
The timeout in milliseconds. If connection to the browser takes longer, the test suite will fail.
323
+
超时时间(以毫秒为单位)。如果连接到浏览器的时间超过此时间,测试套件将失败。
324
324
325
325
::: 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.
0 commit comments