Skip to content

Commit 0f69d34

Browse files
authored
Merge pull request #974 from vitest-dev/sync-ea5391c0-1
docs(en): merge docs-cn/sync-docs into docs-cn/dev @ ea5391c
2 parents 72e981b + 4853352 commit 0f69d34

5 files changed

Lines changed: 29 additions & 5 deletions

File tree

api/browser/commands.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ declare module 'vitest/browser' {
125125
::: warning
126126
如果自定义命令具有相同的名称,则它们将覆盖内置命令。
127127
:::
128+
<!-- TODO: translation -->
129+
### Recording trace markers
130+
131+
Custom commands can record [trace markers](/api/browser/context#mark) for the test that triggered them through `context.mark`. This is the server-side equivalent of `page.mark` and helps annotate the [trace view](/guide/browser/trace-view) with custom actions performed inside a command.
132+
133+
```ts
134+
import type { BrowserCommand } from 'vitest/node'
135+
136+
export const uploadFixture: BrowserCommand<[name: string]> = async (
137+
context,
138+
name,
139+
) => {
140+
await context.mark(`upload start: ${name}`, { kind: 'action' })
141+
// ... do server-side work
142+
await context.mark(`upload done: ${name}`, { kind: 'action' })
143+
}
144+
```
145+
146+
`context.mark` is a no-op when browser tracing is not enabled or no test is currently running in the session. Unlike `page.mark`, it does not accept a callback form.
128147

129148
### 自定义 `playwright` 命令 {#custom-playwright-commands}
130149

api/browser/context.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const page: {
122122
请注意,如果 `save` 设置为 `false``screenshot` 将始终返回 base64 字符串。
123123
在这种情况下,`path` 也会被忽略。
124124
:::
125-
125+
<!-- TODO: translation -->
126126
### mark
127127
128128
```ts
@@ -157,6 +157,8 @@ await page.mark('submit flow', async () => {
157157

158158
::: tip
159159
This method is useful only when [`browser.trace`](/config/browser/trace) is enabled.
160+
161+
A server-side equivalent is available on the [`BrowserCommandContext`](/api/browser/commands#recording-trace-markers) so [custom commands](/api/browser/commands#custom-commands) can record markers attributed to the test that triggered them.
160162
:::
161163

162164
### frameLocator

config/attachmentsdir.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ title: attachmentsDir | 配置
33
outline: deep
44
---
55

6-
# attachmentsDir
6+
# attachmentsDir <CRoot />
77

88
- **类型:** `string`
99
- **默认值:** `'.vitest/attachments'`
1010

11-
用于存储 [`context.annotate`](/guide/test-context#annotate) 所创建附件的目录路径(相对于项目根目录)。
11+
Directory path for storing file attachments created by [`context.annotate`](/guide/test-context#annotate).
12+
13+
This option is resolved relative to the root Vitest config. When using [`projects`](/guide/projects), all projects share the same `attachmentsDir`; it cannot be configured per project.

guide/browser/trace-view.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Trace entries are recorded automatically for:
101101

102102
Each entry captures the DOM state at that point, along with timing information, the selector, and the source location that triggered it.
103103

104-
Element highlighting is best-effort. Some provider-specific selectors, shadow DOM selectors, or elements that are not present in the captured snapshot may not be highlighted.
104+
In Vitest UI, trace entries are streamed as the test runs, so you can inspect recorded steps before the test finishes. Long-running actions, `expect.element(...)` assertions, and callback `page.mark()` entries appear as in-progress steps first, then update with their final status and duration.
105105

106106
## Custom Trace Entries
107107

guide/projects.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ export default defineConfig({
285285

286286
::: danger 不支持的选项
287287
部分配置选项不允许在项目配置中使用,主要包括:
288-
288+
<!-- TODO: translation -->
289289
- `coverage`:覆盖率统计针对整个进程
290290
- `reporters`:只支持根级别的 reporters
291291
- `resolveSnapshotPath`:只尊重根级别的快照路径解析器
292+
- `attachmentsDir`: attachments are stored in one root-level directory shared by all projects
292293
- 其他不影响测试运行器的选项
293294

294295
所有不支持在项目配置中使用的配置选项,在 ["配置"](/config/) 指南中会用 <CRoot /> 标记。它们必须在根配置文件中定义一次。

0 commit comments

Comments
 (0)