new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vitest · Guide · all subjects

reporters/extending

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Import reporters from vitest/node

Reporters can be imported from 'vitest/node' and extended to create custom reporters.

Extend DefaultReporter for custom reporters

You can extend the DefaultReporter class from 'vitest/node' to create a custom reporter. Example: import { DefaultReporter } from 'vitest/node'; export default class MyDefaultReporter extends DefaultReporter { }

Built-in reporters are not stable

Exposed reporters are not considered stable and can change the shape of their API within a minor version.

Custom reporter example with onTestModuleCollected

Example of a custom reporter implementing the Reporter interface: import type { Reporter } from 'vitest/node'; export default class CustomReporter implements Reporter { onTestModuleCollected(testModule) { console.log(testModule.moduleId, 'is finished'); for (const test of testModule.children.allTests()) { console.log(test.name, test.result().state) } } }

Configure custom reporter in vitest.config.ts

Custom reporters are configured in vitest.config.ts using the test.reporters array: import { defineConfig } from 'vitest/config'; import CustomReporter from './custom-reporter.js'; export default defineConfig({ test: { reporters: [new CustomReporter()], }, })

Reporter events receive tasks for tests, suites and modules

Reported events receive tasks for tests, suites, and modules. The onTestRunEnd event receives an array of TestModule objects, and each module has a children property that contains tasks with properties like type and fullName.

Use .vitest directory for reporter artifacts

Custom reporters should store artifacts in the .vitest directory at the project root. Each reporter should create its own subdirectory inside .vitest (e.g., .vitest/yaml-reporter/). Reporters can create the .vitest directory if it does not exist, but should never remove it. Reporters can only remove their own specific subdirectories.

vitest.createReport utility for artifacts

Vitest provides vitest.createReport that exposes a collection of utilities for writing artifacts on the file system conveniently.

Built-in reporters list

Vitest comes with nine built-in reporters: DefaultReporter, DotReporter, JsonReporter, VerboseReporter, TapReporter, JUnitReporter, TapFlatReporter, HangingProcessReporter, and TreeReporter.

Reporter interface available

The Reporter interface is available for import from 'vitest/node' to create custom reporters from scratch.

Give your agent this brain