interface Reporter

The reporter contract — the public extension point for observing a run. Reporters render it to text (the built-in tap/spec/dot/github), write an artifact (junit), or simply collect, which is how the JS API turns a run into a value.

Every method is optional, so a reporter is any object carrying the handlers it cares about.

Lifecycle: onRunStart → (onTestEnd | onNotice | onBrowserLog)* → onRunEnd. In watch mode the whole cycle repeats per rerun, so stateful reporters must reset in onRunStart.

Concurrency: one reporter instance is shared across all concurrent groups (the group configs are spread off the parent config, so state.reporters is the same array). onTestEnd therefore arrives interleaved across groups.

Text goes through context.console, never process.stdout — that indirection is what lets a caller redirect or silence a built-in reporter.

const names: string[] = [];
const reporter: Reporter = {
  onTestEnd(_context, details) {
    names.push(details.fullName.join(' | ')); // one entry per finished test
  },
};
reporter.onTestEnd?.({} as ReporterContext, { status: 'passed', fullName: ['Math', 'adds'], runtime: 2 });
names; // ['Math | adds']

Methods

optional
onRunStart(): void

Called once before any test output. In watch mode, once per rerun.

optional
onTestEnd(
context: ReporterContext,
details: TestDetails
): void

Called once per test, after counter has already been updated for this test.

optional
onRunEnd(): void | Promise<void>

Called once when the run finishes, with the final counts on config.state.results.counter.

optional
onNotice(
context: ReporterContext,
notice: Notice
): void

Called for each of qunitx's own diagnostics — the # … lines about what it decided to run, what it could not find, what timed out. The default rendering has already gone to config.state.console; implement this only to capture them as data.

optional
onBrowserLog(): void

Called for each console.* call and uncaught error from the page under test. Only warnings and errors arrive unless debug is on — the same selection the CLI prints.

Usage

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