Skip to content

Instantly share code, notes, and snippets.

@keksipurkki
Created November 26, 2021 10:01
Show Gist options
  • Save keksipurkki/8263012b921021134645bf50241b63a0 to your computer and use it in GitHub Desktop.
Save keksipurkki/8263012b921021134645bf50241b63a0 to your computer and use it in GitHub Desktop.
Parse Junit.xml with JS
#!/usr/bin/env node
const Parser = require("junitxml-to-javascript");
function countErrors(testsuites) {
let errors = 0;
for (const testsuite of testsuites) {
errors += testsuite.errors;
}
return errors;
}
async function main(...junitReports) {
for (const junit of junitReports) {
const parser = new Parser();
const { testsuites } = await parser.parseXMLFile(junit);
const errors = countErrors(testsuites);
console.log(`${junit}: ${errors} errors, ${errors ? "FAIL" : "PASS"}`);
}
}
main(...process.argv.slice(2)).catch((error) => {
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment