UNPKG

1.64 kBPlain TextView Raw
1import { MutantResult } from '@stryker-mutator/api/core';
2import { MutationTestingPlanReadyEvent } from '@stryker-mutator/api/src/report';
3
4import { progressBarWrapper } from './progress-bar.js';
5import { ProgressKeeper } from './progress-keeper.js';
6
7export class ProgressBarReporter extends ProgressKeeper {
8 private progressBar?: ProgressBar;
9
10 public onMutationTestingPlanReady(event: MutationTestingPlanReadyEvent): void {
11 super.onMutationTestingPlanReady(event);
12 const progressBarContent =
13 'Mutation testing [:bar] :percent (elapsed: :et, remaining: :etc) :tested/:mutants Mutants tested (:survived survived, :timedOut timed out)';
14
15 this.progressBar = new progressBarWrapper.ProgressBar(progressBarContent, {
16 complete: '=',
17 incomplete: ' ',
18 stream: process.stdout,
19 total: this.progress.total,
20 width: 50,
21 });
22 }
23
24 public onMutantTested(result: MutantResult): number {
25 const ticks = super.onMutantTested(result);
26
27 const progressBarContent = { ...this.progress, et: this.getElapsedTime(), etc: this.getEtc() };
28 if (ticks) {
29 this.tick(ticks, progressBarContent);
30 } else {
31 this.render(progressBarContent);
32 }
33 return ticks;
34 }
35
36 private tick(ticks: number, tickObj: ProgressState): void {
37 this.progressBar?.tick(ticks, tickObj);
38 }
39
40 private render(renderObj: ProgressState): void {
41 if (this.progressBar?.total) {
42 this.progressBar.render(renderObj);
43 }
44 }
45}
46
47interface ProgressState {
48 et: string;
49 etc: string;
50 survived: number;
51 timedOut: number;
52 tested: number;
53 mutants: number;
54 total: number;
55 ticks: number;
56}