Skip to content

Commit 0d00650

Browse files
committed
docs: update reporters guide
1 parent 5790931 commit 0d00650

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

docs/advanced/reporters.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,20 @@ 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.
21+
Of course, you can create your reporter from scratch. Just implement the `Reporter` interface:
2222

2323
And here is an example of a custom reporter:
2424

2525
```ts [custom-reporter.js]
26-
import { BaseReporter } from 'vitest/reporters'
27-
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:
37-
38-
```ts [custom-reporter.js]
39-
import type { Reporter } from 'vitest/node'
26+
import type { Reporter } from 'vitest/reporters'
4027

4128
export default class CustomReporter implements Reporter {
42-
onTestModuleCollected() {
43-
// print something
29+
onTestModuleCollected(testModule) {
30+
console.log(testModule.moduleId, 'is finished')
31+
32+
for (const test of testModule.children.allTests()) {
33+
console.log(test.name, test.result().state)
34+
}
4435
}
4536
}
4637
```
@@ -60,9 +51,7 @@ export default defineConfig({
6051

6152
## Reported Tasks
6253

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)`:
54+
Reported [events](/advanced/api/reporters) receive tasks for [tests](/advanced/api/test-case), [suites](/advanced/api/test-suite) and [modules](/advanced/api/test-module):
6655

6756
```ts twoslash
6857
import type { Reporter, TestModule } from 'vitest/node'
@@ -94,10 +83,6 @@ class MyReporter implements Reporter {
9483
7. `TapFlatReporter`
9584
8. `HangingProcessReporter`
9685

97-
### Base Abstract reporters:
98-
99-
1. `BaseReporter`
100-
10186
### Interface reporters:
10287

10388
1. `Reporter`

0 commit comments

Comments
 (0)