Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions docs/advanced/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,20 @@ export default class MyDefaultReporter extends DefaultReporter {
}
```

Of course, you can create your reporter from scratch. Just extend the `BaseReporter` class and implement the methods you need.
Of course, you can create your reporter from scratch. Just implement the `Reporter` interface:

And here is an example of a custom reporter:

```ts [custom-reporter.js]
import { BaseReporter } from 'vitest/reporters'

export default class CustomReporter extends BaseReporter {
onTestModuleCollected() {
const files = this.ctx.state.getFiles(this.watchFilters)
this.reportTestSummary(files)
}
}
```

Or implement the `Reporter` interface:

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

export default class CustomReporter implements Reporter {
onTestModuleCollected() {
// print something
onTestModuleCollected(testModule) {
console.log(testModule.moduleId, 'is finished')

for (const test of testModule.children.allTests()) {
console.log(test.name, test.result().state)
}
}
}
```
Expand All @@ -60,9 +51,7 @@ export default defineConfig({

## Reported Tasks

Instead of using the tasks that reporters receive, it is recommended to use the Reported Tasks API instead.

You can get access to this API by calling `vitest.state.getReportedEntity(runnerTask)`:
Reported [events](/advanced/api/reporters) receive tasks for [tests](/advanced/api/test-case), [suites](/advanced/api/test-suite) and [modules](/advanced/api/test-module):

```ts twoslash
import type { Reporter, TestModule } from 'vitest/node'
Expand Down Expand Up @@ -94,10 +83,6 @@ class MyReporter implements Reporter {
7. `TapFlatReporter`
8. `HangingProcessReporter`

### Base Abstract reporters:

1. `BaseReporter`

### Interface reporters:

1. `Reporter`