{"id":13035,"library":"cucumber-junit-convert","title":"Cucumber.js to JUnit XML Converter","description":"The `cucumber-junit-convert` package is a utility designed to transform JSON output files generated by Cucumber.js into the standard JUnit XML format, widely used for continuous integration reporting. Currently at version 2.1.1, the library's key distinguishing feature is its mapping strategy: it treats each Cucumber 'Scenario' as a JUnit 'Testcase', rather than the more granular 'Step' level often used by similar tools. This approach provides a clearer, higher-level overview in test reports. While not on a strict rapid release cycle, the package has received consistent updates, including recent bug fixes and feature additions like support for embeddings and the option to use feature names as JUnit class names, indicating active maintenance. It is particularly useful for projects integrating Cucumber.js tests with CI/CD pipelines that expect JUnit XML reports.","status":"active","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/znevrly/cucumber-junit-convert","tags":["javascript","cucumber","cucumberjs","junit"],"install":[{"cmd":"npm install cucumber-junit-convert","lang":"bash","label":"npm"},{"cmd":"yarn add cucumber-junit-convert","lang":"bash","label":"yarn"},{"cmd":"pnpm add cucumber-junit-convert","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary `convert` function is typically accessed as a named export in ESM contexts. Direct default import might lead to issues.","wrong":"import cucumberJunitConvert from 'cucumber-junit-convert';\ncucumberJunitConvert.convert(options);","symbol":"convert","correct":"import { convert } from 'cucumber-junit-convert';"},{"note":"For CommonJS, the module typically exports an object where the main conversion function is a property named `convert`.","wrong":"const { convert } = require('cucumber-junit-convert');","symbol":"cucumberJunitConvert (CJS)","correct":"const cucumberJunitConvert = require('cucumber-junit-convert');"},{"note":"While not explicitly documented, types for options are often available, assuming the library ships with TypeScript declarations.","symbol":"Type Imports","correct":"import type { ConvertOptions } from 'cucumber-junit-convert';"}],"quickstart":{"code":"const cucumberJunitConvert = require('cucumber-junit-convert');\nconst fs = require('fs');\nconst path = require('path');\n\n// Create a dummy Cucumber JSON file for demonstration\nconst dummyJson = [\n    {\n        \"keyword\": \"Feature\",\n        \"name\": \"Dummy Feature\",\n        \"description\": \"\",\n        \"line\": 1,\n        \"id\": \"dummy-feature\",\n        \"uri\": \"features/dummy.feature\",\n        \"elements\": [\n            {\n                \"keyword\": \"Scenario\",\n                \"name\": \"Successful Scenario\",\n                \"description\": \"\",\n                \"line\": 3,\n                \"type\": \"scenario\",\n                \"id\": \"dummy-feature;successful-scenario\",\n                \"steps\": [\n                    { \"keyword\": \"Given\", \"name\": \"a step\", \"line\": 4, \"result\": { \"status\": \"passed\", \"duration\": 1000000 } }\n                ]\n            },\n            {\n                \"keyword\": \"Scenario\",\n                \"name\": \"Failing Scenario\",\n                \"description\": \"\",\n                \"line\": 6,\n                \"type\": \"scenario\",\n                \"id\": \"dummy-feature;failing-scenario\",\n                \"steps\": [\n                    { \"keyword\": \"When\", \"name\": \"another step\", \"line\": 7, \"result\": { \"status\": \"failed\", \"duration\": 2000000, \"error_message\": \"Assertion failed\" } }\n                ]\n            }\n        ]\n    }\n];\n\nconst inputFilePath = path.join(__dirname, 'cucumber-results.json');\nconst outputFilePath = path.join(__dirname, 'junit-report.xml');\n\nfs.writeFileSync(inputFilePath, JSON.stringify(dummyJson, null, 2));\n\nconst options = {\n    inputJsonFile: inputFilePath,\n    outputXmlFile: outputFilePath,\n    featureNameAsClassName: true // default: false\n}\n\ntry {\n    cucumberJunitConvert.convert(options);\n    console.log(`Successfully converted '${inputFilePath}' to '${outputFilePath}'.`);\n} catch (error) {\n    console.error('Conversion failed:', error);\n} finally {\n    // Clean up dummy file\n    fs.unlinkSync(inputFilePath);\n}\n","lang":"javascript","description":"This quickstart demonstrates how to convert a Cucumber.js JSON result file into a JUnit XML report, including a basic example of creating the input JSON and configuring conversion options."},"warnings":[{"fix":"Ensure the `inputJsonFile` option points to an existing and accessible Cucumber.js JSON report file.","message":"The `inputJsonFile` path must be valid and readable. If the specified file does not exist, the conversion will fail with a file not found error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need to preserve existing JUnit XML reports, ensure your build process moves or renames them before running the conversion, or specify a unique output file name.","message":"The `outputXmlFile` will be overwritten if it already exists at the specified path. There is no confirmation prompt or option to prevent overwriting.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For consistent reporting, upgrade to v2.1.0 or newer and set `featureNameAsClassName: true` in your options if you desire this mapping.","message":"The `featureNameAsClassName` option (introduced in v2.1.0) controls whether the Cucumber Feature name is used as the JUnit `classname`. Prior to v2.1.0, this option was not available, and behavior might differ.","severity":"gotcha","affected_versions":"<2.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that the path provided for `inputJsonFile` is correct, the file exists, and your application has read permissions for it.","cause":"The input JSON file specified by `inputJsonFile` in the options object could not be found or accessed.","error":"Error: ENOENT: no such file or directory, open '<filename>.json'"},{"fix":"For CommonJS, use `const cucumberJunitConvert = require('cucumber-junit-convert'); cucumberJunitConvert.convert(options);`. For ESM, use `import { convert } from 'cucumber-junit-convert'; convert(options);`.","cause":"This error typically occurs when attempting to call `convert` on an undefined module export, often due to incorrect CommonJS `require` or ESM `import` syntax, or the module failing to load.","error":"TypeError: Cannot read properties of undefined (reading 'convert') at Object.<anonymous>"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}