Skip to content

Commit 8ed3cc7

Browse files
authored
docs: update reporters guide (#8524)
1 parent aa9fc38 commit 8ed3cc7

1 file changed

Lines changed: 13 additions & 24 deletions

File tree

docs/guide/advanced/reporters.md

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This is an advanced API. If you just want to configure built-in reporters, read the ["Reporters"](/guide/reporters) guide.
55
:::
66

7-
You can import reporters from `vitest/reporters` and extend them to create your custom reporters.
7+
You can import reporters from `vitest/node` and extend them to create your custom reporters.
88

99
## Extending Built-in Reporters
1010

@@ -18,29 +18,24 @@ export default class MyDefaultReporter extends DefaultReporter {
1818
}
1919
```
2020

21-
Of course, you can create your reporter from scratch. Just extend the `BaseReporter` class and implement the methods you need.
22-
23-
And here is an example of a custom reporter:
21+
::: warning
22+
However, note that exposed reports are not considered stable and can change the shape of their API within a minor version.
23+
:::
2424

25-
```ts [custom-reporter.js]
26-
import { BaseReporter } from 'vitest/node'
25+
Of course, you can create your reporter from scratch. Just implement the [`Reporter`](/api/advanced/reporters) interface:
2726

28-
export default class CustomReporter extends BaseReporter {
29-
onTestModuleCollected() {
30-
const files = this.ctx.state.getFiles(this.watchFilters)
31-
this.reportTestSummary(files)
32-
}
33-
}
34-
```
35-
36-
Or implement the `Reporter` interface:
27+
And here is an example of a custom reporter:
3728

3829
```ts [custom-reporter.js]
3930
import type { Reporter } from 'vitest/node'
4031

4132
export default class CustomReporter implements Reporter {
42-
onTestModuleCollected() {
43-
// print something
33+
onTestModuleCollected(testModule) {
34+
console.log(testModule.moduleId, 'is finished')
35+
36+
for (const test of testModule.children.allTests()) {
37+
console.log(test.name, test.result().state)
38+
}
4439
}
4540
}
4641
```
@@ -60,9 +55,7 @@ export default defineConfig({
6055

6156
## Reported Tasks
6257

63-
Instead of using the tasks that reporters receive, it is recommended to use the Reported Tasks API instead.
64-
65-
You can get access to this API by calling `vitest.state.getReportedEntity(runnerTask)`:
58+
Reported [events](/api/advanced/reporters) receive tasks for [tests](/api/advanced/test-case), [suites](/api/advanced/test-suite) and [modules](/api/advanced/test-module):
6659

6760
```ts twoslash
6861
import type { Reporter, TestModule } from 'vitest/node'
@@ -95,10 +88,6 @@ class MyReporter implements Reporter {
9588
8. `HangingProcessReporter`
9689
9. `TreeReporter`
9790

98-
### Base Abstract reporters:
99-
100-
1. `BaseReporter`
101-
10291
### Interface reporters:
10392

10493
1. `Reporter`

0 commit comments

Comments
 (0)