Skip to content

Commit 6ec637b

Browse files
committed
docs(en): merging all conflicts
2 parents a981f33 + ec964f3 commit 6ec637b

45 files changed

Lines changed: 1017 additions & 39 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ export default ({ mode }: { mode: string }) => {
807807
link: '/guide/browser/trace-view',
808808
docFooterText: '追踪查看器 | 浏览器模式',
809809
},
810+
{
811+
text: 'Playwright Traces',
812+
link: '/guide/browser/playwright-traces',
813+
docFooterText: 'Playwright Traces | Browser Mode',
814+
},
810815
{
811816
text: 'ARIA Snapshots',
812817
link: '/guide/browser/aria-snapshots',

api/advanced/vitest.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ function start(filters?: string[]): Promise<TestRunResult>
244244
function standalone(): Promise<void>
245245
```
246246

247+
<<<<<<< HEAD
247248
- **别名:**: `init` <Deprecated />
249+
=======
250+
- **Alias:** `init` <Deprecated />
251+
>>>>>>> ec964f36ce7596a023a32b8265f6019c51b32926
248252

249253
初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 `--watch` 标志,Vitest 仍将运行更改的测试,即使未调用此方法。
250254

@@ -696,3 +700,122 @@ export interface SourceModuleDiagnostic {
696700
::: warning
697701
[浏览器模式](/guide/browser/) 暂不支持。
698702
:::
703+
704+
## createReport <Version>5.0.0</Version> {#createreport}
705+
706+
```ts
707+
function createReport(scope: string): Report
708+
```
709+
710+
Creates a report that is limited to the given scope. `Report` follows Vitest's rules around [Storing artifacts on file system](/guide/advanced/reporters.html#storing-artifacts-on-file-system).
711+
712+
`Report` provides collection of utilities for writing test results, temporary files and other artifacts on the file system. It's especially intended for third party integrations like custom reporters.
713+
714+
All operations of `Report` are limited to given `scope`. A single report cannot interfere with other reports. Internally Vitest creates `.vitest` directory where each `scope` creates their own directory. This convention of `.vitest` directory reduces the amount of entries end-users need to specify in their `.gitignore`.
715+
716+
```ts
717+
import type { Report } from 'vitest/node'
718+
719+
const scope = 'example-yaml-reporter'
720+
721+
// Automatically creates `<project-root>/.vitest/example-yaml-reporter/`
722+
// directory if it does not exist already
723+
const report: Report = vitest.createReport(scope)
724+
```
725+
726+
### Report.root
727+
728+
```ts
729+
const root: string
730+
```
731+
732+
The root directory for this scope.
733+
734+
```ts
735+
const report = vitest.createReport('my-json-reporter')
736+
737+
// Is <project-root>/.vitest/my-json-reporter
738+
const root = report.root
739+
```
740+
741+
742+
### Report.clean
743+
744+
```ts
745+
function clean(): Promise<void>
746+
```
747+
748+
Clean up the report directory for this scope.
749+
750+
```ts
751+
const report = vitest.createReport('my-json-reporter')
752+
753+
// Removes everything inside <project-root>/.vitest/my-json-reporter/
754+
await report.clean()
755+
```
756+
757+
### Report.writeFile
758+
759+
```ts
760+
function writeFile(
761+
filename: string,
762+
content: string | Uint8Array,
763+
encoding?: BufferEncoding
764+
): Promise<void>
765+
```
766+
767+
Write a file to the report directory for this scope. By default the file will be written with UTF-8 encoding. The filename is relative to the scope directory.
768+
769+
```ts
770+
const report = vitest.createReport('my-json-reporter')
771+
772+
// Writes file to .vitest/my-json-reporter/test-report.json
773+
await report.writeFile('test-report.json', JSON.stringify(results))
774+
```
775+
776+
### Report.readFile
777+
778+
```ts
779+
function readFile(filename: string, encoding?: BufferEncoding): Promise<string>
780+
```
781+
782+
Read a file from the report directory for this scope.
783+
784+
```ts
785+
const report = vitest.createReport('my-json-reporter')
786+
787+
// Reads file from .vitest/my-json-reporter/test-report.json
788+
const content: string = await report.readFile('test-report.json')
789+
```
790+
791+
### Report.readdir
792+
793+
```ts
794+
function readdir(): Promise<string[]>
795+
```
796+
797+
Read contents of the report directory for this scope.
798+
799+
```ts
800+
const report = vitest.createReport('my-json-reporter')
801+
802+
// Reads contents from .vitest/my-json-reporter
803+
const filenames: string[] = await report.readdir()
804+
```
805+
806+
### Report.delete
807+
808+
<!-- eslint-skip -->
809+
```ts
810+
function delete(filename: string): Promise<void>
811+
```
812+
813+
Delete a file from the report directory for this scope.
814+
815+
```ts
816+
const report = vitest.createReport('my-json-reporter')
817+
818+
// Deletes file from .vitest/my-json-reporter/test-report.json
819+
await report.delete('test-report.json')
820+
```
821+

api/assert.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ test('assert.fail', () => {
3535

3636
## isOk
3737

38+
<<<<<<< HEAD
3839
- **类型:** `<T>(value: T, message?: string) => asserts value`
3940
- **Alias** `ok`
41+
=======
42+
- **Type:** `<T>(value: T, message?: string) => asserts value`
43+
- **Alias:** `ok`
44+
>>>>>>> ec964f36ce7596a023a32b8265f6019c51b32926
4045
4146
断言给定的 `value` 是 true 。
4247

@@ -51,8 +56,13 @@ test('assert.isOk', () => {
5156

5257
## isNotOk
5358

59+
<<<<<<< HEAD
5460
- **类型:** `<T>(value: T, message?: string) => void`
5561
- **Alias** `notOk`
62+
=======
63+
- **Type:** `<T>(value: T, message?: string) => void`
64+
- **Alias:** `notOk`
65+
>>>>>>> ec964f36ce7596a023a32b8265f6019c51b32926
5666
5767
断言给定的 `value` 是 false 。
5868

api/browser/context.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ export const utils: {
267267
* Creates "Cannot find element" error. Useful for custom locators.
268268
*/
269269
getElementError(selector: string, container?: Element): Error
270+
/**
271+
* Utilities for generating and working with ARIA trees and templates.
272+
* @experimental
273+
*/
274+
aria: {
275+
generateAriaTree(rootElement: Element): AriaNode
276+
renderAriaTree(root: AriaNode): string
277+
renderAriaTemplate(template: AriaTemplateNode): string
278+
parseAriaTemplate(text: string): AriaTemplateNode
279+
matchAriaTree(root: AriaNode, template: AriaTemplateNode): { pass: boolean; resolved: string }
280+
}
270281
}
271282
```
272283

@@ -337,3 +348,22 @@ utils.configurePrettyDOM({
337348
::: tip
338349
This feature is inspired by Testing Library's [`defaultIgnore`](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaultignore) configuration.
339350
:::
351+
352+
### aria <Version type="experimental">5.0.0</Version> {#aria}
353+
354+
The `aria` namespace exposes low-level utilities used by Vitest's ARIA snapshot matchers.
355+
356+
```ts
357+
import { utils } from 'vitest/browser'
358+
359+
document.body.innerHTML = `
360+
<h1>Hello, World!</h1>
361+
<button aria-hidden="true">Hidden</button>
362+
<button>Visible</button>
363+
`
364+
const tree = utils.aria.generateAriaTree(document.body)
365+
const yaml = utils.aria.renderAriaNode(tree)
366+
console.log(yaml)
367+
// - heading "Hello, World!" [level=1]
368+
// - button "Visible""
369+
```

0 commit comments

Comments
 (0)