{"id":14654,"library":"junitxml-to-javascript","title":"JUnit XML to JavaScript Parser","description":"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.","status":"maintenance","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/ladariha/junitxml-to-javascript","tags":["javascript","junit","xml","report","parser"],"install":[{"cmd":"npm install junitxml-to-javascript","lang":"bash","label":"npm"},{"cmd":"yarn add junitxml-to-javascript","lang":"bash","label":"yarn"},{"cmd":"pnpm add junitxml-to-javascript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Internal XML parsing mechanism.","package":"xml2js-parser","optional":false}],"imports":[{"note":"This package is CommonJS-only and does not support ESM `import` syntax.","wrong":"import Parser from 'junitxml-to-javascript';","symbol":"Parser","correct":"const Parser = require('junitxml-to-javascript');"},{"note":"Parsing methods are instance methods, not static methods on the `Parser` class itself.","wrong":"Parser.parseXMLFile('/path/to/report.xml')","symbol":"new Parser().parseXMLFile","correct":"new Parser().parseXMLFile('/path/to/report.xml')"},{"note":"Similar to `parseXMLFile`, `parseXMLString` must be called on an instantiated `Parser` object.","wrong":"Parser.parseXMLString('<testsuite>...</testsuite>')","symbol":"new Parser().parseXMLString","correct":"new Parser().parseXMLString('<testsuite>...</testsuite>')"}],"quickstart":{"code":"const Parser = require(\"junitxml-to-javascript\");\nconst fs = require('fs');\nconst path = require('path');\n\nconst xmlString = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuite name=\"MyTestSuit\" errors=\"0\" tests=\"2\" failures=\"0\" skipped=\"0\"\ntimestamp=\"2023-01-01T12:00:00+0000\" time=\"10.5\">\n    <properties>\n        <property name=\"build.id\" value=\"123\"/>\n    </properties>\n    <testcase classname=\"com.example.TestA\" name=\"shouldPass\" time=\"5.2\"/>\n    <testcase classname=\"com.example.TestB\" name=\"shouldAlsoPass\" time=\"5.3\"/>\n</testsuite>`;\n\nconsole.log('Parsing XML string...');\nnew Parser()\n    .parseXMLString(xmlString)\n    .then(report => {\n        console.log('--- Parsed XML String Output ---');\n        console.log(JSON.stringify(report, null, 2));\n    })\n    .catch(err => console.error('Error parsing string:', err.message));\n\n// Demonstrating file parsing (requires creating a dummy file)\nconst tempFilePath = path.join(__dirname, 'temp_junit_report.xml');\nfs.writeFileSync(tempFilePath, xmlString, 'utf8');\n\nconsole.log('\\nParsing XML file...');\nnew Parser({ customTag: \"CI_BUILD\" })\n    .parseXMLFile(tempFilePath)\n    .then(report => {\n        console.log('--- Parsed XML File Output ---');\n        console.log(JSON.stringify(report, null, 2));\n    })\n    .catch(err => console.error('Error parsing file:', err.message))\n    .finally(() => {\n        // Clean up the temporary file\n        fs.unlinkSync(tempFilePath);\n        console.log('Temporary file cleaned up.');\n    });","lang":"javascript","description":"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."},"warnings":[{"fix":"Ensure your project uses CommonJS or use dynamic `import()` for ESM projects that need to consume CommonJS modules.","message":"The package is explicitly CommonJS-only, requiring `const Parser = require('pkg');` syntax. Attempting to use ESM `import` statements will result in runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if the package's current functionality meets your needs or consider alternatives for long-term projects requiring active maintenance and support.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `const Parser = require('junitxml-to-javascript');` to import the module. Ensure you use `new Parser()` to create an instance.","cause":"Attempting to use `Parser` with ESM `import` syntax as a default export, or incorrectly calling `Parser()` without `new`.","error":"TypeError: Parser is not a constructor"},{"fix":"Verify the file path is correct and accessible. Ensure the file exists and the application has read permissions for it.","cause":"The `parseXMLFile` method could not find the specified XML file at the given path.","error":"ENOENT: no such file or directory, open '/tmp/passed.xml'"}],"ecosystem":"npm"}