Skip to content

Commit 17287b1

Browse files
WuMingDaoNoiseFan
andauthored
docs(cn): translate Vitest 3.2 release announcement (#831)
* Add translate * update translate * Refine comments in examples.md for clarity * Update title from '注解' to '注释' in guide * Fix formatting in vitest-3-2.md * Update method return value explanation in vitest-3-2.md Clarified the explanation regarding the return value of the method. * docs(cn): proofreading translation --------- Co-authored-by: noise <noisefan@163.com>
1 parent d5b6e83 commit 17287b1

File tree

6 files changed

+93
-251
lines changed

6 files changed

+93
-251
lines changed

blog/vitest-3-2.md

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Vitest 3.2 is out!
2+
title: Vitest 3.2 发布了!
33
author:
4-
name: The Vitest Team
4+
name: Vitest 团队
55
date: 2025-06-02
66
sidebar: false
77
head:
@@ -10,48 +10,48 @@ head:
1010
content: website
1111
- - meta
1212
- property: og:title
13-
content: Announcing Vitest 3.2
13+
content: Vitest 3.2 发布了
1414
- - meta
1515
- property: og:image
16-
content: https://vitest.dev/og-vitest-3-2.png
16+
content: https://cn.vitest.dev/og-vitest-3-2.png
1717
- - meta
1818
- property: og:url
19-
content: https://vitest.dev/blog/vitest-3-2
19+
content: https://cn.vitest.dev/blog/vitest-3-2
2020
- - meta
2121
- property: og:description
22-
content: Vitest 3.2 Release Announcement
22+
content: Vitest 3.2 发布公告
2323
- - meta
2424
- name: twitter:card
2525
content: summary_large_image
2626
---
2727

28-
# Vitest 3.2 is out!
28+
# Vitest 3.2 发布了!
2929

30-
_June 2, 2025_
30+
_2025 年 6 月 2 日_
3131

32-
![Vitest 3.2 Announcement Cover Image](/og-vitest-3-2.png)
32+
![Vitest 3.2 公告封面图](/og-vitest-3-2.png)
3333

34-
Vitest 3.2 focuses on improvements to Browser Mode and TypeScript support. This release also includes some new useful methods, config options and deprecates the `workspace` config in favour of `projects`.
34+
Vitest 3.2 专注于改进浏览器模式和 TypeScript 支持。此版本还包含一些新的实用方法、配置选项,并弃用了 `workspace` 配置,转而推荐使用 `projects`
3535

36-
## `workspace` is Deprecated
36+
## `workspace` 已弃用 {#workspace-is-deprecated}
3737

38-
In an effort to simplify the configuration, the team decided to deprecate the separate `vitest.workspace` file and recommend using only the `projects` option in the root config. This also simplifies how the global options are configured (because you don't need to guess how to add reporters when you have no root config).
38+
为了简化配置,团队决定弃用单独的 `vitest.workspace` 文件,推荐仅在根配置中使用 `projects` 选项。这也简化了全局选项的配置方式(因为当你没有根配置时,不需要再猜测如何添加报告器)。
3939

40-
We also decided to deprecate the `workspace` name because it clashes with other tools like PNPM that provide monorepo support via this option. Vitest doesn't run these projects with separate `CWD` and treats them more like sub-Vitests. It also gives us more space to come up with a better solution for monorepos without breaking others.
40+
我们还决定弃用 `workspace` 这个名称,因为它与 PNPM 等工具通过该选项提供 monorepo 支持功能存在冲突。Vitest 不会为这些项目分配独立的 `工作目录(CWD`,而是将其视为子 Vitest 实例。这也为我们提供了更多空间,以便在不破坏其他功能的情况下为 monorepo 提供更好的解决方案。
4141

42-
This option will be removed completely in a future major, replaced by `projects`. Until then, Vitest will print a warning if workspace feature is used.
42+
此选项将在未来的主版本中完全移除,由 `projects` 取代。在此之前,如果使用了 workspace 功能,Vitest 将打印警告。
4343

4444
<!--@include: ../guide/examples/projects-workspace.md-->
4545

46-
## Annotation API
46+
## 注释 API {#annotation-api}
4747

48-
The new [annotation API](/guide/test-annotations) allows you to annotate any test with a custom message and attachment. These annotations are visible in the UI, HTML, junit, tap and GitHub Actions reporters. Vitest will also print related annotation in the CLI if the test fails.
48+
新的 [注释 API](/guide/test-annotations) 允许你为任何测试添加自定义消息和附件。这些注释在 UI、HTMLjunittap GitHub Actions 报告器中可见。如果测试失败,Vitest 还会在 CLI 中打印相关注释。
4949

5050
<img src="/annotation-api-cute-puppy-example.png" />
5151

52-
## Scoped Fixtures
52+
## 作用域固定装置 {#scoped-fixtures}
5353

54-
The `test.extend` fixtures can now specify the `scope` option: either `file` or `worker`.
54+
`test.extend` 固定装置现在可以指定 `scope` 选项:`file` `worker`
5555

5656
```ts
5757
const test = baseTest.extend({
@@ -66,15 +66,15 @@ const test = baseTest.extend({
6666
})
6767
```
6868

69-
The file fixture is similar to using `beforeAll` and `afterAll` at the top level of the file, but it won't be called if the fixture is not used in any test.
69+
`file` 固定装置类似于在文件顶层使用 `beforeAll` `afterAll`,但如果没有任何测试使用该固定装置,它就不会被调用。
7070

71-
The `worker` fixture is initiated once per worker, but note that by default Vitest creates one worker for every test, so you need to disable [isolation](/config/#isolate) to benefit from it.
71+
`worker` 固定装置在每个工作线程中仅初始化一次。但请注意,默认情况下 Vitest 为每个测试创建独立工作线程,因此需要禁用 [隔离模式](/config/#isolate) 才能生效。
7272

73-
## Custom Project Name Colors
73+
## 自定义项目名称颜色 {#custom-project-name-colors}
7474

75-
You can now set a custom [color](/config/#name) when using `projects`:
75+
使用 `projects` 时,你现在可以设置自定义 [颜色](/config/#name)
7676

77-
::: details Config Example
77+
::: details 配置示例
7878
```ts{6-9,14-17}
7979
export default defineConfig({
8080
test: {
@@ -108,9 +108,9 @@ export default defineConfig({
108108

109109
<img src="/v3-2-custom-colors.png" />
110110

111-
## Custom Browser Locators API
111+
## 自定义浏览器定位器 API {#custom-browser-locators-api}
112112

113-
Built-in locators might not be enough to express your application’s needs. Instead of falling back to CSS and losing the retry-ability protection that Vitest provides through its locator API, we now recommend extending locators using the new [`locators.extend` API](/guide/browser/locators#custom-locators).
113+
当内置定位器无法满足应用需求时。与其降级使用 CSS 选择器,并牺牲 Vitest 定位器 API 提供的重试保护机制,不如推荐你使用 [`locators.extend` API](/guide/browser/locators#custom-locators) 扩展定位器。
114114

115115
```ts
116116
import { locators } from '@vitest/browser/context'
@@ -122,9 +122,9 @@ locators.extend({
122122
})
123123
```
124124

125-
Return a Playwright [locator string](https://playwright.dev/docs/other-locators) to construct a new locator. Note that string returned from this method will be scoped to the parent locator, if there is one.
125+
返回 Playwright [定位器字符串](https://playwright.dev/docs/other-locators)来构造新的定位器。请注意,从此方法返回的字符串将用作于父定位器范围内(如果有的话)。
126126

127-
Now you can call `getByCommentsCount` on the `page` or any other locator directly:
127+
现在你可以直接在 `page` 对象或任何其他定位器上调用 `getByCommentsCount`
128128

129129
```ts
130130
await expect.element(page.getByCommentsCount(1)).toBeVisible()
@@ -134,15 +134,15 @@ await expect.element(
134134
).toBeVisible()
135135
```
136136

137-
If this method returns a string, then the return value will be converted into a locator, so you can keep chaining it:
137+
如果此方法返回字符串,返回值将被转换为定位器对象,因此你可以继续链式调用:
138138

139139
```ts
140140
page.getByRole('article', { name: 'Hello World' })
141141
.getByCommentsCount(1)
142142
.getByText('comments')
143143
```
144144

145-
This method has access to the current locator context, if there is one (if method is called on the `page`, then context will refer to `page`), so you can chain all locator methods inside:
145+
此方法可以访问当前的定位器上下文(如果有的话,在 `page` 对象上调用时,则上下文指向 `page`),因此你可以在内部链式调用所有定位器方法:
146146

147147
```ts
148148
import type { Locator } from '@vitest/browser/context'
@@ -156,7 +156,7 @@ locators.extend({
156156
})
157157
```
158158

159-
Having access to context also allows you to call regular methods of the locator to define a custom user event:
159+
通过访问上下文,你还可以调用定位器的常规方法来定义自定义用户事件:
160160

161161
```ts
162162
import type { Locator } from '@vitest/browser/context'
@@ -172,11 +172,11 @@ locators.extend({
172172
await page.getByRole('textbox').clickAndFill('Hello World')
173173
```
174174

175-
Please, refer to the [`locators.extend` API](/guide/browser/locators#custom-locators) for more information.
175+
请参阅 [`locators.extend` API](/guide/browser/locators#custom-locators) 获取更多信息。
176176

177-
## Explicit Resource Management in `vi.spyOn` and `vi.fn`
177+
## `vi.spyOn` `vi.fn` 中的显式资源管理 {#explicit-resource-management-in-vi-spyon-and-vi-fn}
178178

179-
In environments that support [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management), you can use `using` instead of `const` to automatically call `mockRestore` on any mocked function when the containing block is exited. This is especially useful for spied methods:
179+
在支持 [显式资源管理](https://github.com/tc39/proposal-explicit-resource-management) 的环境中,你可以使用 `using` 代替 `const`,以便在包含块退出时自动对任何模拟函数调用 `mockRestore`。这对于监听方法特别有用:
180180

181181
```ts
182182
it('calls console.log', () => {
@@ -185,34 +185,34 @@ it('calls console.log', () => {
185185
expect(spy).toHaveBeenCalled()
186186
})
187187

188-
// console.log is restored here
188+
// console.log 在此处还原
189189
```
190190

191-
## Test `signal` API
191+
## 测试 `signal` API {#test-signal-api}
192192

193-
Vitest now provides an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) object to the test body. You can use it to stop any resource that supports this Web API.
193+
Vitest 现在向测试主体提供一个 [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) 对象。你可以使用它来停止任何支持此 Web API 的资源。
194194

195-
The signal is aborted when test times out, another test fails and [`--bail` flag](/config/#bail) is set to a non-zero value, or the user presses Ctrl+C in the terminal.
195+
当测试超时、其他测试失败且 [`--bail` 标志](/config/#bail) 设置为非零值,或者用户在终端中按下 Ctrl+C 时,信号会被中止。
196196

197-
For example, you can stop a `fetch` request when tests are interrupted:
197+
例如,你可以在测试中断时停止 `fetch` 请求:
198198

199199
```ts
200200
it('stop request when test times out', async ({ signal }) => {
201201
await fetch('/heavy-resource', { signal })
202202
}, 2000)
203203
```
204204

205-
## Coverage V8 AST-aware remapping
205+
## Coverage V8 AST 感知重映射 {#coverage-v8-ast-aware-remapping}
206206

207-
Vitest now uses `ast-v8-to-istanbul` package developed by one of the Vitest maintainers, [AriPerkkio](https://github.com/AriPerkkio). This brings v8 coverage report in line with istanbul, but has a better performance! Enable this feature by setting [`coverage.experimentalAstAwareRemapping`](/config/#coverage-experimentalastawareremapping) to `true`.
207+
Vitest 现在使用由 Vitest 维护者之一 [AriPerkkio](https://github.com/AriPerkkio) 开发的 `ast-v8-to-istanbul` 包。这使 v8 覆盖率报告与 istanbul 保持一致,但性能更好!通过将 [`coverage.experimentalAstAwareRemapping`](/config/#coverage-experimentalastawareremapping) 设置为 `true` 来启用此功能。
208208

209-
We are planning to make this the default remapping mode in the next major. The old `v8-to-istanbul` will be removed completely. Feel free to join discussion at https://github.com/vitest-dev/vitest/issues/7928.
209+
我们计划在下一个主版本中将此作为默认重映射模式。旧的 `v8-to-istanbul` 将被完全移除。欢迎在 https://github.com/vitest-dev/vitest/issues/7928 参与讨论。
210210

211-
## `watchTriggerPatterns` Option
211+
## `watchTriggerPatterns` 选项 {#watchtriggerpatterns-option}
212212

213-
When you edit a file, Vitest is smart enough to rerun only tests that import this file. Unfortunately, Vitest static analysis respects only static and dynamic `import` statement. If you are reading a file or starting a separate process, Vitest will ignore changes to related files.
213+
当你编辑文件时,Vitest 会智能地仅重新运行导入该文件的测试。遗憾的是,Vitest 的静态分析只支持静态和动态 `import` 语句。如果你通过文件读取或启动单独的进程,Vitest 将忽略相关文件的更改。
214214

215-
With `watchTriggerPatterns` option you can configure which tests to rerun depending on the file that was changed. For example, to always rerun `mailers` tests when a template is changed, add a trigger pattern:
215+
使用 `watchTriggerPatterns` 选项,你可以配置根据更改的文件重新运行哪些测试。例如,如果想要在更改模板时始终重新运行 `mailers` 测试,可以添加一个触发模式:
216216

217217
```ts
218218
export default defineConfig({
@@ -229,15 +229,15 @@ export default defineConfig({
229229
})
230230
```
231231

232-
## The New Multi-Purpose `Matchers` Type
232+
## 新的多用途 `Matchers` 类型 {#the-new-multi-purpose-matchers-type}
233233

234-
Vitest now has a `Matchers` type that you can extend to add type support for all your custom matchers in one place. This type affects all these use cases:
234+
Vitest 现在有一个 `Matchers` 类型,你可以扩展它来在一个地方为所有自定义匹配器添加类型支持。此类型影响以下所有用例:
235235

236236
- `expect().to*`
237237
- `expect.to*`
238238
- `expect.extend({ to* })`
239239

240-
For example, to have a type-safe `toBeFoo` matcher, you can write something like this:
240+
例如,要拥有一个类型安全的 `toBeFoo` 匹配器,你可以这样写:
241241

242242
```ts twoslash
243243
import { expect } from 'vitest'
@@ -253,7 +253,7 @@ declare module 'vitest' {
253253
expect.extend({
254254
toBeFoo(actual, arg) {
255255
// ^?
256-
// ... implementation
256+
// 具体实现...
257257
return {
258258
pass: true,
259259
message: () => '',
@@ -267,14 +267,14 @@ expect.toBeFoo('foo')
267267

268268
## `sequence.groupOrder`
269269

270-
The new [`sequence.groupOrder`](/config/#grouporder) option controls the order in which the project runs its tests when using multiple [projects](/guide/projects).
270+
新的 [`sequence.groupOrder`](/config/#grouporder) 选项控制在使用多个 [projects](/guide/projects) 时项目测试执行的顺序。
271271

272-
- Projects with the same group order number will run together, and groups are run from lowest to highest.
273-
- If you don’t set this option, all projects run in parallel.
274-
- If several projects use the same group order, they will run at the same time.
272+
- 具有相同分组序号的测试项目将并行运行,各组按序号从低到高依次执行。
273+
- 若未设置此选项,所有项目将默认并行执行。
274+
- 当多个项目使用相同分组序号时,它们将同时执行。
275275

276-
::: details Example
277-
Consider this example:
276+
::: details 示例
277+
考虑这个例子:
278278

279279
```ts
280280
import { defineConfig } from 'vitest/config'
@@ -311,17 +311,17 @@ export default defineConfig({
311311
})
312312
```
313313

314-
Tests in these projects will run in this order:
314+
这些项目中的测试将按以下顺序运行:
315315

316316
```
317317
0. slow |
318-
|> running together
318+
|> 并行执行
319319
0. fast |
320320
321-
1. flaky |> runs after slow and fast alone
321+
1. flaky |> slow fast 之后单独运行
322322
```
323323
:::
324324

325325
----
326326

327-
The complete list of changes is at the [Vitest 3.2 Changelog](https://github.com/vitest-dev/vitest/releases/tag/v3.2.0).
327+
完整的更改列表请查看 [Vitest 3.2 更新日志](https://github.com/vitest-dev/vitest/releases/tag/v3.2.0)

blog/vitest-3.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Vitest 3.0 发布了!
33
author:
4-
name: The Vitest Team
4+
name: Vitest 团队
55
date: 2025-01-17
66
sidebar: false
77
head:
@@ -13,23 +13,23 @@ head:
1313
content: Vitest 3.0 发布了!
1414
- - meta
1515
- property: og:image
16-
content: https://vitest.dev/og-vitest-3.jpg
16+
content: https://cn.vitest.dev/og-vitest-3.jpg
1717
- - meta
1818
- property: og:url
19-
content: https://vitest.dev/blog/vitest-3
19+
content: https://cn.vitest.dev/blog/vitest-3
2020
- - meta
2121
- property: og:description
22-
content: Vitest 3.0 Release Announcement
22+
content: Vitest 3.0 发布公告
2323
- - meta
2424
- name: twitter:card
2525
content: summary_large_image
2626
---
2727

2828
# Vitest 3.0 发布了!
2929

30-
_January 17, 2025_
30+
_2025 年 1 月 17 日_
3131

32-
![Vitest 3 Announcement Cover Image](/og-vitest-3.jpg)
32+
![Vitest 3 公告封面图](/og-vitest-3.jpg)
3333

3434
我们在半年前发布了 Vitest 2。我们见证了它被广泛采用,每周 npm 下载量从 480 万次增长到 770 万次。我们的生态系统也在快速发展。其中包括,Storybook 新的测试功能由我们的 VS Code 扩展和浏览器模式提供支持,以及 Matt Pocock 正在基于 Vitest 开发 Evalite,这是一个用于评估 AI 驱动应用的工具。
3535

0 commit comments

Comments
 (0)