From 37a759633c948507b46bad93922c90607dc40a0b Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sat, 23 Mar 2024 18:49:40 +0100 Subject: [PATCH] [Core] Include stack traces in html report With cucumber/react-components#345 the html formatter started to support rendering stack traces. Unfortunately this also broke the regular rendering of stacktrace. And fixing this required including the stack trace the xml report as well so that when the Convertor in messages was fixed to always include the stacktrace, we wouldn't render the stacktrace in the xml formatter twice. --- CHANGELOG.md | 2 ++ cucumber-bom/pom.xml | 4 ++-- .../main/java/io/cucumber/core/runner/TestStep.java | 13 +------------ .../core/runtime/CucumberExecutionContext.java | 3 +-- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 370b3d8c56..5ae2f47ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- [Core] Include stack traces in html report ([#2862](https://github.com/cucumber/cucumber-jvm/pull/2862) M.P. Korstanje) ## [7.16.0] - 2024-03-21 ### Added diff --git a/cucumber-bom/pom.xml b/cucumber-bom/pom.xml index 23f3198587..fbbff8a191 100644 --- a/cucumber-bom/pom.xml +++ b/cucumber-bom/pom.xml @@ -16,8 +16,8 @@ 17.1.0 28.0.0 21.3.0 - 0.2.1 - 24.0.1 + 0.3.0 + 24.1.0 6.1.0 diff --git a/cucumber-core/src/main/java/io/cucumber/core/runner/TestStep.java b/cucumber-core/src/main/java/io/cucumber/core/runner/TestStep.java index 9c20db0c01..f0340778ef 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/runner/TestStep.java +++ b/cucumber-core/src/main/java/io/cucumber/core/runner/TestStep.java @@ -10,9 +10,6 @@ import io.cucumber.plugin.event.TestStepFinished; import io.cucumber.plugin.event.TestStepStarted; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.UUID; @@ -117,7 +114,7 @@ private void emitTestStepFinished( TestStepResult testStepResult = new TestStepResult( toMessage(duration), - result.getError() != null ? extractStackTrace(result.getError()) : null, + result.getError() != null ? result.getError().getMessage() : null, from(result.getStatus()), result.getError() != null ? toMessage(result.getError()) : null); @@ -128,12 +125,4 @@ private void emitTestStepFinished( toMessage(stopTime))); bus.send(envelope); } - - private String extractStackTrace(Throwable error) { - ByteArrayOutputStream s = new ByteArrayOutputStream(); - PrintStream printStream = new PrintStream(s); - error.printStackTrace(printStream); - return new String(s.toByteArray(), StandardCharsets.UTF_8); - } - } diff --git a/cucumber-core/src/main/java/io/cucumber/core/runtime/CucumberExecutionContext.java b/cucumber-core/src/main/java/io/cucumber/core/runtime/CucumberExecutionContext.java index 80c7c46962..5e4a252f29 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/runtime/CucumberExecutionContext.java +++ b/cucumber-core/src/main/java/io/cucumber/core/runtime/CucumberExecutionContext.java @@ -24,7 +24,6 @@ import java.util.function.Consumer; import static io.cucumber.cienvironment.DetectCiEnvironment.detectCiEnvironment; -import static io.cucumber.core.exception.ExceptionUtils.printStackTrace; import static io.cucumber.core.exception.ExceptionUtils.throwAsUncheckedException; import static io.cucumber.core.exception.UnrecoverableExceptions.rethrowIfUnrecoverable; import static io.cucumber.messages.Convertor.toMessage; @@ -118,7 +117,7 @@ private void emitTestRunFinished(Throwable exception) { bus.send(new TestRunFinished(instant, result)); io.cucumber.messages.types.TestRunFinished testRunFinished = new io.cucumber.messages.types.TestRunFinished( - exception != null ? printStackTrace(exception) : null, + exception != null ? exception.getMessage() : null, exception == null && exitStatus.isSuccess(), toMessage(instant), exception == null ? null : toMessage(exception));