Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dotnet/Cucumber.HtmlFormatter/MessagesToHtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public void Write(Envelope envelope)
_preMessageWritten = true;
_writer.Flush();
}
if(envelope.StepDefinition != null || envelope.Hook != null || envelope.ParameterType != null)
{
return;
}
if (!_firstMessageWritten)
{
_firstMessageWritten = true;
Expand Down Expand Up @@ -142,6 +146,10 @@ public async Task WriteAsync(Envelope envelope)
_preMessageWritten = true;
await _writer.FlushAsync();
}
if(envelope.Source != null || envelope.StepDefinition != null)
{
return;
}
if (!_firstMessageWritten)
{
_firstMessageWritten = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public void write(Envelope envelope) throws IOException {
preMessageWritten = true;
}

if (envelope.getStepDefinition().isPresent()
|| envelope.getHook().isPresent()
|| envelope.getParameterType().isPresent()) {
return;
}

if (!firstMessageWritten) {
firstMessageWritten = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.Location;
import io.cucumber.messages.types.Source;
import io.cucumber.messages.types.SourceMediaType;
import io.cucumber.messages.types.SourceReference;
import io.cucumber.messages.types.StepDefinition;
import io.cucumber.messages.types.StepDefinitionPattern;
import io.cucumber.messages.types.StepDefinitionPatternType;
import io.cucumber.messages.types.TestRunFinished;
import io.cucumber.messages.types.TestRunStarted;
import org.junit.jupiter.api.Test;
Expand All @@ -15,6 +21,7 @@
import java.io.IOException;
import java.time.Instant;

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

@Test
void it_ignores_step_definition_messages() throws IOException {
StepDefinitionPattern pattern = new StepDefinitionPattern("hello {int} cucumber(s)", StepDefinitionPatternType.CUCUMBER_EXPRESSION);
Envelope envelope = Envelope.of(new StepDefinition("123", pattern, SourceReference.of("path/to/StepDefinition.java")));
String html = renderAsHtml(envelope);
assertThat(html, containsString("window.CUCUMBER_MESSAGES = [];"));
}

@Test
void it_writes_default_title() throws IOException {
String html = renderAsHtml(MessagesToHtmlWriter.builder(serializer));
Expand Down
4 changes: 4 additions & 0 deletions javascript/src/CucumberHtmlStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class CucumberHtmlStream extends Transform {
}

private writeMessage(envelope: messages.Envelope) {
if (envelope.stepDefinition || envelope.hook || envelope.parameterType) {
Copy link
Contributor Author

@mpkorstanje mpkorstanje Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidjgoss in #414 (comment) you said:

Before implementing the specific solution suggested here I think it would make sense to strip out all messages that are not used by the html report.

Agreed. As it stands we can do without:

* `source`

* `stepDefinition`

But source is used by react components. Instead I got this set of messages as unused from Cucumber JVM (filesize workaround).

Does this make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, source is currently used, although I am getting rid of that soon in cucumber/react-components#396.

hook is definitely used in the components to look up the name and other details of the defined hook.

But stepDefinition and parameterType can definitely be filtered out for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'll wait for cucumber/react-components#396 then.

return;
}

if (!this.firstMessageWritten) {
this.firstMessageWritten = true
} else {
Expand Down
4 changes: 4 additions & 0 deletions ruby/lib/cucumber/html_formatter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def process_messages(messages)
end

def write_message(message)
if message.step_definition != nil || message.hook != nil || message.parameter_type != nil
return
end

out.puts(',') unless @first_message
# Replace < with \x3C
# https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
Expand Down
Loading