44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import type { CoverageReport, ReporterType } from '../types';
|
|
import { HtmlReporter } from './html';
|
|
import { HtmlCompactReporter } from './html-compact';
|
|
import { JsonReporter } from './json';
|
|
import { MarkdownReporter } from './markdown';
|
|
import { TerminalReporter } from './terminal';
|
|
import { TextReporter } from './text';
|
|
|
|
export class ReporterManager {
|
|
private reporters: Partial<
|
|
Record<ReporterType, { report(report: CoverageReport, outputDir?: string): void }>
|
|
> = {
|
|
terminal: new TerminalReporter(),
|
|
json: new JsonReporter(),
|
|
markdown: new MarkdownReporter(),
|
|
html: new HtmlCompactReporter(), // Use compact HTML by default
|
|
'html-full': new HtmlReporter(), // Keep full HTML as option
|
|
text: new TextReporter(),
|
|
};
|
|
|
|
async report(
|
|
coverage: CoverageReport,
|
|
reporters: ReporterType[],
|
|
outputDir: string
|
|
): Promise<void> {
|
|
for (const reporterType of reporters) {
|
|
try {
|
|
const reporter = this.reporters[reporterType];
|
|
if (!reporter) {
|
|
console.warn(`Unknown reporter type: ${reporterType}`);
|
|
continue;
|
|
}
|
|
|
|
if (reporterType === 'terminal') {
|
|
reporter.report(coverage);
|
|
} else {
|
|
reporter.report(coverage, outputDir);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error running ${reporterType} reporter:`, error);
|
|
}
|
|
}
|
|
}
|
|
}
|