Registry / testing / cucumber-junit-convert

cucumber-junit-convert

JSON →
library2.1.1jsnpmunverified

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.

npm install cucumber-junit-convert
INSTALL
IMPORT
SIG · CUCUMBER-JUNIT-CON
C
cucumber-junit-convert
testingjavascriptv2.1.1
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.

convert
import { convert } from 'cucumber-junit-convert';
import cucumberJunitConvert from 'cucumber-junit-convert'; cucumberJunitConvert.convert(options);
The primary `convert` function is typically accessed as a named export in ESM contexts. Direct default import might lead to issues.
cucumberJunitConvert (CJS)
const cucumberJunitConvert = require('cucumber-junit-convert');
const { convert } = require('cucumber-junit-convert');
For CommonJS, the module typically exports an object where the main conversion function is a property named `convert`.
Type Imports
import type { ConvertOptions } from 'cucumber-junit-convert';
While not explicitly documented, types for options are often available, assuming the library ships with TypeScript declarations.

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.

const cucumberJunitConvert = require('cucumber-junit-convert'); const fs = require('fs'); const path = require('path'); // Create a dummy Cucumber JSON file for demonstration const dummyJson = [ { "keyword": "Feature", "name": "Dummy Feature", "description": "", "line": 1, "id": "dummy-feature", "uri": "features/dummy.feature", "elements": [ { "keyword": "Scenario", "name": "Successful Scenario", "description": "", "line": 3, "type": "scenario", "id": "dummy-feature;successful-scenario", "steps": [ { "keyword": "Given", "name": "a step", "line": 4, "result": { "status": "passed", "duration": 1000000 } } ] }, { "keyword": "Scenario", "name": "Failing Scenario", "description": "", "line": 6, "type": "scenario", "id": "dummy-feature;failing-scenario", "steps": [ { "keyword": "When", "name": "another step", "line": 7, "result": { "status": "failed", "duration": 2000000, "error_message": "Assertion failed" } } ] } ] } ]; const inputFilePath = path.join(__dirname, 'cucumber-results.json'); const outputFilePath = path.join(__dirname, 'junit-report.xml'); fs.writeFileSync(inputFilePath, JSON.stringify(dummyJson, null, 2)); const options = { inputJsonFile: inputFilePath, outputXmlFile: outputFilePath, featureNameAsClassName: true // default: false } try { cucumberJunitConvert.convert(options); console.log(`Successfully converted '${inputFilePath}' to '${outputFilePath}'.`); } catch (error) { console.error('Conversion failed:', error); } finally { // Clean up dummy file fs.unlinkSync(inputFilePath); }
Debug
Known issues
gotchaThe `inputJsonFile` path must be valid and readable. If the specified file does not exist, the conversion will fail with a file not found error.
fix
Ensure the `inputJsonFile` option points to an existing and accessible Cucumber.js JSON report file.
affects: >=1.0.0
gotchaThe `outputXmlFile` will be overwritten if it already exists at the specified path. There is no confirmation prompt or option to prevent overwriting.
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.
affects: >=1.0.0
gotchaThe `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.
fix
For consistent reporting, upgrade to v2.1.0 or newer and set `featureNameAsClassName: true` in your options if you desire this mapping.
affects: <2.1.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open '<filename>.json'
The input JSON file specified by `inputJsonFile` in the options object could not be found or accessed.
fix
Verify that the path provided for `inputJsonFile` is correct, the file exists, and your application has read permissions for it.
TypeError: Cannot read properties of undefined (reading 'convert') at Object.<anonymous>
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.
fix
For CommonJS, use `const cucumberJunitConvert = require('cucumber-junit-convert'); cucumberJunitConvert.convert(options);`. For ESM, use `import { convert } from 'cucumber-junit-convert'; convert(options);`.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
cucumber-junit-convert — npm install cucumber-junit-convert · libregistry