All files / src coverage-summary.ts

76.92% Statements 10/13
83.33% Branches 15/18
100% Functions 4/4
75% Lines 9/12

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 37                        230x       184x       23x   23x 23x 92x   23x 23x             23x    
export interface CoverageMetric {
  readonly pct: number;
}
 
export interface CoverageSummary {
  readonly statements: CoverageMetric;
  readonly branches: CoverageMetric;
  readonly functions: CoverageMetric;
  readonly lines: CoverageMetric;
}
 
function isRecord(value: unknown): value is Record<string, unknown> {
  return typeof value === "object" && value !== null;
}
 
function isCoverageMetric(value: unknown): value is CoverageMetric {
  return isRecord(value) && typeof value.pct === "number";
}
 
export function parseCoverageSummary(value: unknown): CoverageSummary {
  Iif (!isRecord(value) || !("total" in value))
    throw new Error("coverage summary does not contain total metrics");
  const total = value.total;
  const names = ["statements", "branches", "functions", "lines"] as const;
  Iif (!isRecord(total) || !names.every((name) => isCoverageMetric(total[name])))
    throw new Error("coverage summary has invalid total metrics");
  const { statements, branches, functions, lines } = total;
  Iif (
    !isCoverageMetric(statements) ||
    !isCoverageMetric(branches) ||
    !isCoverageMetric(functions) ||
    !isCoverageMetric(lines)
  )
    throw new Error("coverage summary has invalid total metrics");
  return { statements, branches, functions, lines };
}