Registry / testing / junitxml-to-javascript

junitxml-to-javascript

JSON →
library1.1.4jsnpmunverified

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.

npm install junitxml-to-javascript
INSTALL
IMPORT
SIG · JUNITXML-TO-JAVASC
J
junitxml-to-javascript
testingjavascriptv1.1.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser
const Parser = require('junitxml-to-javascript');
import Parser from 'junitxml-to-javascript';
This package is CommonJS-only and does not support ESM `import` syntax.
new Parser().parseXMLFile
new Parser().parseXMLFile('/path/to/report.xml')
Parser.parseXMLFile('/path/to/report.xml')
Parsing methods are instance methods, not static methods on the `Parser` class itself.
new Parser().parseXMLString
new Parser().parseXMLString('<testsuite>...</testsuite>')
Parser.parseXMLString('<testsuite>...</testsuite>')
Similar to `parseXMLFile`, `parseXMLString` must be called on an instantiated `Parser` object.

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.'); });
Debug
Known issues
gotchaThe package is explicitly CommonJS-only, requiring `const Parser = require('pkg');` syntax. Attempting to use ESM `import` statements will result in runtime errors.
fix
Ensure your project uses CommonJS or use dynamic `import()` for ESM projects that need to consume CommonJS modules.
affects: >=1.0.0
gotchaThe package specifies an old Node.js engine requirement (`>=8.2.1`). While it might run on newer Node.js versions, it's not actively maintained for modern environments, potentially leading to compatibility issues or missed optimizations/security patches.
fix
Be aware of potential compatibility issues with very recent Node.js versions. Consider containerizing or using a specific Node.js version if encountering problems.
affects: >=1.0.0
gotchaThis package does not ship with TypeScript type definitions. Developers using TypeScript will need to create their own declaration files (`.d.ts`) or use a global `declare module` to avoid type errors.
fix
Add a `declarations.d.ts` file with `declare module 'junitxml-to-javascript';` or define the types for the `Parser` class and its methods manually.
affects: >=1.0.0
deprecatedThe package appears to be unmaintained or in a long-term maintenance state, with no active development or recent updates indicated by its version (1.1.4) and reliance on older technologies. This could lead to a lack of support for new JUnit XML features or unresolved bugs.
fix
Evaluate if the package's current functionality meets your needs or consider alternatives for long-term projects requiring active maintenance and support.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Parser is not a constructor
Attempting to use `Parser` with ESM `import` syntax as a default export, or incorrectly calling `Parser()` without `new`.
fix
Use `const Parser = require('junitxml-to-javascript');` to import the module. Ensure you use `new Parser()` to create an instance.
ENOENT: no such file or directory, open '/tmp/passed.xml'
The `parseXMLFile` method could not find the specified XML file at the given path.
fix
Verify the file path is correct and accessible. Ensure the file exists and the application has read permissions for it.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
xml2js-parserrequiredInternal XML parsing mechanism.
Agent activity
2 hits · last 30 days
node
2
Resources