npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

junitxml-to-javascript

v1.1.4

Published

Pluggable jUnit XML reports parser to JavaScript objects

Downloads

137,118

Readme

junitxml-to-javascript

Pluggable jUnit XML reports parser to JavaScript objects

Installation

npm install junitxml-to-javascript

Usage

Parsing XML report file

const Parser = require("junitxml-to-javascript");
new Parser({customTag: "GENERAL1"})
    .parseXMLFile("/tmp/passed.xml")
    .then(report => console.log(JSON.stringify(report, null, 2)))
    .catch(err => console.error(e.message))
    

Parsing XML report string

const Parser = require("junitxml-to-javascript");
new Parser({customTag: "GENERAL1"})
    .parseXMLString(`<?xml version="1.0" encoding="UTF-8"?>
        <testsuite name="1my.package.class.Something" errors="0" test="5" failures="0" skipped="0"
        timestamp="20171206T181624+0100" time="116.716">
            <properties></properties>
            <testcase classname="1my.package.class.Something" name="test00Monitoring" time="0.150">
                <system-out>
                </system-out>
            </testcase>
            <testcase classname="1my.package.class.Something" name="test01CreateJob" time="43.254">
                <system-out>
                </system-out>
            </testcase>
        </testsuite>`)
    .then(e => console.log(JSON.stringify(e, null, 2)))
    .catch(e => console.error(e.message))

Sample output

{
  "testsuites": [
    {
      "name": "1my.package.class.Something",
      "timestamp": 1512580584000,
      "properties": [],
      "testCases": [
        {
          "name": "test00Monitoring",
          "duration": 0.15,
          "result": "succeeded",
          "message": ""
        },
        {
          "name": "test01CreateJob",
          "duration": 43.25,
          "result": "succeeded",
          "message": ""
        }
      ],
      "succeeded": 2,
      "tests": 2,
      "errors": 0,
      "skipped": 0,
      "tag": "GENERAL",
      "durationSec": 43.4
    }
  ]
}

Basic API

New parser instance

 const Parser = require("junitxml-to-javascript");
 const p = new Parser()

New parser instance with custom modifier

You can add your own modifier function that will be called right after the XML data are transformed to raw JavaScript object using library xml2js-parser (transformed to match the output of the xml2json parser). This function:

  • will be given 1 parameter, the output of xml2js-parser parser
  • must be synchronous and must return object that will be further processed
     const Parser = require("junitxml-to-javascript");
     const p = new Parser({modifier : (xmlObject) => {
         const x = {};
         x.testsuites = xmlObject;
         return x;
     });

This is useful if your XML is not exactly as expected and you wish to preprocess

Parse XML string

const Parser = require("junitxml-to-javascript");
new Parser({customTag: "GENERAL1"})
    .parseXMLString(`<?xml version="1.0" encoding="UTF-8"?>
        <testsuite name="1my.package.class.Something" errors="0" test="5" failures="0" skipped="0"
        timestamp="20171206T181624+0100" time="116.716">
            <properties></properties>
            <testcase classname="1my.package.class.Something" name="test00Monitoring" time="0.150">
                <system-out>
                </system-out>
            </testcase>
            <testcase classname="1my.package.class.Something" name="test01CreateJob" time="43.254">
                <system-out>
                </system-out>
            </testcase>
        </testsuite>`)
    .then(e => console.log(JSON.stringify(e, null, 2)))
    .catch(e => console.error(e.message))   

Parse XML file with custom encoding

By default parser uses UTF-8 encoding. One can change that:

const Parser = require("junitxml-to-javascript");
new Parser()
    .parseXMLFile("/tmp/passed.xml", "utf16")
    .then(report => console.log(JSON.stringify(report, null, 2)))
    .catch(err => console.error(e.message))

Use time attribute from test suite instead of making sum of test cases for duration

By default parser uses time attribute of testcase element and sums all values to get total duration of test suite. However, sometimes it might be needed to use time attribute from testsuite element instead. One can change that by specifying sumTestCasesDuration to be false (default is true):

const Parser = require("junitxml-to-javascript");
new Parser({
        sumTestCasesDuration: false
     })
    .parseXMLFile("/tmp/passed.xml", "utf16")
    .then(report => console.log(JSON.stringify(report, null, 2)))
    .catch(err => console.error(e.message))