Registry / testing / cucumber-junit-formatter

cucumber-junit-formatter

JSON →
library0.2.2jsnpmunverified

cucumber-junit-formatter (v0.2.2) is a custom formatter for Cucumber.js that generates JUnit XML reports compatible with Jenkins, GitLab CI/CD, and other CI systems. It transforms Cucumber test results into the standard JUnit XML format, treating pending or undefined steps as failures. The package is maintained but receives infrequent updates, with peer dependency on cucumber >=3.0.0. Key differentiators include support for optional configuration like scenarioAsStep (wrapping scenarios as steps within features), withPackage (adding package attribute), and propertiesInTestcase (embedding properties in testcase elements). It is an alternative to cucumber-junit and cucumber-pretty, focusing on strict JUnit compliance for CI pipelines.

npm install cucumber-junit-formatter
INSTALL
IMPORT
SIG · CUCUMBER-JUNIT-FOR
C
cucumber-junit-formatter
testingjavascriptv0.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
// No direct import: use via CLI cucumber-js -f cucumber-junit-formatter[:<file>]
const formatter = require('cucumber-junit-formatter')
This package is a Cucumber formatter, not a library. Use the -f CLI flag; direct require is not supported.
Formatter constructor
// As a Cucumber formatter, configured via --format or --format-options cucumber-js -f node_modules/cucumber-junit-formatter --format-options '{"scenarioAsStep":true}'
const JunitFormatter = require('cucumber-junit-formatter'); new JunitFormatter(...)
Do not instantiate directly. The formatter uses Cucumber's internal event system; only CLI usage is supported.

Install package and run Cucumber.js with JUnit formatter, demonstrating CLI usage with optional file output and format options.

// Install npm install --save-dev cucumber-junit-formatter@0.2.2 // Run with default options npx cucumber-js -f cucumber-junit-formatter:output.xml // Custom options npx cucumber-js -f cucumber-junit-formatter:output.xml \ --format-options '{"scenarioAsStep":false,"withPackage":true,"propertiesInTestcase":false}' // Example features/example.feature: Feature: Example Scenario: Passing Given a step When action Then result
Debug
Known issues
gotchaPending or undefined steps are reported as failures, not skipped. This may cause false negatives in CI pipelines.
fix
Mark steps as pending or use @pending tag; alternatively, consider a different formatter if you need skipped/pending to be non-failing.
affects: >=0.1.0
deprecatedThe package uses the older Cucumber event protocol (messages-based). With cucumber-js 7+, custom formatters should use the new event protocol.
fix
Upgrade to cucumber-js 7+ and consider using built-in JUnit formatter (@cucumber/junit-xml) or a modern alternative.
affects: >=0.2.0
gotchaFile output specified without a file path writes to stdout. This may clobber terminal output or not produce a file as expected.
fix
Always specify a file path after colon: -f cucumber-junit-formatter:output.xml
affects: >=0.1.0
breakingPeer dependency requires cucumber >=3.0.0. Using with cucumber <3 or >=7 may cause missing exports or runtime errors.
fix
Ensure cucumber version is 3.x, 4.x, 5.x, or 6.x. For cucumber 7+, use @cucumber/junit-xml instead.
affects: >=0.1.0
gotchaThe option 'scenarioAsStep' changes XML structure: when true, feature = <testsuite>, scenario = <testcase>. Default (false) makes each scenario a <testsuite>.
fix
Set 'scenarioAsStep' according to your CI parser expectations. Many CI tools expect each testcase to be a test method (scenarioAsStep=true).
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'cucumber-junit-formatter'
Package not installed or not in node_modules when running cucumber-js from a different directory.
fix
Run from project root after `npm install --save-dev cucumber-junit-formatter`. Use full path: -f `pwd`/node_modules/cucumber-junit-formatter
TypeError: formatter is not a constructor
Attempting to require() and instantiate the formatter directly in code.
fix
Do not use require. Use the CLI -f option as documented: npx cucumber-js -f cucumber-junit-formatter
Warnings: 'pending' or 'undefined' steps will be reported in xml as failures.
Default behavior: pending/undefined steps are treated as failures, which may be unexpected.
fix
If you want pending steps to be skipped, use cucumber's --no-strict option or consider a different formatter.
Unsupported format options: scenarioAsStep/withPackage/propertiesInTestcase not working.
Format options must be passed as JSON string via --format-options. They are not read from cucumber.js config.
fix
Use `--format-options '{"scenarioAsStep":true}'` on the command line.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
cucumberrequiredPeer dependency required for the formatter to hook into Cucumber's event protocol
Agent activity
9 hits · last 30 days
node
8
Resources
cucumber-junit-formatter — npm install cucumber-junit-formatter · libregistry