Skip to content

Commit 9cc6c56

Browse files
authored
Merge pull request #790 from lxKylin/env-1
docs: update env & test-module
2 parents 5fa1b37 + f20b137 commit 9cc6c56

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

advanced/api/test-module.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (task.type === 'module') {
2626

2727
## relativeModuleId
2828

29-
Module id relative to the project. This is the same as `task.name` in the deprecated API.
29+
相对于项目的模块 ID。这与已弃用 API 中的 `task.name` 相同。
3030

3131
```ts
3232
'project/example.test.ts' //
@@ -54,12 +54,12 @@ function meta(): TaskMeta
5454
import { test } from 'vitest'
5555
5656
describe('the validation works correctly', (task) => {
57-
// assign "decorated" during collection
57+
// 在收集阶段分配 "decorated"
5858
task.file.meta.decorated = false
5959
6060
test('some test', ({ task }) => {
61-
// assign "decorated" during test run, it will be available
62-
// only in onTestCaseReady hook
61+
// 在测试运行期间分配 "decorated",它将可用
62+
// 仅在 onTestCaseReady 钩子中
6363
task.file.meta.decorated = false
6464
})
6565
})
@@ -80,43 +80,43 @@ function diagnostic(): ModuleDiagnostic
8080
```ts
8181
interface ModuleDiagnostic {
8282
/**
83-
* The time it takes to import and initiate an environment.
83+
* 导入和初始化环境所需的时间。
8484
*/
8585
readonly environmentSetupDuration: number
8686
/**
87-
* The time it takes Vitest to setup test harness (runner, mocks, etc.).
87+
* Vitest 设置测试运行环境(运行器、模拟等)所需的时间。
8888
*/
8989
readonly prepareDuration: number
9090
/**
91-
* The time it takes to import the test module.
92-
* This includes importing everything in the module and executing suite callbacks.
91+
* 导入测试模块所需的时间。
92+
* 这包括导入模块中的所有内容以及执行套件回调函数。
9393
*/
9494
readonly collectDuration: number
9595
/**
96-
* The time it takes to import the setup module.
96+
* 导入设置模块所需的时间。
9797
*/
9898
readonly setupDuration: number
9999
/**
100-
* Accumulated duration of all tests and hooks in the module.
100+
* 模块中所有测试和钩子函数的累计持续时间。
101101
*/
102102
readonly duration: number
103103
/**
104-
* The amount of memory used by the module in bytes.
105-
* This value is only available if the test was executed with `logHeapUsage` flag.
104+
* 模块使用的内存量(以字节为单位)。
105+
* 此值仅在使用 `logHeapUsage` 标志执行测试时才可用。
106106
*/
107107
readonly heap: number | undefined
108108
/**
109-
* The time spent importing every non-externalized dependency that Vitest has processed.
109+
* Vitest处理的每个非外部化依赖项的导入时间。
110110
*/
111111
readonly importDurations: Record<string, ImportDuration>
112112
}
113113
114-
/** The time spent importing & executing a non-externalized file. */
114+
/** 导入和执行非外部化文件所花费的时间。 */
115115
interface ImportDuration {
116-
/** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
116+
/** 导入和执行文件本身所花费的时间,不包括该文件所依赖的所有非外部化导入。 */
117117
selfTime: number
118118
119-
/** The time spent importing & executing the file and all its imports. */
119+
/** 导入和执行文件及其所有导入项所花费的时间。 */
120120
totalTime: number
121121
}
122122
```

guide/environment.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Vitest 提供 [`environment`](/config/#environment) 选项以在特定环境中
1616
::: info
1717
当使用 `jsdom``happy-dom` 环境时,Vitest 在导入 [CSS](https://vitejs.dev/guide/features.html#css)[资源文件](https://vitejs.dev/guide/features.html#static-assets) 时遵循与 Vite 相同的规则。如果在导入外部依赖时出现 `unknown extension .css` 错误,则需要通过将所有相关包添加到 [`server.deps.inline`](/config/#server-deps-inline) 中,手动内联整个导入链。例如,在以下导入链中:`源代码 -> package-1 -> package-2 -> package-3`,如果错误发生在 `package-3`,你需要将这三个包都添加到 `server.deps.inline` 中。
1818

19-
外部依赖中的CSS和资源文件的 `require` 调用会自动解析。
19+
外部依赖中的 CSS 和资源文件的 `require` 调用会自动解析。
2020
:::
2121

2222
::: warning
@@ -58,15 +58,15 @@ export default <Environment>{
5858
return context
5959
},
6060
teardown() {
61-
// called after all tests with this env have been run
61+
// 在所有使用此环境的测试运行完毕后调用
6262
},
6363
}
6464
},
6565
setup() {
66-
// custom setup
66+
// 自定义设置
6767
return {
6868
teardown() {
69-
// called after all tests with this env have been run
69+
// 在所有使用此环境的测试运行完毕后调用
7070
},
7171
}
7272
},
@@ -89,15 +89,15 @@ Vitest 还提供了 `populateGlobal` 实用函数,可用于将属性从对象
8989

9090
```ts
9191
interface PopulateOptions {
92-
// should non-class functions be bind to the global namespace
92+
// 非类函数是否应该绑定到全局命名空间
9393
bindFunctions?: boolean
9494
}
9595

9696
interface PopulateResult {
97-
// a list of all keys that were copied, even if value doesn't exist on original object
97+
// 所有被复制的键的列表,即使原始对象上不存在该值
9898
keys: Set<string>
99-
// a map of original object that might have been overridden with keys
100-
// you can return these values inside `teardown` function
99+
// 可能已被键覆盖的原始对象的映射
100+
// 你可以在 `teardown` 函数中返回这些值
101101
originals: Map<string | symbol, any>
102102
}
103103

0 commit comments

Comments
 (0)