Created
February 23, 2021 15:21
-
-
Save dallonf/7ddb5008375d96db4d2572450fa6bd75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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