Skip to content

Commit fe369a2

Browse files
committed
docs(en): merging all conflicts
2 parents 759296d + ad185a8 commit fe369a2

16 files changed

Lines changed: 352 additions & 11 deletions

api/advanced/runner.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export default class Runner {
145145
:::
146146

147147
::: tip
148+
<<<<<<< HEAD
148149
快照支持和其他功能是依赖于测试运行器的。如果你想保留这些功能,可以从 `vitest/runners` 导入 `VitestTestRunner` 并将你的测试运行器继承该类。如果你想扩展基准测试功能,它还提供了 `NodeBenchmarkRunner`
150+
=======
151+
Snapshot support and some other features depend on the runner. If you don't want to lose it, you can extend your runner from `TestRunner` imported from `vitest`. It also exposes `NodeBenchmarkRunner`, if you want to extend benchmark functionality.
152+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
149153
:::
150154

151155
## Tasks {#tasks}

api/browser/locators.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,19 +1053,74 @@ function all(): Locator[]
10531053

10541054
- [更多内容请参阅 `locator.elements()`](#elements)
10551055

1056+
### serialize
1057+
1058+
```ts
1059+
function serialize(): SerializedLocator
1060+
```
1061+
1062+
Returns a JSON-serializable representation of the locator. The returned object has two fields:
1063+
1064+
- [`selector`](#selector): the provider-specific selector string used to query the element at runtime.
1065+
- `locator`: a human-readable description of the locator (e.g. `getByRole('button')`), used for error messages and tracing. Equivalent to calling [`asLocator()`](#aslocator).
1066+
1067+
This is primarily intended for forwarding a locator to a [browser command](/api/browser/commands), which runs in Node and cannot receive a live `Locator` instance:
1068+
1069+
```ts
1070+
import { commands, page } from 'vitest/browser'
1071+
1072+
await commands.myCommand(page.getByRole('button').serialize())
1073+
```
1074+
1075+
::: tip
1076+
Vitest automatically serializes any `Locator` argument passed to a command, so calling `serialize()` explicitly is rarely necessary. You can also use `JSON.stringify(locator)` (it calls [`toJSON`](#tojson) internally), which produces the same result.
1077+
:::
1078+
1079+
### toJSON
1080+
1081+
```ts
1082+
function toJSON(): SerializedLocator
1083+
```
1084+
1085+
Alias of [`serialize`](#serialize). Defined so that `JSON.stringify(locator)` and structured-clone-based transports return a `SerializedLocator` object.
1086+
1087+
### asLocator
1088+
1089+
```ts
1090+
function asLocator(): string
1091+
```
1092+
1093+
Returns a human-readable description of the locator using the JavaScript locator syntax (e.g. `getByRole('button', { name: 'Submit' })`). This is the same string exposed as the `locator` field of [`serialize()`](#serialize) and is used in error messages and traces.
1094+
1095+
```ts
1096+
import { page } from 'vitest/browser'
1097+
1098+
const button = page.getByRole('button', { name: 'Submit' })
1099+
button.asLocator() // "getByRole('button', { name: 'Submit' })"
1100+
```
1101+
1102+
::: tip
1103+
Use [`selector`](#selector) when you need the provider-specific string to forward to a [browser command](/api/browser/commands). Use `asLocator()` only for diagnostic output. The returned string is not meant to be re-used to query elements.
1104+
:::
1105+
10561106
## Properties
10571107

10581108
### selector
10591109

1110+
<<<<<<< HEAD
10601111
`selector` 是一个字符串,将由浏览器提供程序用于定位元素。Playwright 将使用 `playwright` 定位器语法,而 `preview``webdriverio` 将使用 CSS
1112+
=======
1113+
The `selector` is a string that will be used to locate the element by the browser provider. Playwright will use a `playwright` locator syntax, and `preview` and `webdriverio` will use CSS.
1114+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
10611115

10621116
::: danger
10631117
你不应在测试代码中使用此字符串。`selector` 字符串仅应在使用 Commands API 时使用:
10641118

10651119
```ts [commands.ts]
10661120
import type { BrowserCommand } from 'vitest/node'
1121+
import type { SerializedLocator } from '@vitest/browser'
10671122
1068-
const test: BrowserCommand<string> = function test(context, selector) {
1123+
const test: BrowserCommand<SerializedLocator> = function test(context, { selector }) {
10691124
// playwright
10701125
await context.iframe.locator(selector).click()
10711126
// webdriverio
@@ -1078,8 +1133,13 @@ import { test } from 'vitest'
10781133
import { commands, page } from 'vitest/browser'
10791134
10801135
test('works correctly', async () => {
1136+
<<<<<<< HEAD
10811137
await commands.test(page.getByText('Hello').selector) // ✅
10821138
// Vitest 会自动将其解包为字符串
1139+
=======
1140+
await commands.test(page.getByText('Hello').serialize()) // ✅
1141+
// vitest will automatically unwrap it to a SerializedLocator
1142+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
10831143
await commands.test(page.getByText('Hello')) // ✅
10841144
})
10851145
```

api/describe.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,24 @@ describe.concurrent('suite', () => {
208208
})
209209
```
210210

211+
<<<<<<< HEAD
211212
`.skip``.only``.todo` 适用于并发测试套件。以下所有组合都有效:
213+
=======
214+
Set `concurrent` to `false` to opt out of concurrency inherited from a parent suite or [`sequence.concurrent`](/config/sequence#sequence-concurrent):
215+
216+
```ts
217+
describe.concurrent('suite', () => {
218+
test('concurrent test', async () => { /* ... */ })
219+
220+
describe('sequential suite', { concurrent: false }, () => {
221+
test('sequential test 1', async () => { /* ... */ })
222+
test('sequential test 2', async () => { /* ... */ })
223+
})
224+
})
225+
```
226+
227+
`.skip`, `.only`, and `.todo` works with concurrent suites. All the following combinations are valid:
228+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
212229

213230
```ts
214231
describe.concurrent(/* ... */)
@@ -230,6 +247,7 @@ describe.concurrent('suite', () => {
230247
})
231248
```
232249

250+
<<<<<<< HEAD
233251
## describe.sequential
234252

235253
- **别名:** `suite.sequential`
@@ -250,6 +268,8 @@ describe.concurrent('suite', () => {
250268
})
251269
```
252270

271+
=======
272+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
253273
## describe.shuffle
254274

255275
- **别名:** `suite.shuffle`

api/test.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,21 @@ describe(
217217

218218
是否与测试套件中其他并发测试并行运行。
219219

220-
### sequential
220+
Set `concurrent` to `false` to opt out of concurrency inherited from [`describe.concurrent`](/api/describe#describe-concurrent) or [`sequence.concurrent`](/config/sequence#sequence-concurrent):
221221

222+
<<<<<<< HEAD
222223
- **类型:** `boolean`
223224
- **默认值:** `true`
224225
- **别名:** [`test.sequential`](#test-sequential)
225226

226227
是否按顺序运行测试。如果同时指定了 `concurrent``sequential``concurrent` 优先生效。
228+
=======
229+
```ts
230+
test('runs sequentially', { concurrent: false }, async () => {
231+
// ...
232+
})
233+
```
234+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
227235

228236
### skip
229237

@@ -453,6 +461,7 @@ test.concurrent('test 2', async ({ expect }) => {
453461

454462
注意,如果测试是同步的,Vitest 仍会按顺序运行它们。
455463

464+
<<<<<<< HEAD
456465
## test.sequential
457466

458467
- **别名:** `it.sequential`
@@ -478,6 +487,8 @@ describe.concurrent('suite', () => {
478487
})
479488
```
480489

490+
=======
491+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
481492
## test.todo
482493

483494
- **别名:** `it.todo`

config/attachmentsdir.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ outline: deep
55

66
# attachmentsDir
77

8+
<<<<<<< HEAD
89
- **类型:** `string`
910
- **默认值:** `'.vitest-attachments'`
11+
=======
12+
- **Type:** `string`
13+
- **Default:** `'.vitest/attachments'`
14+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
1015
1116
用于存储 [`context.annotate`](/guide/test-context#annotate) 所创建附件的目录路径(相对于项目根目录)。

config/browser/expect.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ export default defineConfig({
104104

105105
[`attachmentsDir`](/config/attachmentsdir) 配置项提供的值,如果未配置则使用其默认值。
106106

107+
<<<<<<< HEAD
107108
例如,以下示例按浏览器分组存储截图:
109+
=======
110+
- `project: TestProject` <Version type="experimental">4.1.6</Version> <Experimental />
111+
112+
The [`TestProject`](/api/advanced/test-project) the test belongs to.
113+
114+
For example, to group screenshots by browser:
115+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
108116
109117
```ts
110118
resolveScreenshotPath: ({ arg, browserName, ext, root, testFileName }) =>

config/coverage.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,19 @@ export default defineConfig({
457457
- **可用的测试提供者:** `'v8' | 'istanbul'`
458458
- **命令行终端:** `--coverage.changed`, `--coverage.changed=<commit/branch>`
459459

460+
<<<<<<< HEAD
460461
仅收集自指定提交或分支以来更改的文件的代码覆盖率。设置为 `true` 时,使用已暂存和未暂存的更改。
462+
=======
463+
Collect coverage only for files changed since a specified commit or branch. When set to `true`, it uses staged and unstaged changes.
464+
465+
## coverage.autoAttachSubprocess <Version>5.0.0</Version> {#coverage-autoattachsubprocess}
466+
467+
- **Type:** `boolean`
468+
- **Default:** `false`
469+
- **Available for providers:** `'v8'`
470+
- **CLI:** `--coverage.autoAttachSubprocess`
471+
472+
Track coverage of the `node:child_process` and `node:worker_threads` spawned during test run.
473+
474+
Note that this option has some performance overhead as its using [`NODE_V8_COVERAGE`](https://nodejs.org/api/cli.html#node-v8-coveragedir) internally. This triggers Node to write lots of unnecessary files on file system.
475+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a

config/reporters.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ interface UserConfig {
1414
type ConfigReporter = string | Reporter | [string, object?]
1515
```
1616
17+
<<<<<<< HEAD
1718
- **默认值:** [`'default'`](/guide/reporters#default-reporter)(当 `process.env.GITHUB_ACTIONS === 'true'` 时为 <code>[['default'](/guide/reporters#default-reporter), ['github-actions'](/guide/reporters#github-actions-reporter)]</code>)
1819
- **命令行终端:**
1920
- `--reporter=tap` 用于单个报告器
2021
- `--reporter=verbose --reporter=github-actions` 用于多个报告器
22+
=======
23+
- **Default:** [`'default'`](/guide/reporters#default-reporter). See [Default Reporters](/guide/reporters#default-reporters) for environment-specific behavior.
24+
- **CLI:**
25+
- `--reporter=tap` for a single reporter
26+
- `--reporter=verbose --reporter=github-actions` for multiple reporters
27+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
2128
2229
此选项定义在 Vitest 测试运行期间可用的单个报告器或报告器列表。
2330
@@ -49,16 +56,24 @@ type ConfigReporter = string | Reporter | [string, object?]
4956
5057
::: code-group
5158
```js [vitest.config.js]
52-
import { defineConfig } from 'vitest/config'
59+
import { configDefaults, defineConfig } from 'vitest/config'
5360

5461
export default defineConfig({
5562
test: {
5663
reporters: [
64+
<<<<<<< HEAD
5765
'default',
5866
// 条件报告器
5967
process.env.CI ? 'github-actions' : {},
6068
// 来自 npm 包的自定义报告器
6169
// 选项将以元组形式向下传递
70+
=======
71+
...configDefaults.reporters,
72+
// conditional reporter
73+
...(process.env.CI ? ['html'] : []),
74+
// custom reporter from npm package
75+
// options are passed down as a tuple
76+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
6277
[
6378
'vitest-sonar-reporter',
6479
{ outputFile: 'sonar-report.xml' }

guide/browser/visual-regression-testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ Reference screenshot:
276276
tests/__screenshots__/button.test.ts/button-chromium-darwin.png
277277
278278
Actual screenshot:
279-
tests/.vitest-attachments/button.test.ts/button-chromium-darwin-actual.png
279+
tests/.vitest/attachments/button.test.ts/button-chromium-darwin-actual.png
280280
281281
Diff image:
282-
tests/.vitest-attachments/button.test.ts/button-chromium-darwin-diff.png
282+
tests/.vitest/attachments/button.test.ts/button-chromium-darwin-diff.png
283283
```
284284

285285
### 如何解读差异图 {#understanding-the-diff-image}

guide/cli-generated.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ Coverage reporters to use. Visit [`coverage.reporter`](/config/coverage#coverage
299299

300300
UI 模式和 HTML 报告器中提供的 HTML 覆盖率输出目录。
301301

302+
### coverage.autoAttachSubprocess
303+
304+
- **CLI:** `--coverage.autoAttachSubprocess`
305+
- **Config:** [coverage.autoAttachSubprocess](/config/coverage#coverage-autoattachsubprocess)
306+
307+
Track coverage of the `node:child_process` and `node:worker_threads` spawned during test run. Supported only by `v8` provider. (default: false)
308+
302309
### mode
303310

304311
- **命令行终端:** `--mode <name>`
@@ -865,7 +872,11 @@ UI 模式和 HTML 报告器中提供的 HTML 覆盖率输出目录。
865872
- **命令行终端:** `--attachmentsDir <dir>`
866873
- **配置:** [attachmentsDir](/config/attachmentsdir)
867874

875+
<<<<<<< HEAD
868876
`context.annotate` 方法所生成附件的存储目录 (默认值: `.vitest-attachments`)
877+
=======
878+
The directory where attachments from `context.annotate` are stored in (default: `.vitest/attachments`)
879+
>>>>>>> ad185a835a130e727cdfb4ac909f05238364dc6a
869880
870881
### run
871882

0 commit comments

Comments
 (0)