Skip to main content

Reporters

Default reporter

Betterer has a reporter system for hooking into the test runner. The default reporter lives in it's own package (@betterer/reporter), and uses Ink for fancy terminal output:

Custom reporters

If you want to write your own reporter, you need to implement the BettererReporter API and export an instance from a JavaScript module:

// src/html-reporter.ts
import { BettererContext, BettererContextSummary, BettererReporter } from '@betterer/betterer';
import { BettererError } from '@betterer/errors';
import { promises as fs } from 'node:fs';

export const reporter: BettererReporter = createHTMLReporter();

function createHTMLReporter(): BettererReporter {
return {
contextEnd(contextSummary: BettererContextSummary): Promise<void> {
return fs.writeFile('report.html', renderHTMLTemplate(contextSummary), 'utf8');
},
contextError(_: BettererContext, error: BettererError): void {
console.log(error);
}
};
}

function renderHTMLTemplate(contextSummary: BettererContextSummary): string {
// ...
}

You can then use the --reporter option when you run Betterer:

yarn betterer --reporter ./src/html-reporter