Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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
- Fix interpolated data tables and doc string arguments ([#29](https://github.com/cucumber/cucumber-json-formatter/pull/29))


## [0.3.0] - 2025-10-27
### Changed
Expand Down
35 changes: 23 additions & 12 deletions java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.cucumber.messages.types.Attachment;
import io.cucumber.messages.types.AttachmentContentEncoding;
import io.cucumber.messages.types.Background;
import io.cucumber.messages.types.DataTable;
import io.cucumber.messages.types.DocString;
import io.cucumber.messages.types.Exception;
import io.cucumber.messages.types.Feature;
Expand All @@ -29,7 +28,11 @@
import io.cucumber.messages.types.HookType;
import io.cucumber.messages.types.Location;
import io.cucumber.messages.types.Pickle;
import io.cucumber.messages.types.PickleDocString;
import io.cucumber.messages.types.PickleStep;
import io.cucumber.messages.types.PickleStepArgument;
import io.cucumber.messages.types.PickleTable;
import io.cucumber.messages.types.PickleTableCell;
import io.cucumber.messages.types.PickleTag;
import io.cucumber.messages.types.Rule;
import io.cucumber.messages.types.RuleChild;
Expand All @@ -39,7 +42,6 @@
import io.cucumber.messages.types.StepDefinition;
import io.cucumber.messages.types.StepMatchArgument;
import io.cucumber.messages.types.StepMatchArgumentsList;
import io.cucumber.messages.types.TableCell;
import io.cucumber.messages.types.Tag;
import io.cucumber.messages.types.TestCaseStarted;
import io.cucumber.messages.types.TestStep;
Expand Down Expand Up @@ -418,8 +420,8 @@ private Optional<JvmStep> createTestStep(JvmElementData data, TestStepFinished t
createJvmMatch(testStep),
pickleStep.getText(),
createJvmResult(testStepFinished.getTestStepResult()),
createJvmDocString(step),
createJvmDataTableRows(step),
createJvmDocString(pickleStep, step),
createJvmDataTableRows(pickleStep),
createHookSteps(beforeStepHooks),
createHookSteps(afterStepHooks),
createEmbeddings(attachments),
Expand Down Expand Up @@ -453,25 +455,34 @@ private JvmArgument createJvmArgument(StepMatchArgument argument) {
group.getStart().orElse(null));
}

private List<JvmDataTableRow> createJvmDataTableRows(Step step) {
return step.getDataTable().map(this::createJvmDataTableRows).orElse(null);
private List<JvmDataTableRow> createJvmDataTableRows(PickleStep pickleStep) {
return pickleStep.getArgument()
.flatMap(PickleStepArgument::getDataTable)
.map(this::createJvmDataTableRows)
.orElse(null);
}

private List<JvmDataTableRow> createJvmDataTableRows(DataTable argument) {
private List<JvmDataTableRow> createJvmDataTableRows(PickleTable argument) {
return argument.getRows().stream()
.map(row -> new JvmDataTableRow(row.getCells().stream()
.map(TableCell::getValue)
.map(PickleTableCell::getValue)
.collect(toList())))
.collect(toList());
}

private JvmDocString createJvmDocString(Step step) {
return step.getDocString().map(this::createJvmDocString).orElse(null);
private JvmDocString createJvmDocString(PickleStep pickleStep, Step step) {
return pickleStep.getArgument()
.flatMap(PickleStepArgument::getDocString)
.map(docString -> createJvmDocString(docString, step)).orElse(null);
}

private JvmDocString createJvmDocString(DocString docString) {
private JvmDocString createJvmDocString(PickleDocString docString, Step step) {
return new JvmDocString(
docString.getLocation().getLine(),
step.getDocString()
.map(DocString::getLocation)
// Can't happen. Pickle doc strings are made from step doc strings
.orElseGet(step::getLocation)
.getLine(),
docString.getContent(),
docString.getMediaType().orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{"meta":{"protocolVersion":"28.0.0","implementation":{"name":"cucumber-jvm","version":"7.26.0"},"runtime":{"name":"OpenJDK 64-Bit Server VM","version":"21.0.4+7-LTS"},"os":{"name":"Linux"},"cpu":{"name":"amd64"}}}
{"testRunStarted":{"timestamp":{"seconds":1763644288,"nanos":306383552}}}
{"source":{"uri":"file:///home/mpkorstanje/Projects/cucumber/json-formatter/testdata/cucumber-jvm/7.26.0-java/../../features/pickle-arguments-interpolated.feature","data":"Feature: pickle-arguments-interpolated\n\n Scenario Outline: docstring\n Given this step accepts a docstring\n \"\"\"application/json\n { \"hello\": \"<key>\" }\n \"\"\"\n\n Examples:\n | key |\n | word |\n\n Scenario Outline: datatable\n Given this step accepts a datatable\n | hello |\n | <key> |\n\n Examples:\n | key |\n | world |","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"uri":"file:///home/mpkorstanje/Projects/cucumber/json-formatter/testdata/cucumber-jvm/7.26.0-java/../../features/pickle-arguments-interpolated.feature","feature":{"location":{"line":1,"column":1},"tags":[],"language":"en","keyword":"Feature","name":"pickle-arguments-interpolated","description":"","children":[{"scenario":{"location":{"line":3,"column":3},"tags":[],"keyword":"Scenario Outline","name":"docstring","description":"","steps":[{"location":{"line":4,"column":5},"keyword":"Given ","keywordType":"Context","text":"this step accepts a docstring","docString":{"location":{"line":5,"column":7},"mediaType":"application/json","content":"{ \"hello\": \"<key>\" }","delimiter":"\"\"\""},"id":"124f5e2f-8fb9-4ada-a965-7963f8ff132a"}],"examples":[{"location":{"line":9,"column":5},"tags":[],"keyword":"Examples","name":"","description":"","tableHeader":{"location":{"line":10,"column":7},"cells":[{"location":{"line":10,"column":9},"value":"key"}],"id":"b8b55b27-ad32-46b6-b85d-a79a97927b62"},"tableBody":[{"location":{"line":11,"column":7},"cells":[{"location":{"line":11,"column":9},"value":"word"}],"id":"d746b808-e301-43fc-9de0-c68219e17537"}],"id":"8224ae3a-685f-4095-b4f0-a954cce6eaac"}],"id":"fad2f834-c2d0-46ec-8d60-2a69144e3bee"}},{"scenario":{"location":{"line":13,"column":3},"tags":[],"keyword":"Scenario Outline","name":"datatable","description":"","steps":[{"location":{"line":14,"column":5},"keyword":"Given ","keywordType":"Context","text":"this step accepts a datatable","dataTable":{"location":{"line":15,"column":7},"rows":[{"location":{"line":15,"column":7},"cells":[{"location":{"line":15,"column":9},"value":"hello"}],"id":"5f7bff4e-f35a-4eb1-9bed-e9b9e7621d55"},{"location":{"line":16,"column":7},"cells":[{"location":{"line":16,"column":9},"value":"<key>"}],"id":"81cfba97-a5f4-4d48-ae61-ec3f488e6ff8"}]},"id":"220adae6-2fe3-4d53-ab2f-81365c3d426e"}],"examples":[{"location":{"line":18,"column":5},"tags":[],"keyword":"Examples","name":"","description":"","tableHeader":{"location":{"line":19,"column":7},"cells":[{"location":{"line":19,"column":9},"value":"key"}],"id":"a4552dc8-1a2a-4dda-8e4c-2c11a9ab6ec6"},"tableBody":[{"location":{"line":20,"column":7},"cells":[{"location":{"line":20,"column":9},"value":"world"}],"id":"0d04ceb8-0465-4a61-a526-c5ceaaac233d"}],"id":"1aa3b71b-4e91-434c-ba36-156ad5af7498"}],"id":"0e801b20-ab0a-4bd8-8c68-5fba5d72e069"}}]},"comments":[]}}
{"pickle":{"id":"692b7307-db1f-4f51-8d4b-976024d92b9c","uri":"file:///home/mpkorstanje/Projects/cucumber/json-formatter/testdata/cucumber-jvm/7.26.0-java/../../features/pickle-arguments-interpolated.feature","name":"docstring","language":"en","steps":[{"argument":{"docString":{"mediaType":"application/json","content":"{ \"hello\": \"word\" }"}},"astNodeIds":["124f5e2f-8fb9-4ada-a965-7963f8ff132a","d746b808-e301-43fc-9de0-c68219e17537"],"id":"7034b14d-2a77-4a42-a44c-44dd238df755","type":"Context","text":"this step accepts a docstring"}],"tags":[],"astNodeIds":["fad2f834-c2d0-46ec-8d60-2a69144e3bee","d746b808-e301-43fc-9de0-c68219e17537"]}}
{"pickle":{"id":"d4e73c0e-dcbf-4753-9caa-b0f8a1ee4c84","uri":"file:///home/mpkorstanje/Projects/cucumber/json-formatter/testdata/cucumber-jvm/7.26.0-java/../../features/pickle-arguments-interpolated.feature","name":"datatable","language":"en","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"hello"}]},{"cells":[{"value":"world"}]}]}},"astNodeIds":["220adae6-2fe3-4d53-ab2f-81365c3d426e","0d04ceb8-0465-4a61-a526-c5ceaaac233d"],"id":"9d52f691-dc13-4865-969e-ccb432540f09","type":"Context","text":"this step accepts a datatable"}],"tags":[],"astNodeIds":["0e801b20-ab0a-4bd8-8c68-5fba5d72e069","0d04ceb8-0465-4a61-a526-c5ceaaac233d"]}}
{"hook":{"id":"5dfc64e0-e717-4cc9-a052-e3c429be4695","sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"tagged_passing_before_attachments","methodParameterTypes":["io.cucumber.java.Scenario"]}},"tagExpression":"@attachments","type":"BEFORE_TEST_CASE"}}
{"hook":{"id":"2b4bf5a5-2660-4bc5-a638-51242d22a711","sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"tagged_failing_before_hook","methodParameterTypes":[]}},"tagExpression":"@failing_before","type":"BEFORE_TEST_CASE"}}
{"hook":{"id":"98efd286-d79f-47fe-9f50-b7cdc2309377","sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"tagged_failing_before_step_hook","methodParameterTypes":[]}},"tagExpression":"@failing_before_step","type":"BEFORE_TEST_STEP"}}
{"stepDefinition":{"id":"201bab70-4dff-4aaa-8cc5-fe1b011aa2f7","pattern":{"source":"^.*pass.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"passing_step","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"aea5dd0c-12bd-45ec-a2cf-58dd2987c045","pattern":{"source":"^.*docstring.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"passing_step","methodParameterTypes":["io.cucumber.docstring.DocString"]}}}}
{"stepDefinition":{"id":"36de3f50-b88c-4122-8f6f-70ce1621d7a0","pattern":{"source":"^.*datatable.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"passing_step","methodParameterTypes":["io.cucumber.datatable.DataTable"]}}}}
{"stepDefinition":{"id":"d7f5a650-a93f-4c20-941b-33b57f86540f","pattern":{"source":"^.*pending.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"pending_step","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"e87b95ea-e317-4263-8926-41246394a73d","pattern":{"source":"^.*fail.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"failing_step","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"77bffb18-ef09-46c7-8e05-6227de30f5ad","pattern":{"source":"^.*decaying.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"decaying_step","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"32a27a28-953c-48a4-8d73-de021221da15","pattern":{"source":"^I have (\\d+) cukes(?: in my (.*))?$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"cukes_in_something","methodParameterTypes":["int","java.lang.String"]}}}}
{"stepDefinition":{"id":"f7067c38-6bfc-416a-9f6a-d774ff1c3f3b","pattern":{"source":"^.*attach.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"attaching_step","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"8494c0dc-eee1-43ed-b6bd-7333918f7058","pattern":{"source":"^.*ambiguous.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"ambiguous_step_a","methodParameterTypes":[]}}}}
{"stepDefinition":{"id":"78170f05-f027-4427-b119-a77e6454502e","pattern":{"source":"^.*ambiguous step.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"ambiguous_step_b","methodParameterTypes":[]}}}}
{"hook":{"id":"ca9a5a29-b55f-47c9-951a-a96aa3c76792","sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"tagged_failing_after_step_hook","methodParameterTypes":[]}},"tagExpression":"@failing_after_step","type":"AFTER_TEST_STEP"}}
{"hook":{"id":"cc8ca4b0-5d6e-49a1-adc5-0f867c374172","sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"tagged_failing_after_hook","methodParameterTypes":[]}},"tagExpression":"@failing_after","type":"AFTER_TEST_CASE"}}
{"testCase":{"id":"95d13d47-d254-4823-84dd-9d0488ff1d9f","pickleId":"692b7307-db1f-4f51-8d4b-976024d92b9c","testSteps":[{"id":"8e1e78b3-2a9b-4b3f-944a-ed7ec93b4c56","pickleStepId":"7034b14d-2a77-4a42-a44c-44dd238df755","stepDefinitionIds":["aea5dd0c-12bd-45ec-a2cf-58dd2987c045"],"stepMatchArgumentsLists":[{"stepMatchArguments":[]}]}]}}
{"testCaseStarted":{"attempt":0,"id":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","testCaseId":"95d13d47-d254-4823-84dd-9d0488ff1d9f","workerId":"io.cucumber.core.cli.Main.main()","timestamp":{"seconds":1763644288,"nanos":371334824}}}
{"testStepStarted":{"testCaseStartedId":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","testStepId":"8e1e78b3-2a9b-4b3f-944a-ed7ec93b4c56","timestamp":{"seconds":1763644288,"nanos":379014456}}}
{"testStepFinished":{"testCaseStartedId":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","testStepId":"8e1e78b3-2a9b-4b3f-944a-ed7ec93b4c56","testStepResult":{"duration":{"seconds":0,"nanos":596910},"status":"PASSED"},"timestamp":{"seconds":1763644288,"nanos":379611366}}}
{"testCaseFinished":{"testCaseStartedId":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","timestamp":{"seconds":1763644288,"nanos":382824547},"willBeRetried":false}}
{"testCase":{"id":"2853662a-fac5-436a-b388-55cc28c966df","pickleId":"d4e73c0e-dcbf-4753-9caa-b0f8a1ee4c84","testSteps":[{"id":"925def37-3a8f-4a7f-b52b-2d7fddbe5bae","pickleStepId":"9d52f691-dc13-4865-969e-ccb432540f09","stepDefinitionIds":["36de3f50-b88c-4122-8f6f-70ce1621d7a0"],"stepMatchArgumentsLists":[{"stepMatchArguments":[]}]}]}}
{"testCaseStarted":{"attempt":0,"id":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","testCaseId":"2853662a-fac5-436a-b388-55cc28c966df","workerId":"io.cucumber.core.cli.Main.main()","timestamp":{"seconds":1763644288,"nanos":384293346}}}
{"testStepStarted":{"testCaseStartedId":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","testStepId":"925def37-3a8f-4a7f-b52b-2d7fddbe5bae","timestamp":{"seconds":1763644288,"nanos":384561183}}}
{"testStepFinished":{"testCaseStartedId":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","testStepId":"925def37-3a8f-4a7f-b52b-2d7fddbe5bae","testStepResult":{"duration":{"seconds":0,"nanos":867732},"status":"PASSED"},"timestamp":{"seconds":1763644288,"nanos":385428915}}}
{"testCaseFinished":{"testCaseStartedId":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","timestamp":{"seconds":1763644288,"nanos":386516513},"willBeRetried":false}}
{"testRunFinished":{"success":true,"timestamp":{"seconds":1763644288,"nanos":386880191}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"line":1,"elements":[{"start_timestamp":"2025-11-20T13:11:28.371Z","line":11,"name":"docstring","description":"","id":"pickle-arguments-interpolated;docstring;;2","type":"scenario","keyword":"Scenario Outline","steps":[{"result":{"duration":596910,"status":"passed"},"line":4,"name":"this step accepts a docstring","match":{"location":"io.cucumber.jsonformatter.StepDefinitions.passing_step(io.cucumber.docstring.DocString)"},"keyword":"Given ","doc_string":{"content_type":"application/json","line":5,"value":"{ \"hello\": \"word\" }"}}]},{"start_timestamp":"2025-11-20T13:11:28.384Z","line":20,"name":"datatable","description":"","id":"pickle-arguments-interpolated;datatable;;2","type":"scenario","keyword":"Scenario Outline","steps":[{"result":{"duration":867732,"status":"passed"},"line":14,"name":"this step accepts a datatable","match":{"location":"io.cucumber.jsonformatter.StepDefinitions.passing_step(io.cucumber.datatable.DataTable)"},"rows":[{"cells":["hello"]},{"cells":["world"]}],"keyword":"Given "}]}],"name":"pickle-arguments-interpolated","description":"","id":"pickle-arguments-interpolated","keyword":"Feature","uri":"file:///home/mpkorstanje/Projects/cucumber/json-formatter/testdata/cucumber-jvm/7.26.0-java/../../features/pickle-arguments-interpolated.feature","tags":[]}]
Loading