1.0.2 • Published 4 years ago

read-lcov-safe v1.0.2

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

Read and parse an lcov file without try catch.

Installation

yarn add read-lcov-safe
npm install read-lcov-safe

API

Usage

import {
  readLCOV,
  readLCOVSync,
  LCOVRecord,
  FunctionsDetails,
  BranchesDetails,
  LinesDetails
} from "read-lcov-safe";

readLCOV(path).then((lcov) => {
  console.log(lcov);
  // Example output:
  // [{
  //   title: "",
  //   file: "source/file.ts",
  //   functions: {
  //     found: 2,
  //     hit: 2,
  //     details: [{
  //       line: 5,
  //       hit: 2,
  //       name: "functionA"
  //     }, {
  //       hit: 16,
  //       line: 8,
  //       name: "functionB"
  //     }]
  //   },
  //   branches: {
  //     found: 3,
  //     hit: 3,
  //     details: [{
  //       block: 0,
  //       branch: 0,
  //       line: 5,
  //       taken: 1
  //     }, {
  //       block: 1,
  //       branch: 0,
  //       line: 9,
  //       taken: 0
  //     }]
  //   },
  //   lines: {
  //     found: 13,
  //     hit: 13,
  //     details: [{
  //       hit: 1,
  //       line: 1
  //     }]
  //   }
  // }]
});

Types

import { readLCOV, readLCOVSync } from "read-lcov-safe";

function readLCOV(path: string): Promise<LCOVRecord[]>;

function readLCOVSync(path: string): LCOVRecord[];

type LCOVRecord = {
  title: string;
  file: string;
  functions: LCOVStats & {
    details: FunctionsDetails[];
  };
  branches: LCOVStats & {
    details: BranchesDetails[];
  };
  lines: LCOVStats & {
    details: LinesDetails[];
  };
}

type LCOVStats = {
  found: number;
  hit: number;
}

type FunctionsDetails = {
  name: string;
  line: number;
  hit?: number;
}

type BranchesDetails = {
  line: number;
  block: number;
  branch: number;
  taken: number;
};

type LinesDetails = {
  line: number;
  hit: number;
}

MIT