interface ReporterContext

What a reporter is given on every hook: where to write, what the run has counted so far, and the few resolved paths a message needs.

Deliberately not the run's Config. A reporter is third-party code, and handing it the whole config would hand it the mutable state of the run it is reporting on — plus a type it cannot name, since Config is internal. Everything here is read-only from a reporter's side.

counts and sourceMapDecoder are live: counts is the same object the runner mutates, and the decoder arrives partway through a run, so both read through rather than being snapshots.

// Defined, not invoked: a reporter that prints a running tally.
const tally = {
  onTestEnd({ console, counts }: ReporterContext) {
    console.log(`# ${counts.passed}/${counts.total}\n`);
  },
};
tally.onTestEnd.length; // 1 — the context is the only thing a simple reporter needs

Properties

console: Console

Where this reporter's text goes. silentConsole when the run was asked to print nothing.

counts: Counter

The run's live outcome totals — the same object the runner updates, not a copy.

projectRoot: string

Absolute path of the directory holding package.json, for rendering paths relative to it.

output: string

Absolute path of the build output directory.

optional
junit: boolean | string

--junit's value: true for the default path, a string for an explicit one.

sourceMapDecoder: SourceMapDecoder | null

Maps a bundle stack frame back to source, once the run has built one.

daemon: boolean

Whether this run is executing inside the persistent daemon.

Usage

import { type ReporterContext } from "lib/api/index.ts";