Cucumber 7.0 default plugin shift impacts alert clarity when using pretty and json together
0 reputation · 26 Jun 2024, 13:07 UTC
0 reputation · 26 Jun 2024, 13:07 UTC
Goal: Configure Cucumber to emit step‑level alerts via the pretty plugin while simultaneously generating JSON output for downstream alerting, keeping console noise low.
Constraint: Starting with Cucumber 7.0 the default plugin list changed to ['progress']; adding both 'pretty' and 'json' plugins does not guarantee a deterministic order, which can cause interleaving of pretty‑formatted step lines and JSON events, especially when the monochrome flag strips ANSI codes.
Questions: Does Cucumber provide a mechanism to enforce plugin output order or to isolate streams? Can users rely on monochrome plus plugin selection to avoid interleaving in CI logs? Is there a recommended pattern or workaround to obtain clear step alerts and clean JSON without noise?
31275 reputation · 26 Jun 2024, 22:08 UTC
Cucumber does not provide a native mechanism to enforce the sequential execution order of plugins or to isolate their output streams when both are targeting the standard output (stdout). Because plugins act as listeners to the same event bus, they trigger concurrently. If both the pretty and json plugins are configured to write to the console, their outputs will interleave, resulting in corrupted JSON and fragmented human-readable logs.
The interleaving occurs when the json plugin is invoked without a specific file path (e.g., --plugin json instead of --plugin json:target/cucumber.json). In this scenario, both plugins compete for the stdout stream. The monochrome flag removes ANSI color codes but does not synchronize the write operations of separate plugins, meaning it cannot prevent interleaving.
To obtain clear step-level alerts in the console while maintaining a clean JSON file for downstream reporting, you must isolate the JSON plugin to a physical file. This removes the JSON stream from the console entirely, leaving only the pretty output for human observation.
Use the following plugin configuration in your CLI or Runner class:
--plugin pretty --plugin json:target/cucumber-report.json
Verification Steps:
--plugin pretty. Confirm that step alerts are legible and not interrupted.target/cucumber-report.json to ensure it is a valid JSON array and not interleaved with "Scenario:" or "Given" text.--monochrome flag to ensure the console logs remain clean of ANSI characters without affecting the JSON file content.Diagnostic Detail Needed: Are you currently specifying a file path for the JSON plugin, or are you relying on the default stdout output for both?
Use comments to ask for clarification. Post a solution as an answer.
31,275 reputation · 26 Jun 2024, 17:43 UTC
--plugin flags doesn’t solve interleavingIn Cucumber 7.x the --plugin flags are processed in the order they appear, but each plugin is an independent listener that writes to the same stdout stream. Because the writes happen asynchronously, the output is interleaved regardless of flag order.
Redirect one of the plugins to a file. The json plugin already supports a file path syntax, e.g.:
--plugin pretty --plugin json:target/cucumber-report.json
This keeps the human‑readable console output clean while preserving a valid JSON file for downstream alerting.
If you also want to keep a log of the pretty output, add a second file target:
--plugin pretty:target/pretty.log --plugin json:target/cucumber-report.json
Now the console shows only the pretty logs, the JSON file is untouched, and a separate file contains the full pretty trace for audit purposes.