class APIReporter
implements Reporter
The reporter that turns a run into a value: it records what happened instead of printing it.
Attached by the JS API to every run, alongside whatever reporters the caller asked for — so
reporter: 'tap' still streams TAP and still resolves with a full RunResult.
import type { ReporterContext } from '../reporters/types.ts'; const reporter = new APIReporter(); reporter.onTestEnd({} as ReporterContext, { status: 'passed', fullName: ['Math', 'adds'], runtime: 2 }); reporter.tests[0].fullName; // 'Math: adds'
readonly
browserLogs: BrowserLog[]
The most recent page console calls and uncaught errors, capped at MAX_BROWSER_LOGS.
browserLogsDropped: number
How many page-log entries the cap dropped.
readonly
tests: TestResult[]
Every finished test, in arrival order.
onBrowserLog(_context: ReporterContext,log: BrowserLog): void
Records one page console call or uncaught error.
import type { ReporterContext } from '../reporters/types.ts'; const reporter = new APIReporter(); reporter.onBrowserLog({} as ReporterContext, { type: 'error', text: 'boom', args: [] }); reporter.browserLogs[0].text; // 'boom'
onNotice(_context: ReporterContext,notice: Notice): void
Records one diagnostic.
import type { ReporterContext } from '../reporters/types.ts'; const reporter = new APIReporter(); reporter.onNotice({} as ReporterContext, { level: 'warning', message: 'No tests matched' }); reporter.notices[0].level; // 'warning'
onTestEnd(_context: ReporterContext,details: TestDetails): void
Records one finished test.
import type { ReporterContext } from '../reporters/types.ts'; const reporter = new APIReporter(); reporter.onTestEnd({} as ReporterContext, { status: 'failed', fullName: ['Cart', 'adds'], runtime: 4 }); reporter.tests[0].status; // 'failed'
reset(): void
Drops everything from a previous run. Watch sessions reuse one collector across reruns, so this is what keeps rerun N's result from containing rerun N-1's tests.
const reporter = new APIReporter(); reporter.notices.push({ level: 'info', message: 'stale' }); reporter.reset(); reporter.notices.length; // 0