coverage.json contains a report object, which is a hash where keys are file names (absolute
paths), and values are coverage data for that file (the result of
json.stringify(collector.fileCoverageFor(filename))) Each entry consists of:
-
path- The path to the file. This is an absolute path, and should be the same as the key in the report object. -
s- Hash of statement counts, where keys as statement IDs. -
b- Hash of branch counts, where keys are branch IDs and values are arrays of counts. For an if statement, the value would have two counts; one for the if, and one for the else. Switch statements would have an array of values for each case. -
f- Hash of function counts, where keys are function IDs. -
fnMap- Hash of functions where keys are function IDs, and values are{name, line, loc, skip}, wherenameis the name of the function,lineis the line the function is declared on, andlocis theLocationof the function declaration (just the declaration, not the entire function body - see 'Location Objects' below.) Ifskipis present and true, then this indicates that this function was ignored by a### instabul ignore ... ###pragma. Note that if a function is not ignored theskipfield will be missing entirely. -
statementMap- Hash where keys are statement IDs, and values areLocationobjects for each statement. TheLocationfor a function definition is really an assignment, and should include the entire function. In addition to the normal location object fields, astatementMapentry can also have an optionalskipfield. -
branchMap- Hash where keys are branch IDs, and values are{line, type, locations}objects.lineis the line the branch starts on.typeis the type of the branch (e.g. "if", "switch").locationsis an array ofLocationobjects, one for each possible outcome of the branch. Note for anifstatement where there is noelseclause, there will still be twolocationsgenerated. Istanbul does not generate coverage for thedefaultcase of a switch statement ifdefaultis not explicitly present in the source code. -
l- Hash of line counts, where keys are the line number.locationsfor an if statement are always 0-length and located at the start of theif(even the location for the "else"). For aswitchstatement,locationsstart at the start of thecasestatement and go to the end of the line before the next case statement (note Istanbul does nothing clever here if acaseis missing abreak.) Each location inlocationscan also optionally have askip: truefield to indicate that this branch was ignored.
IDs used in the fnMap, statementMap, and branchMap are sequential integers, starting at 1.
Location objects are a {start: {line, column}, end: {line, column}} object that describes
the start and end of a piece of code. Note that line is 1-based, but column is 0-based.