Skip to content

Commit 11430d5

Browse files
committed
Filter unused messages
Because the message stream simply writes all messages, the report is larger than it needs to be. By filtering out step definitions, hooks and parameter types the report becomes smaller (but not much).
1 parent 1c05773 commit 11430d5

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

dotnet/Cucumber.HtmlFormatter/MessagesToHtmlWriter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public void Write(Envelope envelope)
112112
_preMessageWritten = true;
113113
_writer.Flush();
114114
}
115+
if(envelope.StepDefinition != null || envelope.Hook != null || envelope.ParameterType != null)
116+
{
117+
return;
118+
}
115119
if (!_firstMessageWritten)
116120
{
117121
_firstMessageWritten = true;
@@ -142,6 +146,10 @@ public async Task WriteAsync(Envelope envelope)
142146
_preMessageWritten = true;
143147
await _writer.FlushAsync();
144148
}
149+
if(envelope.Source != null || envelope.StepDefinition != null)
150+
{
151+
return;
152+
}
145153
if (!_firstMessageWritten)
146154
{
147155
_firstMessageWritten = true;

java/src/main/java/io/cucumber/htmlformatter/MessagesToHtmlWriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public void write(Envelope envelope) throws IOException {
143143
preMessageWritten = true;
144144
}
145145

146+
if (envelope.getStepDefinition().isPresent() || envelope.getHook().isPresent() || envelope.getParameterType().isPresent()) {
147+
return;
148+
}
149+
146150
if (!firstMessageWritten) {
147151
firstMessageWritten = true;
148152
} else {

java/src/test/java/io/cucumber/htmlformatter/MessagesToHtmlWriterTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import io.cucumber.messages.types.Envelope;
77
import io.cucumber.messages.types.GherkinDocument;
88
import io.cucumber.messages.types.Location;
9+
import io.cucumber.messages.types.Source;
10+
import io.cucumber.messages.types.SourceMediaType;
11+
import io.cucumber.messages.types.SourceReference;
12+
import io.cucumber.messages.types.StepDefinition;
13+
import io.cucumber.messages.types.StepDefinitionPattern;
14+
import io.cucumber.messages.types.StepDefinitionPatternType;
915
import io.cucumber.messages.types.TestRunFinished;
1016
import io.cucumber.messages.types.TestRunStarted;
1117
import org.junit.jupiter.api.Test;
@@ -15,6 +21,7 @@
1521
import java.io.IOException;
1622
import java.time.Instant;
1723

24+
import static io.cucumber.messages.types.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN;
1825
import static java.nio.charset.StandardCharsets.UTF_8;
1926
import static java.util.Collections.singletonList;
2027
import static org.hamcrest.CoreMatchers.containsString;
@@ -61,6 +68,14 @@ void it_writes_no_message_to_html() throws IOException {
6168
assertThat(html, containsString("window.CUCUMBER_MESSAGES = [];"));
6269
}
6370

71+
@Test
72+
void it_ignores_step_definition_messages() throws IOException {
73+
StepDefinitionPattern pattern = new StepDefinitionPattern("hello {int} cucumber(s)", StepDefinitionPatternType.CUCUMBER_EXPRESSION);
74+
Envelope envelope = Envelope.of(new StepDefinition("123", pattern, SourceReference.of("path/to/StepDefinition.java")));
75+
String html = renderAsHtml(envelope);
76+
assertThat(html, containsString("window.CUCUMBER_MESSAGES = [];"));
77+
}
78+
6479
@Test
6580
void it_writes_default_title() throws IOException {
6681
String html = renderAsHtml(MessagesToHtmlWriter.builder(serializer));

javascript/src/CucumberHtmlStream.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export class CucumberHtmlStream extends Transform {
138138
}
139139

140140
private writeMessage(envelope: messages.Envelope) {
141+
if (envelope.stepDefinition || envelope.hook || envelope.parameterType) {
142+
return;
143+
}
144+
141145
if (!this.firstMessageWritten) {
142146
this.firstMessageWritten = true
143147
} else {

ruby/lib/cucumber/html_formatter/formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def process_messages(messages)
2222
end
2323

2424
def write_message(message)
25+
if message.step_definition != nil || message.hook != nil || message.parameter_type != nil
26+
return
27+
end
28+
2529
out.puts(',') unless @first_message
2630
# Replace < with \x3C
2731
# https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements

0 commit comments

Comments
 (0)