diff --git a/docs/advanced/reporters.md b/docs/advanced/reporters.md index b75f080db2e5..e957f4b4ffb5 100644 --- a/docs/advanced/reporters.md +++ b/docs/advanced/reporters.md @@ -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) + } } } ``` @@ -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' @@ -94,10 +83,6 @@ class MyReporter implements Reporter { 7. `TapFlatReporter` 8. `HangingProcessReporter` -### Base Abstract reporters: - -1. `BaseReporter` - ### Interface reporters: 1. `Reporter`