All files / src/utils/parsers accumulator.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        2x                               30x       30x       2x              
import { number } from '../numbers';
import type { Results } from './base';
 
export class CoverageAccumulator {
  private coverage = {
    lines: {
      total: 0,
      hit: 0,
    },
    functions: {
      total: 0,
      hit: 0,
    },
    branches: {
      total: 0,
      hit: 0,
    },
  };
 
  public hit(type: keyof typeof this.coverage, value: number | string): void {
    this.coverage[type].hit += number(value, 0);
  }
 
  public total(type: keyof typeof this.coverage, value: number | string): void {
    this.coverage[type].total += number(value, 0);
  }
 
  public toResults(): Results {
    return {
      lines: this.coverage.lines.hit / this.coverage.lines.total,
      functions: this.coverage.functions.hit / this.coverage.functions.total,
      branches: this.coverage.branches.hit / this.coverage.branches.total,
    };
  }
}