You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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>
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`.
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).
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.
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.
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.
@@ -66,15 +66,15 @@ const test = baseTest.extend({
66
66
})
67
67
```
68
68
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.
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.
You can now set a custom [color](/config/#name) when using `projects`:
75
+
使用 `projects` 时,你现在可以设置自定义 [颜色](/config/#name):
76
76
77
-
::: details Config Example
77
+
::: details 配置示例
78
78
```ts{6-9,14-17}
79
79
export default defineConfig({
80
80
test: {
@@ -108,9 +108,9 @@ export default defineConfig({
108
108
109
109
<imgsrc="/v3-2-custom-colors.png" />
110
110
111
-
## Custom Browser Locators API
111
+
## 自定义浏览器定位器 API {#custom-browser-locators-api}
112
112
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) 扩展定位器。
114
114
115
115
```ts
116
116
import { locators } from'@vitest/browser/context'
@@ -122,9 +122,9 @@ locators.extend({
122
122
})
123
123
```
124
124
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.
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:
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:
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 的资源。
194
194
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.
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`.
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.
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.
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:
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:
For example, to have a type-safe `toBeFoo`matcher, you can write something like this:
240
+
例如,要拥有一个类型安全的 `toBeFoo`匹配器,你可以这样写:
241
241
242
242
```ts twoslash
243
243
import { expect } from'vitest'
@@ -253,7 +253,7 @@ declare module 'vitest' {
253
253
expect.extend({
254
254
toBeFoo(actual, arg) {
255
255
// ^?
256
-
// ... implementation
256
+
//具体实现...
257
257
return {
258
258
pass: true,
259
259
message: () =>'',
@@ -267,14 +267,14 @@ expect.toBeFoo('foo')
267
267
268
268
## `sequence.groupOrder`
269
269
270
-
The new [`sequence.groupOrder`](/config/#grouporder)option controls the order in which the project runs its tests when using multiple [projects](/guide/projects).
0 commit comments