Skip to content

Commit 01f4ec6

Browse files
committed
docs: update content
1 parent 02f514e commit 01f4ec6

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

api/index.md

+33-33
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ myTest('add item', ({ todos }) => {
117117
import { assert, test } from 'vitest'
118118

119119
test.skip('skipped test', () => {
120-
// Test skipped, no error
120+
// 测试被跳过,没有错误。
121121
assert.equal(Math.sqrt(4), 3)
122122
})
123123
```
@@ -129,7 +129,7 @@ import { assert, test } from 'vitest'
129129

130130
test('skipped test', (context) => {
131131
context.skip()
132-
// Test skipped, no error
132+
// 测试被跳过,没有错误。
133133
assert.equal(Math.sqrt(4), 3)
134134
})
135135
```
@@ -147,7 +147,7 @@ import { assert, test } from 'vitest'
147147
const isDev = process.env.NODE_ENV === 'development'
148148

149149
test.skipIf(isDev)('prod only test', () => {
150-
// this test only runs in production
150+
// 此测试仅在生产环境中运行。
151151
})
152152
```
153153

@@ -168,7 +168,7 @@ import { assert, test } from 'vitest'
168168
const isDev = process.env.NODE_ENV === 'development'
169169

170170
test.runIf(isDev)('dev only test', () => {
171-
// this test only runs in development
171+
// 此测试仅在开发环境中运行。
172172
})
173173
```
174174

@@ -189,7 +189,7 @@ test.runIf(isDev)('dev only test', () => {
189189
import { assert, test } from 'vitest'
190190

191191
test.only('test', () => {
192-
// Only this test (and others marked with only) are run
192+
// 只有此测试(以及其他标记为 `only` 的测试)会被运行。
193193
assert.equal(Math.sqrt(4), 2)
194194
})
195195
```
@@ -212,7 +212,7 @@ test.only('test', () => {
212212
```ts
213213
import { describe, test } from 'vitest'
214214

215-
// The two tests marked with concurrent will be run in parallel
215+
// 标记为 `concurrent` 的两个测试将并行运行。
216216
describe('suite', () => {
217217
test('serial test', async () => {
218218
/* ... */
@@ -259,7 +259,7 @@ test.concurrent('test 2', async ({ expect }) => {
259259
```ts
260260
import { describe, test } from 'vitest'
261261

262-
// with config option { sequence: { concurrent: true } }
262+
// 使用配置选项 `{ sequence: { concurrent: true } }`
263263
test('concurrent test 1', async () => {
264264
/* ... */
265265
})
@@ -274,7 +274,7 @@ test.sequential('sequential test 2', async () => {
274274
/* ... */
275275
})
276276

277-
// within concurrent suite
277+
// 在并发套件中
278278
describe.concurrent('suite', () => {
279279
test('concurrent test 1', async () => {
280280
/* ... */
@@ -300,7 +300,7 @@ describe.concurrent('suite', () => {
300300
使用 `test.todo` 来存根测试,以便稍后实施。测试报告中将显示一个条目,以便知道还有多少测试需要执行。
301301

302302
```ts
303-
// An entry will be shown in the report for this test
303+
// 此测试将在报告中显示一个条目。
304304
test.todo('unimplemented test')
305305
```
306306

@@ -358,7 +358,7 @@ test.each([
358358
expect(a + b).toBe(expected)
359359
})
360360

361-
// this will return
361+
// 这将返回
362362
// ✓ add(1, 1) -> 2
363363
// ✓ add(1, 2) -> 3
364364
// ✓ add(2, 1) -> 3
@@ -375,7 +375,7 @@ test.each([
375375
expect(a + b).toBe(expected)
376376
})
377377

378-
// this will return
378+
// 这将返回
379379
// ✓ add(1, 1) -> 2
380380
// ✓ add(1, 2) -> 3
381381
// ✓ add(2, 1) -> 3
@@ -395,7 +395,7 @@ test.each`
395395
expect(a.val + b).toBe(expected)
396396
})
397397

398-
// this will return
398+
// 这将返回
399399
// ✓ add(1, b) -> 1b
400400
// ✓ add(2, b) -> 2b
401401
// ✓ add(3, b) -> 3b
@@ -438,7 +438,7 @@ Vitest 使用 chai `format` 方法处理 `$values`。如果数值太短,可以
438438
其他非数组情况(包括模板字符串的使用)完全相同。
439439

440440
```ts
441-
// `each` spreads array case
441+
// `each` 展开数组用例
442442
test.each([
443443
[1, 1, 2],
444444
[1, 2, 3],
@@ -447,7 +447,7 @@ test.each([
447447
expect(a + b).toBe(expected)
448448
})
449449

450-
// `for` doesn't spread array case
450+
// `for` 不会展开数组用例
451451
test.for([
452452
[1, 1, 2],
453453
[1, 2, 3],
@@ -837,7 +837,7 @@ import { assert, describe, test } from 'vitest'
837837
const isDev = process.env.NODE_ENV === 'development'
838838

839839
describe.runIf(isDev)('dev only test suite', () => {
840-
// this test suite only runs in development
840+
// 此测试套件仅在开发环境中运行。
841841
})
842842
```
843843

@@ -854,15 +854,15 @@ describe.runIf(isDev)('dev only test suite', () => {
854854
```ts
855855
import { assert, describe, test } from 'vitest'
856856

857-
// Only this suite (and others marked with only) are run
857+
// 只有此测试套件(以及其他标记为 `only` 的测试套件)会被运行。
858858
describe.only('suite', () => {
859859
test('sqrt', () => {
860860
assert.equal(Math.sqrt(4), 3)
861861
})
862862
})
863863

864864
describe('other suite', () => {
865-
// ... will be skipped
865+
// ... 将被跳过
866866
})
867867
```
868868

@@ -885,7 +885,7 @@ In order to do that run `vitest` with specific file containing the tests in ques
885885
```ts
886886
import { describe, test } from 'vitest'
887887

888-
// All suites and tests within this suite will be run in parallel
888+
// 此测试套件中的所有测试套件和测试将并行运行。
889889
describe.concurrent('suite', () => {
890890
test('concurrent test 1', async () => {
891891
/* ... */
@@ -967,25 +967,25 @@ Vitest 通过 CLI 标志 [`--sequence.shuffle`](/guide/cli) 或配置选项 [`se
967967
```ts
968968
import { describe, test } from 'vitest'
969969

970-
// or describe('suite', { shuffle: true }, ...)
970+
// 或 `describe('suite', { shuffle: true }, ...)`
971971
describe.shuffle('suite', () => {
972972
test('random test 1', async () => { /* ... */ })
973973
test('random test 2', async () => { /* ... */ })
974974
test('random test 3', async () => { /* ... */ })
975975

976-
// `shuffle` is inherited
976+
// `shuffle` 是继承的
977977
describe('still random', () => {
978978
test('random 4.1', async () => { /* ... */ })
979979
test('random 4.2', async () => { /* ... */ })
980980
})
981981

982-
// disable shuffle inside
982+
// 禁用内部的 shuffle
983983
describe('not random', { shuffle: false }, () => {
984984
test('in order 5.1', async () => { /* ... */ })
985985
test('in order 5.2', async () => { /* ... */ })
986986
})
987987
})
988-
// order depends on sequence.seed option in config (Date.now() by default)
988+
// 顺序取决于配置中的 `sequence.seed` 选项(默认为 `Date.now()`)
989989
```
990990

991991
`.skip``.only``.todo`适用于随机测试套件。
@@ -1001,7 +1001,7 @@ describe.shuffle('suite', () => {
10011001
使用 `describe.todo` 来暂存待以后实施的套件。测试报告中会显示一个条目,这样就能知道还有多少测试需要执行。
10021002

10031003
```ts
1004-
// An entry will be shown in the report for this suite
1004+
// 此测试套件将在报告中显示一个条目。
10051005
describe.todo('unimplemented suite')
10061006
```
10071007

@@ -1072,7 +1072,7 @@ The difference from `describe.each` is how array case is provided in the argumen
10721072
Other non array case (including template string usage) works exactly same.
10731073

10741074
```ts
1075-
// `each` spreads array case
1075+
// `each` 展开数组用例
10761076
describe.each([
10771077
[1, 1, 2],
10781078
[1, 2, 3],
@@ -1083,7 +1083,7 @@ describe.each([
10831083
})
10841084
})
10851085

1086-
// `for` doesn't spread array case
1086+
// `for` 不会展开数组用例
10871087
describe.for([
10881088
[1, 1, 2],
10891089
[1, 2, 3],
@@ -1113,7 +1113,7 @@ describe.for([
11131113
import { beforeEach } from 'vitest'
11141114

11151115
beforeEach(async () => {
1116-
// Clear mocks and add some testing data after before each test run
1116+
// 在每个测试运行之前清除模拟并添加一些测试数据。
11171117
await stopMocking()
11181118
await addUser({ name: 'John' })
11191119
})
@@ -1127,10 +1127,10 @@ beforeEach(async () => {
11271127
import { beforeEach } from 'vitest'
11281128

11291129
beforeEach(async () => {
1130-
// called once before each test run
1130+
// 在每个测试运行之前调用一次。
11311131
await prepareSomething()
11321132

1133-
// clean up function, called once after each test run
1133+
// 清理函数,在每个测试运行之后调用一次。
11341134
return async () => {
11351135
await resetSomething()
11361136
}
@@ -1150,7 +1150,7 @@ beforeEach(async () => {
11501150
import { afterEach } from 'vitest'
11511151

11521152
afterEach(async () => {
1153-
await clearTestingData() // clear testing data after each test run
1153+
await clearTestingData() // 在每个测试运行之后清除测试数据。
11541154
})
11551155
```
11561156

@@ -1173,7 +1173,7 @@ Vitest 在 1.3.0 新增 [`onTestFinished`](#ontestfinished)。你可以在测试
11731173
import { beforeAll } from 'vitest'
11741174

11751175
beforeAll(async () => {
1176-
await startMocking() // called once before all tests run
1176+
await startMocking() // 在所有测试运行之前调用一次。
11771177
})
11781178
```
11791179

@@ -1185,10 +1185,10 @@ beforeAll(async () => {
11851185
import { beforeAll } from 'vitest'
11861186

11871187
beforeAll(async () => {
1188-
// called once before all tests run
1188+
// 在所有测试运行之前调用一次。
11891189
await startMocking()
11901190

1191-
// clean up function, called once after all tests run
1191+
// 清理函数,在所有测试运行之后调用一次。
11921192
return async () => {
11931193
await stopMocking()
11941194
}
@@ -1208,7 +1208,7 @@ beforeAll(async () => {
12081208
import { afterAll } from 'vitest'
12091209

12101210
afterAll(async () => {
1211-
await stopMocking() // this method is called after all tests run
1211+
await stopMocking() // 此方法在所有测试运行之后被调用。
12121212
})
12131213
```
12141214

config/index.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default defineConfig({
140140

141141
- **Type:** `string`
142142

143-
Assign a custom name to the test project or Vitest process. The name will be visible in the CLI and available in the Node.js API via [`project.name`](/advanced/api/test-project#name).
143+
为测试项目或 Vitest 进程分配一个自定义名称。该名称将在 CLI 中可见,并且可以通过 Node.js API 中的 [`project.name`](/advanced/api/test-project#name) 获取。
144144

145145
### server {#server}
146146

@@ -407,11 +407,11 @@ export default defineConfig({
407407
例如:
408408

409409
```sh
410-
# save main branch's result
410+
# 保存主分支的结果。
411411
git checkout main
412412
vitest bench --outputJson main.json
413413

414-
# change a branch and compare against main
414+
# 切换到另一个分支并与主分支进行比较。
415415
git checkout feature
416416
vitest bench --compare main.json
417417
```
@@ -547,7 +547,7 @@ export default <Environment>{
547547
// custom setup
548548
return {
549549
teardown() {
550-
// called after all tests with this env have been run
550+
// 在所有使用此环境的测试运行完毕后调用。
551551
},
552552
}
553553
},
@@ -613,9 +613,9 @@ import { defineConfig } from 'vitest/config'
613613
export default defineConfig({
614614
test: {
615615
environmentMatchGlobs: [
616-
// all tests in tests/dom will run in jsdom
616+
// `tests/dom` 目录中的所有测试将在 jsdom 中运行。
617617
['tests/dom/**', 'jsdom'],
618-
// all tests in tests/ with .edge.test.ts will run in edge-runtime
618+
// `tests/` 目录中所有以 `.edge.test.ts` 结尾的测试将在 edge-runtime 中运行。
619619
['**/*.edge.test.ts', 'edge-runtime'],
620620
// ...
621621
],

guide/browser/commands.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ test('custom command works correctly', async () => {
108108
expect(result).toEqual({ someValue: true })
109109
})
110110

111-
// if you are using TypeScript, you can augment the module
111+
// 如果你使用 TypeScript,你可以扩展模块。
112112
declare module '@vitest/browser/context' {
113113
interface BrowserCommands {
114114
myCustomCommand: (arg1: string, arg2: string) => Promise<{
@@ -142,7 +142,7 @@ export const myCommand: BrowserCommand<[string, number]> = async (
142142
if (ctx.provider.name === 'playwright') {
143143
const element = await ctx.iframe.findByRole('alert')
144144
const screenshot = await element.screenshot()
145-
// do something with the screenshot
145+
// 对截图进行一些操作。
146146
return difference
147147
}
148148
}

0 commit comments

Comments
 (0)