JUnit XML to JavaScript Parser

1.1.4 · maintenance · verified Sun Apr 19

The `junitxml-to-javascript` package, currently at version 1.1.4, is a Node.js library designed for parsing JUnit XML report files or strings into structured JavaScript objects. It provides a flexible API that allows for custom modification functions to preprocess the raw XML object (initially parsed by `xml2js-parser`) before the final transformation, making it adaptable to various non-standard JUnit XML formats. The package primarily uses CommonJS `require` syntax and has an `engines.node` requirement of `>=8.2.1`, suggesting it is an older project. Its release cadence is not active, and the package appears to be in a maintenance or abandoned state. Its key differentiator is the `modifier` option, enabling deep customization of the parsing logic for specific XML structures.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a JUnit XML report from both a string and a local file, logging the resulting JavaScript object to the console. It includes cleanup for the temporary file.

const Parser = require("junitxml-to-javascript");
const fs = require('fs');
const path = require('path');

const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="MyTestSuit" errors="0" tests="2" failures="0" skipped="0"
timestamp="2023-01-01T12:00:00+0000" time="10.5">
    <properties>
        <property name="build.id" value="123"/>
    </properties>
    <testcase classname="com.example.TestA" name="shouldPass" time="5.2"/>
    <testcase classname="com.example.TestB" name="shouldAlsoPass" time="5.3"/>
</testsuite>`;

console.log('Parsing XML string...');
new Parser()
    .parseXMLString(xmlString)
    .then(report => {
        console.log('--- Parsed XML String Output ---');
        console.log(JSON.stringify(report, null, 2));
    })
    .catch(err => console.error('Error parsing string:', err.message));

// Demonstrating file parsing (requires creating a dummy file)
const tempFilePath = path.join(__dirname, 'temp_junit_report.xml');
fs.writeFileSync(tempFilePath, xmlString, 'utf8');

console.log('\nParsing XML file...');
new Parser({ customTag: "CI_BUILD" })
    .parseXMLFile(tempFilePath)
    .then(report => {
        console.log('--- Parsed XML File Output ---');
        console.log(JSON.stringify(report, null, 2));
    })
    .catch(err => console.error('Error parsing file:', err.message))
    .finally(() => {
        // Clean up the temporary file
        fs.unlinkSync(tempFilePath);
        console.log('Temporary file cleaned up.');
    });

view raw JSON →