Skip to content

Commit 2e990ca

Browse files
committed
docs: update content
1 parent 161f205 commit 2e990ca

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

advanced/api/index.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Advanced API
33
---
44

5-
# Getting Started
5+
# 快速起步
66

77
::: warning
8-
This guide lists advanced APIs to run tests via a Node.js script. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
8+
本指南列出了通过 Node.js 脚本运行测试的高级 API。如果你只是想[运行测试](/guide/),你可能不需要这些内容。这些 API 主要用于库作者。
99
:::
1010

11-
You can import any method from the `vitest/node` entry-point.
11+
你可以从 `vitest/node` 入口点导入任何方法。
1212

1313
## startVitest
1414

@@ -22,7 +22,7 @@ function startVitest(
2222
): Promise<Vitest>
2323
```
2424

25-
You can start running Vitest tests using its Node API:
25+
你可以使用 Vitest Node API 开始运行测试:
2626

2727
```js
2828
import { startVitest } from 'vitest/node'
@@ -32,17 +32,17 @@ const vitest = await startVitest('test')
3232
await vitest.close()
3333
```
3434

35-
`startVitest` function returns [`Vitest`](/advanced/api/vitest) instance if tests can be started.
35+
`startVitest` 函数如果可以启动测试,将返回一个 [`Vitest`](/advanced/api/vitest) 实例。
3636

37-
If watch mode is not enabled, Vitest will call `close` method automatically.
37+
如果未启用监视模式,Vitest 将自动调用 `close` 方法。
3838

39-
If watch mode is enabled and the terminal supports TTY, Vitest will register console shortcuts.
39+
如果启用了监视模式且终端支持 TTYVitest 将注册控制台快捷键。
4040

41-
You can pass down a list of filters as a second argument. Vitest will run only tests that contain at least one of the passed-down strings in their file path.
41+
你可以将过滤器列表作为第二个参数传递。Vitest 将仅运行文件路径中包含至少一个传递字符串的测试。
4242

43-
Additionally, you can use the third argument to pass in CLI arguments, which will override any test config options. Alternatively, you can pass in the complete Vite config as the fourth argument, which will take precedence over any other user-defined options.
43+
此外,你可以使用第三个参数传递 CLI 参数,这些参数将覆盖任何测试配置选项。或者,你可以将完整的 Vite 配置作为第四个参数传递,这将优先于任何其他用户定义的选项。
4444

45-
After running the tests, you can get the results from the [`state.getTestModules`](/advanced/api/test-module) API:
45+
运行测试后,你可以从 [`state.getTestModules`](/advanced/api/test-module) API 获取结果:
4646

4747
```ts
4848
import type { TestModule } from 'vitest/node'
@@ -53,7 +53,7 @@ console.log(vitest.state.getTestModules()) // [TestModule]
5353
```
5454

5555
::: tip
56-
The ["Running Tests"](/advanced/guide/tests#startvitest) guide has a usage example.
56+
[“运行测试”](/advanced/guide/tests#startvitest) 指南中有使用示例。
5757
:::
5858

5959
## createVitest
@@ -67,7 +67,7 @@ function createVitest(
6767
): Promise<Vitest>
6868
```
6969

70-
You can create Vitest instance by using `createVitest` function. It returns the same [`Vitest`](/advanced/api/vitest) instance as `startVitest`, but it doesn't start tests and doesn't validate installed packages.
70+
你可以使用 `createVitest` 函数创建一个 Vitest 实例。它返回与 `startVitest` 相同的 [`Vitest`](/advanced/api/vitest) 实例,但不会启动测试也不会验证已安装的包。
7171

7272
```js
7373
import { createVitest } from 'vitest/node'
@@ -78,7 +78,7 @@ const vitest = await createVitest('test', {
7878
```
7979

8080
::: tip
81-
The ["Running Tests"](/advanced/guide/tests#createvitest) guide has a usage example.
81+
[“运行测试”](/advanced/guide/tests#createvitest) 指南中有使用示例。
8282
:::
8383

8484
## resolveConfig
@@ -93,7 +93,7 @@ function resolveConfig(
9393
}>
9494
```
9595

96-
This method resolves the config with custom parameters. If no parameters are given, the `root` will be `process.cwd()`.
96+
此方法使用自定义参数解析配置。如果没有提供参数,则 `root` 将为 `process.cwd()`
9797

9898
```ts
9999
import { resolveConfig } from 'vitest/node'
@@ -113,15 +113,15 @@ const { vitestConfig, viteConfig } = await resolveConfig({
113113
```
114114

115115
::: info
116-
Due to how Vite's `createServer` works, Vitest has to resolve the config during the plugin's `configResolve` hook. Therefore, this method is not actually used internally and is exposed exclusively as a public API.
116+
由于 Vite`createServer` 工作方式,Vitest 必须在插件的 `configResolve` 钩子中解析配置。因此,此方法实际上并未在内部使用,而是仅作为公共 API 暴露。
117117

118-
If you pass down the config to the `startVitest` or `createVitest` APIs, Vitest will still resolve the config again.
118+
如果你将配置传递给 `startVitest` `createVitest` APIVitest 仍然会重新解析配置。
119119
:::
120120

121121
::: warning
122-
The `resolveConfig` doesn't resolve the `workspace`. To resolve workspace configs, Vitest needs an established Vite server.
122+
`resolveConfig` 不会解析 `workspace`。要解析工作区配置,Vitest 需要一个已建立的 Vite 服务器。
123123

124-
Also note that `viteConfig.test` will not be fully resolved. If you need Vitest config, use `vitestConfig` instead.
124+
另外请注意,`viteConfig.test` 不会被完全解析。如果你需要 Vitest 配置,请使用 `vitestConfig` 代替。
125125
:::
126126

127127
## parseCLI
@@ -133,7 +133,7 @@ function parseCLI(argv: string | string[], config: CliParseOptions = {}): {
133133
}
134134
```
135135

136-
You can use this method to parse CLI arguments. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
136+
你可以使用此方法来解析 CLI 参数。它接受一个字符串(其中参数以单个空格分隔)或一个与 Vitest CLI 使用的格式相同的 CLI 参数字符串数组。它返回一个过滤器和 `options`,你可以在稍后传递给 `createVitest` `startVitest` 方法。
137137

138138
```ts
139139
import { parseCLI } from 'vitest/node'

0 commit comments

Comments
 (0)