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.tsimport { BettererContext, BettererReporter, BettererSummaries } from '@betterer/betterer';import { BettererError } from '@betterer/errors';import { promises as fs } from 'fs';
export const reporter: BettererReporter = createHTMLReporter();
function createHTMLReporter(): BettererReporter {  return {    contextEnd(_: BettererContext, summaries: BettererSummaries): Promise<void> {      return fs.writeFile('report.html', renderHTMLTemplate(summaries), 'utf8');    },    contextError(_: BettererContext, error: BettererError): void {      console.log(error);    }  };}
function renderHTMLTemplate(summaries: BettererSummaries): string {  // ...}

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

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