Skip to content

Commit 5f51c96

Browse files
authored
[Core] Significantly reduce the size of the html report (#2172)
Cucumber-JVM will emit all step, hook and parameter type definition for each scenario. This results in a deluge of messages that effectively grows with the square of the number of scenarios (more scenarios, result in more step definitions). Executing some 500 scenarios can result in a html report anywhere between 150 and 300 MiB. The step, hook, and parameter type definitions are not used by the html report and can be filtered out. This reduces the report size to some 15 MiB. While still large this is much more manageable. Further reductions will have to come from: 1. Improvements to `cucumber/react` 2. Fixing Cucumber JVM to only define steps, hooks and parameter types once.
1 parent 3bc6e77 commit 5f51c96

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717
### Removed
1818

1919
### Fixed
20-
* [Core] Improve error message when plugin paths collide ([#2168](https://github.com/cucumber/cucumber-jvm/pull/2168) M.P. Korstanje)
20+
* [Core] Significantly reduce the size of the html report ([cucumber/#1232](https://github.com/cucumber/cucumber/issues/1232) M.P. Korstanje)
21+
* [Core] Improve error message when plugin paths collide ([#2168](https://github.com/cucumber/cucumber-jvm/pull/2168) M.P. Korstanje)
2122

2223
## [6.8.2] (2020-10-29)
2324

core/src/main/java/io/cucumber/core/plugin/HtmlFormatter.java

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public void setEventPublisher(EventPublisher publisher) {
2323
}
2424

2525
private void write(Envelope event) {
26+
// Workaround to reduce the size of the report
27+
// See: https://github.com/cucumber/cucumber/issues/1232
28+
if (event.hasStepDefinition() || event.hasHook() || event.hasParameterType()) {
29+
return;
30+
}
31+
2632
try {
2733
writer.write(event);
2834
} catch (IOException e) {

core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ void verifyTestCaseStartedSortedCorrectly() {
164164
() -> assertThat(comparator.compare(e, feature1Case1Started), greaterThan(EQUAL_TO)),
165165
() -> assertThat(comparator.compare(e, feature1Case2Started), greaterThan(EQUAL_TO)),
166166
() -> assertThat(comparator.compare(e, feature1Case3Started), greaterThan(EQUAL_TO)),
167-
() -> assertThat(comparator.compare(e, feature2Case1Started), greaterThan(EQUAL_TO))
168-
);
167+
() -> assertThat(comparator.compare(e, feature2Case1Started), greaterThan(EQUAL_TO)));
169168
}
170169

171170
assertAll(

core/src/test/java/io/cucumber/core/plugin/HtmlFormatterTest.java

+47
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,51 @@ void writes_index_html() throws Throwable {
4747
"];"));
4848
}
4949

50+
@Test
51+
void ignores_step_definitions() throws Throwable {
52+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
53+
HtmlFormatter formatter = new HtmlFormatter(bytes);
54+
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
55+
formatter.setEventPublisher(bus);
56+
57+
bus.send(Messages.Envelope.newBuilder()
58+
.setTestRunStarted(Messages.TestRunStarted.newBuilder()
59+
.setTimestamp(Messages.Timestamp.newBuilder()
60+
.setSeconds(10)
61+
.build())
62+
.build())
63+
.build());
64+
65+
bus.send(Messages.Envelope.newBuilder()
66+
.setStepDefinition(Messages.StepDefinition.newBuilder()
67+
.build())
68+
.build());
69+
70+
bus.send(Messages.Envelope.newBuilder()
71+
.setHook(Messages.Hook.newBuilder()
72+
.build())
73+
.build());
74+
75+
bus.send(Messages.Envelope.newBuilder()
76+
.setParameterType(Messages.ParameterType.newBuilder()
77+
.build())
78+
.build());
79+
80+
bus.send(
81+
Messages.Envelope.newBuilder()
82+
.setTestRunFinished(Messages.TestRunFinished.newBuilder()
83+
.setTimestamp(Messages.Timestamp.newBuilder()
84+
.setSeconds(15)
85+
.build())
86+
.build())
87+
.build());
88+
89+
String html = new String(bytes.toByteArray(), UTF_8);
90+
assertThat(html, containsString("" +
91+
"window.CUCUMBER_MESSAGES = [" +
92+
"{\"testRunStarted\":{\"timestamp\":{\"seconds\":\"10\"}}}," +
93+
"{\"testRunFinished\":{\"timestamp\":{\"seconds\":\"15\"}}}" +
94+
"];"));
95+
}
96+
5097
}

0 commit comments

Comments
 (0)