Skip to content

Commit f20b137

Browse files
[autofix.ci] apply automated fixes
1 parent f957b6c commit f20b137

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

advanced/api/test-module.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
`TestModule` 实例始终具有一个 `type` 属性,其值为 `module`。你可以使用它来区分不同的任务类型:
66

77
```ts
8-
if (task.type === "module") {
9-
task; // TestModule
8+
if (task.type === 'module') {
9+
task // TestModule
1010
}
1111
```
1212

@@ -19,50 +19,50 @@ if (task.type === "module") {
1919
这通常是一个绝对的 Unix 文件路径(即使在 Windows 上也是如此)。如果文件不在磁盘上,它可以是一个虚拟 ID。此值对应于 Vite 的 `ModuleGraph` ID。
2020

2121
```ts
22-
"C:/Users/Documents/project/example.test.ts"; //
23-
"/Users/mac/project/example.test.ts"; //
24-
"C:\\Users\\Documents\\project\\example.test.ts"; //
22+
'C:/Users/Documents/project/example.test.ts' //
23+
'/Users/mac/project/example.test.ts' //
24+
'C:\\Users\\Documents\\project\\example.test.ts' //
2525
```
2626

2727
## relativeModuleId
2828

2929
相对于项目的模块 ID。这与已弃用 API 中的 `task.name` 相同。
3030

3131
```ts
32-
"project/example.test.ts"; //
33-
"example.test.ts"; //
34-
"project\\example.test.ts"; //
32+
'project/example.test.ts' //
33+
'example.test.ts' //
34+
'project\\example.test.ts' //
3535
```
3636

3737
## state
3838

3939
```ts
40-
function state(): TestModuleState;
40+
function state(): TestModuleState
4141
```
4242

4343
与 [`testSuite.state()`](/advanced/api/test-suite#state) 的工作方式相同,但如果模块尚未执行,还可以返回 `queued`
4444

4545
## meta <Version>3.1.0</Version> {#meta}
4646

4747
```ts
48-
function meta(): TaskMeta;
48+
function meta(): TaskMeta
4949
```
5050

5151
在模块执行或收集过程中附加到模块的自定义[元数据](/advanced/metadata)。在测试运行期间,可以通过向 `task.meta` 对象分配属性来附加 meta
5252

5353
```ts {5,10}
54-
import { test } from "vitest";
54+
import { test } from 'vitest'
5555
56-
describe("the validation works correctly", (task) => {
56+
describe('the validation works correctly', (task) => {
5757
// 在收集阶段分配 "decorated"
58-
task.file.meta.decorated = false;
58+
task.file.meta.decorated = false
5959
60-
test("some test", ({ task }) => {
60+
test('some test', ({ task }) => {
6161
// 在测试运行期间分配 "decorated",它将可用
6262
// 仅在 onTestCaseReady 钩子中
63-
task.file.meta.decorated = false;
64-
});
65-
});
63+
task.file.meta.decorated = false
64+
})
65+
})
6666
```
6767

6868
:::tip
@@ -72,7 +72,7 @@ describe("the validation works correctly", (task) => {
7272
## diagnostic
7373

7474
```ts
75-
function diagnostic(): ModuleDiagnostic;
75+
function diagnostic(): ModuleDiagnostic
7676
```
7777

7878
关于模块的有用信息,例如持续时间、内存使用等。如果模块尚未执行,所有诊断值将返回 `0`
@@ -82,41 +82,41 @@ interface ModuleDiagnostic {
8282
/**
8383
* 导入和初始化环境所需的时间。
8484
*/
85-
readonly environmentSetupDuration: number;
85+
readonly environmentSetupDuration: number
8686
/**
8787
* Vitest 设置测试运行环境(运行器、模拟等)所需的时间。
8888
*/
89-
readonly prepareDuration: number;
89+
readonly prepareDuration: number
9090
/**
9191
* 导入测试模块所需的时间。
9292
* 这包括导入模块中的所有内容以及执行套件回调函数。
9393
*/
94-
readonly collectDuration: number;
94+
readonly collectDuration: number
9595
/**
9696
* 导入设置模块所需的时间。
9797
*/
98-
readonly setupDuration: number;
98+
readonly setupDuration: number
9999
/**
100100
* 模块中所有测试和钩子函数的累计持续时间。
101101
*/
102-
readonly duration: number;
102+
readonly duration: number
103103
/**
104104
* 模块使用的内存量(以字节为单位)。
105105
* 此值仅在使用 `logHeapUsage` 标志执行测试时才可用。
106106
*/
107-
readonly heap: number | undefined;
107+
readonly heap: number | undefined
108108
/**
109109
* Vitest处理的每个非外部化依赖项的导入时间。
110110
*/
111-
readonly importDurations: Record<string, ImportDuration>;
111+
readonly importDurations: Record<string, ImportDuration>
112112
}
113113
114114
/** 导入和执行非外部化文件所花费的时间。 */
115115
interface ImportDuration {
116116
/** 导入和执行文件本身所花费的时间,不包括该文件所依赖的所有非外部化导入。 */
117-
selfTime: number;
117+
selfTime: number
118118
119119
/** 导入和执行文件及其所有导入项所花费的时间。 */
120-
totalTime: number;
120+
totalTime: number
121121
}
122122
```

guide/environment.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,45 @@ Vitest 并不将 `browser` 视作一种测试环境。如果你想让部分测
3232
```ts
3333
// @vitest-environment jsdom
3434

35-
import { expect, test } from "vitest";
35+
import { expect, test } from 'vitest'
3636

37-
test("test", () => {
38-
expect(typeof window).not.toBe("undefined");
39-
});
37+
test('test', () => {
38+
expect(typeof window).not.toBe('undefined')
39+
})
4040
```
4141

4242
## 自定义环境 {#custom-environment}
4343

4444
你可以创建自己的包来扩展 Vitest 环境。为此,请创建一个名为 `vitest-environment-${name}` 的包,或者指定一个有效的 JS/TS 文件路径。该包应该导出一个形状为 `Environment` 的对象。
4545

4646
```ts
47-
import type { Environment } from "vitest/environments";
47+
import type { Environment } from 'vitest/environments'
4848

4949
export default <Environment>{
50-
name: "custom",
51-
viteEnvironment: "ssr",
50+
name: 'custom',
51+
viteEnvironment: 'ssr',
5252
// optional - only if you support "experimental-vm" pool
5353
async setupVM() {
54-
const vm = await import("node:vm");
55-
const context = vm.createContext();
54+
const vm = await import('node:vm')
55+
const context = vm.createContext()
5656
return {
5757
getVmContext() {
58-
return context;
58+
return context
5959
},
6060
teardown() {
6161
// 在所有使用此环境的测试运行完毕后调用
6262
},
63-
};
63+
}
6464
},
6565
setup() {
6666
// 自定义设置
6767
return {
6868
teardown() {
6969
// 在所有使用此环境的测试运行完毕后调用
7070
},
71-
};
71+
}
7272
},
73-
};
73+
}
7474
```
7575

7676
::: warning
@@ -80,30 +80,30 @@ Vitest 要求环境对象显式提供 `viteEnvironment` 字段(若省略则取
8080
你还可以通过 `vitest/environments` 访问默认的 Vitest 环境:
8181

8282
```ts
83-
import { builtinEnvironments, populateGlobal } from "vitest/environments";
83+
import { builtinEnvironments, populateGlobal } from 'vitest/environments'
8484

85-
console.log(builtinEnvironments); // { jsdom, happy-dom, node, edge-runtime }
85+
console.log(builtinEnvironments) // { jsdom, happy-dom, node, edge-runtime }
8686
```
8787

8888
Vitest 还提供了 `populateGlobal` 实用函数,可用于将属性从对象移动到全局命名空间:
8989

9090
```ts
9191
interface PopulateOptions {
9292
// 非类函数是否应该绑定到全局命名空间
93-
bindFunctions?: boolean;
93+
bindFunctions?: boolean
9494
}
9595

9696
interface PopulateResult {
9797
// 所有被复制的键的列表,即使原始对象上不存在该值
98-
keys: Set<string>;
98+
keys: Set<string>
9999
// 可能已被键覆盖的原始对象的映射
100100
// 你可以在 `teardown` 函数中返回这些值
101-
originals: Map<string | symbol, any>;
101+
originals: Map<string | symbol, any>
102102
}
103103

104104
export function populateGlobal(
105105
global: any,
106106
original: any,
107107
options: PopulateOptions
108-
): PopulateResult;
108+
): PopulateResult
109109
```

0 commit comments

Comments
 (0)