UNPKG

histoire

Version:

A fast story book powered by Vite

26 lines (25 loc) • 1.07 kB
/** * Vitest options appending a reporter that reports finished specs (test modules), to spread * after the run options. Each attempt restarts the count. Without a listener it is empty, * since an explicit `reporters: undefined` breaks Vitest config resolution. * @param reporters Reporters configured for the run; Vitest's `default` when absent. * @param total Number of specs in the run. * @param onProgress Receives counts after the run starts and after every finished spec. */ export function progressReporterOptions(reporters, total, onProgress) { if (!onProgress) return {}; let completed = 0; const reporter = { onTestRunStart() { completed = 0; onProgress({ completed, total }); }, onTestModuleEnd() { completed = Math.min(completed + 1, total); onProgress({ completed, total }); }, }; const configured = reporters === undefined ? ['default'] : Array.isArray(reporters) ? reporters : [reporters]; return { reporters: [...configured, reporter] }; }