Skip to content

Commit a7292a0

Browse files
authored
Merge pull request #942 from NoiseFan/backup-amend-15daae21
docs(en): merge docs-cn/sync-docs into docs-cn/dev @ b72fc6b
2 parents ba2b17a + a8b063b commit a7292a0

91 files changed

Lines changed: 3419 additions & 2675 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vitepress/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ export default ({ mode }: { mode: string }) => {
136136
},
137137
},
138138

139+
banner: {
140+
id: 'viteplus-alpha',
141+
text: 'Announcing Vite+ Alpha: Open source. Unified. Next-gen.',
142+
url: 'https://voidzero.dev/posts/announcing-vite-plus-alpha?utm_source=vitest&utm_content=top_banner',
143+
},
144+
139145
carbonAds: {
140146
code: 'CW7DVKJE',
141147
placement: 'vitestdev',

.vitepress/scripts/cli-generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const template = options.map((option) => {
8787
const cli = option.cli
8888
const [page, ...hash] = (title.startsWith('browser.') ? title.slice(8) : title).toLowerCase().split('.')
8989
const config = skipConfig.has(title) ? '' : `[${title}](${title.includes('browser.') ? '/config/browser/' : '/config/'}${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''})`
90+
// eslint-disable-next-line e18e/prefer-static-regex
9091
return `### ${title}\n\n- **CLI:** ${cli}\n${config ? `- **Config:** ${config}\n` : ''}\n${option.description.replace(/https:\/\/vitest\.dev\//g, '/')}\n`
9192
}).join('\n')
9293

.vitepress/sponsors.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export const sponsors: SponsorTier[] = [
66
size: 'big',
77
items: [
88
{
9-
name: 'NuxtLabs',
10-
url: 'https://nuxtlabs.com',
11-
img: '/nuxtlabs.svg',
9+
name: 'Vercel',
10+
url: 'https://vercel.com',
11+
img: '/vercel.svg',
1212
},
1313
{
14-
name: 'Bolt',
15-
url: 'https://bolt.new',
16-
img: '/bolt.svg',
14+
name: 'Chromatic',
15+
url: 'https://www.chromatic.com/?utm_source=vitest&utm_medium=sponsorship&utm_campaign=vitestSponsorship',
16+
img: '/chromatic.svg',
1717
},
1818
{
1919
name: 'Zammad',
@@ -26,10 +26,11 @@ export const sponsors: SponsorTier[] = [
2626
tier: '铂金赞助商',
2727
size: 'big',
2828
items: [
29+
2930
{
30-
name: 'Chromatic',
31-
url: 'https://www.chromatic.com/?utm_source=vitest&utm_medium=sponsorship&utm_campaign=vitestSponsorship',
32-
img: '/chromatic.svg',
31+
name: 'Bolt',
32+
url: 'https://bolt.new',
33+
img: '/bolt.svg',
3334
},
3435
],
3536
},
@@ -57,6 +58,11 @@ export const sponsors: SponsorTier[] = [
5758
url: 'https://www.liminity.se/',
5859
img: '/liminity.svg',
5960
},
61+
{
62+
name: 'Aerius Ventilation',
63+
url: 'https://aerius.se/',
64+
img: '/aerius.png',
65+
},
6066
],
6167
},
6268
]

api/advanced/metadata.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 任务元数据 <Badge type="danger">advanced</Badge>
1+
# 任务元数据 <Badge type="danger">高级</Badge>
22

33
如果你正在开发自定义报告器或使用 Vitest Node.js API,你可能会发现将在各种上下文中执行的测试中的数据传递给报告器或自定义 Vitest 处理程序很有用。
44

@@ -33,12 +33,12 @@ export default {
3333
} satisfies Reporter
3434
```
3535

36-
::: danger BEWARE
36+
::: danger 警告
3737
Vitest 使用不同的方法与 Node.js 进程进行通信。
3838

39-
- 如果 Vitest 在工作线程内运行测试,它将通过[消息端口](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort)发送数据
39+
- 如果 Vitest 在工作线程内运行测试,它将通过 [消息端口](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) 发送数据
4040
- 如果 Vitest 使用子进程,数据将通过 [`process.send`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) API 作为序列化缓冲区发送
41-
- 如果 Vitest 在浏览器中运行测试,数据将使用 [flatted](https://www.npmjs.com/package/flatted) 包进行字符串化
41+
- 如果 Vitest 在浏览器中运行测试,数据将使用 [flatted](https://npmx.dev/package/flatted) 包进行字符串化
4242

4343
该属性也会出现在每个测试的 `json` 报告中,因此请确保数据可以序列化为 JSON。
4444

api/advanced/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ outline: deep
1111
本指南假设我们知道如何使用 [Vite 插件](https://vite.dev/guide/api-plugin.html)
1212
:::
1313

14-
Vitest 自 3.1 版起支持实验性的 `configureVitest` [插件](https://cn.vite.dev/guide/api-plugin) hook。
14+
Vitest 自 3.1 版起支持 `configureVitest` [插件](https://cn.vite.dev/guide/api-plugin) hook。
1515

1616
::: code-group
1717
```ts [only vitest]

api/advanced/test-project.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default defineConfig({
5151
:::
5252

5353
::: info
54-
如果 [根项目](/api/advanced/vitest#getroottestproject) 不是用户工作区的一部分,则不会解析其 `name`
54+
如果 [根项目](/api/advanced/vitest#getrootproject) 不是用户工作区的一部分,则不会解析其 `name`
5555
:::
5656

5757
## vitest
@@ -78,7 +78,7 @@ project.serializedConfig === project.serializedConfig // ❌
7878

7979
## globalConfig
8080

81-
[`Vitest`](/api/advanced/vitest) 初始化时的测试配置。如果这是 [根项目](/api/advanced/vitest#getroottestproject)`globalConfig``config` 将引用同一个对象。此配置对于无法在项目级别设置的值非常有用,例如 `coverage``reporters`
81+
[`Vitest`](/api/advanced/vitest) 初始化时的测试配置。如果这是 [根项目](/api/advanced/vitest#getrootproject)`globalConfig``config` 将引用同一个对象。此配置对于无法在项目级别设置的值非常有用,例如 `coverage``reporters`
8282

8383
```ts
8484
import type { ResolvedConfig } from 'vitest/node'
@@ -206,7 +206,7 @@ await vitest.runTestSpecifications([specification])
206206
function isRootProject(): boolean
207207
```
208208

209-
检查当前项目是否为根项目。我们也可以通过调用 [`vitest.getRootProject()`](#getrootproject) 获取根项目。
209+
检查当前项目是否为根项目。我们也可以通过调用 [`vitest.getRootProject()`](/api/advanced/vitest#getrootproject) 获取根项目。
210210

211211
## globTestFiles
212212

@@ -233,7 +233,7 @@ project.globTestFiles(['basic/foo.js:10']) // ❌
233233
```
234234

235235
::: tip
236-
Vitest 使用 [fast-glob](https://www.npmjs.com/package/fast-glob) 来查找测试文件。`test.dir`、`test.root`、`root` 或 `process.cwd()` 定义了 `cwd` 选项。
236+
Vitest 使用 [fast-glob](https://npmx.dev/package/fast-glob) 来查找测试文件。`test.dir`、`test.root`、`root` 或 `process.cwd()` 定义了 `cwd` 选项。
237237

238238
此方法查看多个配置选项:
239239

api/browser/assertions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,14 +1072,14 @@ await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button', {
10721072
},
10731073
})
10741074
```
1075-
1075+
<!-- TODO: translation -->
10761076
### Options
10771077

10781078
- `comparatorName: "pixelmatch" = "pixelmatch"`
10791079

1080-
用于比较图像的算法/库名称。
1080+
The algorithm/library used for comparing images.
10811081

1082-
目前,仅支持 [“pixelmatch”](https://github.com/mapbox/pixelmatch)。
1082+
`"pixelmatch"` is the only built-in comparator, but you can use custom ones by [registering them in the config file](/config/browser/expect#browser-expect-tomatchscreenshot-comparators).
10831083

10841084
- `comparatorOptions: object`
10851085

@@ -1127,10 +1127,10 @@ await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button', {
11271127
等待获取稳定截图的时间。
11281128

11291129
设为 `0` 可禁用超时,但如果无法确定稳定截图,进程将不会结束。
1130-
1130+
<!-- TODO: translation -->
11311131
#### `"pixelmatch"` comparator options
11321132

1133-
使用 `"pixelmatch"` 比较器时,以下选项可用:
1133+
The `"pixelmatch"` comparator uses [`@blazediff/core`](https://blazediff.dev/docs/core) under the hood. The following options are available when using it:
11341134

11351135
- `allowedMismatchedPixelRatio: number | undefined = undefined`
11361136

api/browser/context.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const commands: BrowserCommands
6363
:::
6464
6565
使用 [Commands API](/api/browser/commands) 如果您需要访问 Playwright 的 `page` 对象。
66+
<!-- TODO: translation -->
6667
```ts
6768
export const page: {
6869
/**
@@ -78,7 +79,15 @@ export const page: {
7879
base64: string
7980
}>) & ((options?: ScreenshotOptions) => Promise<string>)
8081
/**
81-
* 使用自定义方法扩展默认的 `page` 对象。
82+
* Add a trace marker when browser tracing is enabled.
83+
*/
84+
mark(name: string, options?: { stack?: string }): Promise<void>
85+
/**
86+
* Group multiple operations under a trace marker when browser tracing is enabled.
87+
*/
88+
mark<T>(name: string, body: () => T | Promise<T>, options?: { stack?: string }): Promise<T>
89+
/**
90+
* Extend default `page` object with custom methods.
8291
*/
8392
extend: (methods: Partial<BrowserPage>) => BrowserPage
8493
/**
@@ -114,6 +123,40 @@ export const page: {
114123
在这种情况下,`path` 也会被忽略。
115124
:::
116125
126+
### mark
127+
128+
```ts
129+
function mark(name: string, options?: { stack?: string }): Promise<void>
130+
function mark<T>(
131+
name: string,
132+
body: () => T | Promise<T>,
133+
options?: { stack?: string },
134+
): Promise<T>
135+
```
136+
137+
Adds a named marker to the trace timeline for the current test.
138+
139+
Pass `options.stack` to override the callsite location in trace metadata. This is useful for wrapper libraries that need to preserve the end-user source location.
140+
141+
If you pass a callback, Vitest creates a trace group with this name, runs the callback, and closes the group automatically.
142+
143+
```ts
144+
import { page } from 'vitest/browser'
145+
146+
await page.mark('before submit')
147+
await page.getByRole('button', { name: 'Submit' }).click()
148+
await page.mark('after submit')
149+
150+
await page.mark('submit flow', async () => {
151+
await page.getByRole('textbox', { name: 'Email' }).fill('john@example.com')
152+
await page.getByRole('button', { name: 'Submit' }).click()
153+
})
154+
```
155+
156+
::: tip
157+
This method is useful only when [`browser.trace`](/config/browser/trace) is enabled.
158+
:::
159+
117160
### frameLocator
118161

119162
```ts
@@ -246,7 +289,7 @@ utils.configurePrettyDOM({
246289
- **`maxLength`** - Maximum length of the output string (default: `7000`)
247290
- **`filterNode`** - A CSS selector string or function to filter out nodes from the output. When a string is provided, elements matching the selector will be excluded. When a function is provided, it should return `false` to exclude a node.
248291
- **`highlight`** - Enable syntax highlighting (default: `true`)
249-
- And other options from [`pretty-format`](https://www.npmjs.com/package/@vitest/pretty-format)
292+
- And other options from [`pretty-format`](https://npmx.dev/package/@vitest/pretty-format)
250293
251294
#### Filtering with CSS Selectors <Version>4.1.0</Version> {#filtering-with-css-selectors}
252295

0 commit comments

Comments
 (0)