Skip to content

Commit

Permalink
[Core] Include stack traces in html report (#2862)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpkorstanje committed Mar 23, 2024
1 parent 9eb958d commit a2395d4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cucumber-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<cucumber-expressions.version>17.1.0</cucumber-expressions.version>
<gherkin.version>28.0.0</gherkin.version>
<html-formatter.version>21.3.0</html-formatter.version>
<junit-xml-formatter.version>0.2.1</junit-xml-formatter.version>
<messages.version>24.0.1</messages.version>
<junit-xml-formatter.version>0.3.0</junit-xml-formatter.version>
<messages.version>24.1.0</messages.version>
<tag-expressions.version>6.1.0</tag-expressions.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit a2395d4

Please sign in to comment.