Skip to content

Instantly share code, notes, and snippets.

@dallonf
Created February 23, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dallonf/7ddb5008375d96db4d2572450fa6bd75 to your computer and use it in GitHub Desktop.
Save dallonf/7ddb5008375d96db4d2572450fa6bd75 to your computer and use it in GitHub Desktop.
import * as fs from "fs";
const coverage = JSON.parse(
fs.readFileSync("coverage/coverage-final.json", "utf-8")
);
const output = Object.values(coverage).map((x) => {
const path = x.path;
const totalStatements = Object.keys(x.statementMap).length;
const coveredStatements = Object.entries(x.s).filter(
([statementId, callCount]) => callCount > 0
).length;
const uncoveredStatements = totalStatements - coveredStatements;
return {
path,
totalStatements,
coveredStatements,
uncoveredStatements,
};
});
const fileHandle = fs.openSync("./something.csv", "w");
try {
fs.writeSync(
fileHandle,
"Path,Total Statements,Covered Statements,Uncovered Statements\n"
);
output.forEach((x) => {
fs.writeSync(
fileHandle,
[
x.path,
x.totalStatements,
x.coveredStatements,
x.uncoveredStatements,
].join(",") + "\n"
);
});
} finally {
fs.closeSync(fileHandle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment