Skip to content

Commit d961639

Browse files
authored
docs: some broken problems
- [指南/调试](https://cn.vitest.dev/guide/debugging.html#intellij-idea) 尚未翻译的表头 - [expect](https://cn.vitest.dev/api/expect.html) 尚未翻译的注释 - [自定义运行池](https://cn.vitest.dev/advanced/pool.html) 更新`自定义池`为`自定义运行池`、`执行池`为`运行池` - [高级API](https://cn.vitest.dev/advanced/api/)未翻译的菜单
1 parent a8706f1 commit d961639

File tree

7 files changed

+133
-133
lines changed

7 files changed

+133
-133
lines changed

advanced/api/vitest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function setGlobalTestNamePattern(pattern: string | RegExp): void
354354
function getGlobalTestNamePattern(): RegExp | undefined
355355
```
356356

357-
Returns the regexp used for the global test name pattern.
357+
返回用于全局测试名称模式的正则表达式。
358358

359359
## resetGlobalTestNamePattern
360360

advanced/pool.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Custom Pool
1+
# 自定义运行池
22

33
::: warning
44
这是一个高级且非常底层的 API。如果你只是想 [运行测试](/guide/),你可能不需要这个。它主要由库作者使用。
@@ -12,14 +12,14 @@ Vitest 在默认情况下以多种方式运行测试:
1212
- `browser` 使用浏览器提供程序运行测试
1313
- `typescript` 在测试中运行类型检查
1414

15-
你可以通过指定文件路径来提供自己的池
15+
你可以通过指定文件路径来提供自己的运行池
1616

1717
```ts [vitest.config.ts]
1818
import { defineConfig } from 'vitest/config'
1919

2020
export default defineConfig({
2121
test: {
22-
// 默认情况下,将使用自定义池运行每个文件
22+
// 默认情况下,将使用自定义运行池运行每个文件
2323
pool: './my-custom-pool.ts',
2424
// 可以使用 `poolOptions` 对象提供选项
2525
poolOptions: {
@@ -31,7 +31,7 @@ export default defineConfig({
3131
})
3232
```
3333

34-
如果你需要让测试在不同的执行池中分别运行,可以借助 [`projects`](/guide/projects) 功能来实现:
34+
如果你需要让测试在不同的运行池中分别运行,可以借助 [`projects`](/guide/projects) 功能来实现:
3535

3636
```ts [vitest.config.ts]
3737
export default defineConfig({
@@ -69,7 +69,7 @@ Vitest 会在安排新的测试任务时调用 runTest 方法;如果 files 为
6969

7070
`runTests` 函数执行完毕之前, Vitest 会一直“挂起”当前测试流程;只有当 `runTests` 成功返回, Vitest 才会把 [`onTestRunEnd`](/advanced/reporters) 事件发出来,宣告本轮测试正式结束。
7171

72-
如果你正在使用自定义池,需要自行提供测试文件及其结果 - 可以参考 [`vitest.state`](https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/state.ts)(最重要的是 `collectFiles``updateTasks`)。Vitest 使用 `@vitest/runner` 包中的 `startTests` 函数来执行这些操作。
72+
如果你正在使用自定义运行池,需要自行提供测试文件及其结果 - 可以参考 [`vitest.state`](https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/state.ts)(最重要的是 `collectFiles``updateTasks`)。Vitest 使用 `@vitest/runner` 包中的 `startTests` 函数来执行这些操作。
7373

7474
如果通过 CLI 命令调用 `vitest.collect``vitest list`,则 Vitest 将调用 `collectTests`。它的工作方式与 `runTests` 相同,但你不必运行测试回调,只需通过调用 `vitest.state.collectFiles(files)` 来报告它们的任务。
7575

@@ -93,4 +93,4 @@ function createRpc(project: TestProject, wss: WebSocketServer) {
9393
}
9494
```
9595

96-
你可以查看一个从头开始制作的简单池示例,该池不运行测试,而是将它们标记为已收集:[pool/custom-pool.ts](https://github.com/vitest-dev/vitest/blob/main/test/cli/fixtures/custom-pool/pool/custom-pool.ts)
96+
你可以查看一个从头开始制作的简单运行池示例,该运行池不运行测试,而是将它们标记为已收集:[pool/custom-pool.ts](https://github.com/vitest-dev/vitest/blob/main/test/cli/fixtures/custom-pool/pool/custom-pool.ts)

api/expect-typeof.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { expectTypeOf } from 'vitest'
7070
expectTypeOf({ a: 1, b: 2 }).toMatchObjectType<{ a: number }>() // preferred
7171
expectTypeOf({ a: 1, b: 2 }).toExtend<{ a: number }>() // works but less strict
7272

73-
// Supports nested object checking
73+
// 支持嵌套对象检查
7474
const user = {
7575
name: 'John',
7676
address: { city: 'New York', zip: '10001' }
@@ -102,11 +102,11 @@ function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
102102
const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
103103

104104
expectTypeOf(getResponsiveProp(cssProperties))
105-
.extract<{ xs?: any }>() // extracts the last type from a union
105+
.extract<{ xs?: any }>() // 从联合类型中提取最后一个类型
106106
.toEqualTypeOf<{ xs?: CSSProperties, sm?: CSSProperties, md?: CSSProperties }>()
107107

108108
expectTypeOf(getResponsiveProp(cssProperties))
109-
.extract<unknown[]>() // extracts an array from a union
109+
.extract<unknown[]>() // 从联合类型中提取数组
110110
.toEqualTypeOf<CSSProperties[]>()
111111
```
112112

@@ -135,7 +135,7 @@ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
135135

136136
expectTypeOf(getResponsiveProp(cssProperties))
137137
.exclude<unknown[]>()
138-
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
138+
.exclude<{ xs?: unknown }>() // 或直接使用 .exclude<unknown[] | { xs?: unknown }>()
139139
.toEqualTypeOf<CSSProperties>()
140140
```
141141

api/expect.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ expect(input).toBe(2) // jest API
4141

4242
## assert
4343

44-
- **Type:** `Chai.AssertStatic`
44+
- **类型:** `Chai.AssertStatic`
4545

46-
Vitest reexports chai's [`assert` API](https://www.chaijs.com/api/assert/) as `expect.assert` for convenience. You can see the supported methods on the [Assert API page](/api/assert).
46+
Vitest 将 Chai 的 [`assert` API](https://www.chaijs.com/api/assert/) `expect.assert` 的形式重新导出。你可以在 [Assert API page](/api/assert) 页面查看支持的方法。
4747

48-
This is especially useful if you need to narrow down the type, since `expect.to*` methods do not support that:
48+
如果你需要缩小类型范围时,这将特别有用,因为 `expect.to*` 方法不支持此功能:
4949

5050
```ts
5151
interface Cat {
@@ -61,12 +61,12 @@ type Animal = Cat | Dog
6161
const animal: Animal = { __type: 'Dog', bark: () => {} }
6262

6363
expect.assert(animal.__type === 'Dog')
64-
// does not show a type error!
64+
// 不显示类型错误!
6565
expect(animal.bark()).toBeUndefined()
6666
```
6767

6868
::: tip
69-
Note that `expect.assert` also supports other type-narrowing methods (like `assert.isDefined`, `assert.exists` and so on).
69+
注意,`expect.assert` 还支持其他缩小类型的方法(如:`assert.isDefined``assert.exists`等)。
7070
:::
7171

7272
## soft
@@ -79,10 +79,10 @@ Note that `expect.assert` also supports other type-narrowing methods (like `asse
7979
import { expect, test } from 'vitest'
8080

8181
test('expect.soft test', () => {
82-
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
83-
expect.soft(1 + 2).toBe(4) // mark the test as fail and continue
82+
expect.soft(1 + 1).toBe(3) // 将期望标记为失败并继续
83+
expect.soft(1 + 2).toBe(4) // 将期望标记为失败并继续
8484
})
85-
// reporter will report both errors at the end of the run
85+
// 在执行结束后,报告器会报告这两个错误。
8686
```
8787

8888
它也可以与 `expect` 一起使用。 如果 `expect` 断言失败,测试将终止并显示所有错误。
@@ -91,9 +91,9 @@ test('expect.soft test', () => {
9191
import { expect, test } from 'vitest'
9292

9393
test('expect.soft test', () => {
94-
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
95-
expect(1 + 2).toBe(4) // failed and terminate the test, all previous errors will be output
96-
expect.soft(1 + 3).toBe(5) // do not run
94+
expect.soft(1 + 1).toBe(3) // 将期望标记为失败并继续
95+
expect(1 + 2).toBe(4) // 测试失败并终止执行,所有先前错误将被输出
96+
expect.soft(1 + 3).toBe(5) // 不再执行
9797
})
9898
```
9999

@@ -195,13 +195,13 @@ test('stocks are the same', () => {
195195
import { expect, test } from 'vitest'
196196

197197
test.fails('decimals are not equal in javascript', () => {
198-
expect(0.2 + 0.1).toBe(0.3) // 0.2 + 0.1 is 0.30000000000000004
198+
expect(0.2 + 0.1).toBe(0.3) // 0.2 + 0.1 = 0.30000000000000004
199199
})
200200

201201
test('decimals are rounded to 5 after the point', () => {
202-
// 0.2 + 0.1 is 0.30000 | "000000000004" removed
202+
// 0.2 + 0.1 等于 0.30000 | "000000000004" 被移除
203203
expect(0.2 + 0.1).toBeCloseTo(0.3, 5)
204-
// nothing from 0.30000000000000004 is removed
204+
// 没有从 0.30000000000000004 移除任何内容
205205
expect(0.2 + 0.1).not.toBeCloseTo(0.3, 50)
206206
})
207207
```
@@ -590,9 +590,9 @@ test('the fruit list contains orange', () => {
590590
expect(getAllFruits()).toContain('orange')
591591

592592
const element = document.querySelector('#el')
593-
// element has a class
593+
// element class 属性 flex
594594
expect(element.classList).toContain('flex')
595-
// element is inside another one
595+
// element 是 #wrapper 的子元素
596596
expect(document.querySelector('#wrapper')).toContain(element)
597597
})
598598
```
@@ -664,25 +664,25 @@ const invoice = {
664664
}
665665

666666
test('John Doe Invoice', () => {
667-
expect(invoice).toHaveProperty('isActive') // assert that the key exists
668-
expect(invoice).toHaveProperty('total_amount', 5000) // assert that the key exists and the value is equal
667+
expect(invoice).toHaveProperty('isActive') // 断言对应的key存在
668+
expect(invoice).toHaveProperty('total_amount', 5000) // 断言对应的key存在,并且值相等
669669

670-
expect(invoice).not.toHaveProperty('account') // assert that this key does not exist
670+
expect(invoice).not.toHaveProperty('account') // 断言对应的key不存在
671671

672-
// Deep referencing using dot notation
672+
// 使用点号进行深层引用
673673
expect(invoice).toHaveProperty('customer.first_name')
674674
expect(invoice).toHaveProperty('customer.last_name', 'Doe')
675675
expect(invoice).not.toHaveProperty('customer.location', 'India')
676676

677-
// Deep referencing using an array containing the key
677+
// 使用含键名的数组进行深层引用
678678
expect(invoice).toHaveProperty('items[0].type', 'apples')
679-
expect(invoice).toHaveProperty('items.0.type', 'apples') // dot notation also works
679+
expect(invoice).toHaveProperty('items.0.type', 'apples') // 也可以使用点号
680680

681-
// Deep referencing using an array containing the keyPath
681+
// 通过包含键路径的数组实现深层引用
682682
expect(invoice).toHaveProperty(['items', 0, 'type'], 'apples')
683-
expect(invoice).toHaveProperty(['items', '0', 'type'], 'apples') // string notation also works
683+
expect(invoice).toHaveProperty(['items', '0', 'type'], 'apples') // 字符串表示法同样适用
684684

685-
// Wrap your key in an array to avoid the key from being parsed as a deep reference
685+
// 将键名包裹在数组中,避免其被解析为深层引用
686686
expect(invoice).toHaveProperty(['P.O'], '12345')
687687
})
688688
```
@@ -790,15 +790,15 @@ function getFruitStock(type: string) {
790790
throw new Error('Pineapples are not in stock')
791791
}
792792

793-
// Do some other stuff
793+
// 做一些其他的东西
794794
}
795795

796796
test('throws on pineapples', () => {
797-
// Test that the error message says "stock" somewhere: these are equivalent
797+
// 测试错误信息包含 “stock”,这两种写法是等效的
798798
expect(() => getFruitStock('pineapples')).toThrowError(/stock/)
799799
expect(() => getFruitStock('pineapples')).toThrowError('stock')
800800

801-
// Test the exact error message
801+
// 测试确切的错误信息
802802
expect(() => getFruitStock('pineapples')).toThrowError(
803803
/^Pineapples are not in stock$/
804804
)
@@ -872,7 +872,7 @@ import { expect, test } from 'vitest'
872872

873873
test('matches inline snapshot', () => {
874874
const data = { foo: new Set(['bar', 'snapshot']) }
875-
// Vitest will update following content when updating the snapshot
875+
// Vitest 将在更新快照的同时更新以下内容
876876
expect(data).toMatchInlineSnapshot(`
877877
{
878878
"foo": Set {
@@ -1371,7 +1371,7 @@ async function buyApples() {
13711371
}
13721372

13731373
test('buyApples returns new stock id', async () => {
1374-
// toEqual returns a promise now, so you HAVE to await it
1374+
// toEqual 现在返回一个 Promise,调用时需添加 await
13751375
await expect(buyApples()).resolves.toEqual({ id: 1 }) // jest API
13761376
await expect(buyApples()).resolves.to.equal({ id: 1 }) // chai API
13771377
})
@@ -1403,7 +1403,7 @@ async function buyApples(id) {
14031403
}
14041404

14051405
test('buyApples throws an error when no id provided', async () => {
1406-
// toThrow returns a promise now, so you HAVE to await it
1406+
// toThrow 现在返回一个 Promise,调用时需添加 await
14071407
await expect(buyApples()).rejects.toThrow('no id')
14081408
})
14091409
```
@@ -1464,7 +1464,7 @@ function onSelect(cb) {
14641464
cbs.push(cb)
14651465
}
14661466

1467-
// after selecting from db, we call all callbacks
1467+
// 在数据库查询操作之后,立即执行全部回调函数
14681468
function select(id) {
14691469
return db.select({ id }).then((data) => {
14701470
return Promise.all(cbs.map(cb => cb(data)))
@@ -1474,11 +1474,11 @@ function select(id) {
14741474
test('callback was called', async () => {
14751475
expect.hasAssertions()
14761476
onSelect((data) => {
1477-
// should be called on select
1477+
// 必须在 select 操作时调用
14781478
expect(data).toBeTruthy()
14791479
})
1480-
// if not awaited, test will fail
1481-
// if you don't have expect.hasAssertions(), test will pass
1480+
// 若没有添加 await 测试将会失败
1481+
// 若缺少 expect.hasAssertions(), 测试仍会通过
14821482
await select(3)
14831483
})
14841484
```
@@ -1519,7 +1519,7 @@ test.each(errorDirs)('build fails with "%s"', async (dir) => {
15191519
expect(err.message).toBe(`${dir}/src does not exist`)
15201520
break
15211521
default:
1522-
// to exhaust all error tests
1522+
// 必须覆盖所有错误测试场景
15231523
expect.unreachable('All error test must be handled')
15241524
break
15251525
}

0 commit comments

Comments
 (0)