Skip to content

Commit 255d888

Browse files
authored
Fix interpolated data tables and doc string arguments (#29)
1 parent 1c406fd commit 255d888

File tree

9 files changed

+160
-12
lines changed

9 files changed

+160
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Fixed
10+
- Fix interpolated data tables and doc string arguments ([#29](https://github.com/cucumber/cucumber-json-formatter/pull/29))
11+
912

1013
## [0.3.0] - 2025-10-27
1114
### Changed

java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io.cucumber.messages.types.Attachment;
2020
import io.cucumber.messages.types.AttachmentContentEncoding;
2121
import io.cucumber.messages.types.Background;
22-
import io.cucumber.messages.types.DataTable;
2322
import io.cucumber.messages.types.DocString;
2423
import io.cucumber.messages.types.Exception;
2524
import io.cucumber.messages.types.Feature;
@@ -29,7 +28,11 @@
2928
import io.cucumber.messages.types.HookType;
3029
import io.cucumber.messages.types.Location;
3130
import io.cucumber.messages.types.Pickle;
31+
import io.cucumber.messages.types.PickleDocString;
3232
import io.cucumber.messages.types.PickleStep;
33+
import io.cucumber.messages.types.PickleStepArgument;
34+
import io.cucumber.messages.types.PickleTable;
35+
import io.cucumber.messages.types.PickleTableCell;
3336
import io.cucumber.messages.types.PickleTag;
3437
import io.cucumber.messages.types.Rule;
3538
import io.cucumber.messages.types.RuleChild;
@@ -39,7 +42,6 @@
3942
import io.cucumber.messages.types.StepDefinition;
4043
import io.cucumber.messages.types.StepMatchArgument;
4144
import io.cucumber.messages.types.StepMatchArgumentsList;
42-
import io.cucumber.messages.types.TableCell;
4345
import io.cucumber.messages.types.Tag;
4446
import io.cucumber.messages.types.TestCaseStarted;
4547
import io.cucumber.messages.types.TestStep;
@@ -418,8 +420,8 @@ private Optional<JvmStep> createTestStep(JvmElementData data, TestStepFinished t
418420
createJvmMatch(testStep),
419421
pickleStep.getText(),
420422
createJvmResult(testStepFinished.getTestStepResult()),
421-
createJvmDocString(step),
422-
createJvmDataTableRows(step),
423+
createJvmDocString(pickleStep, step),
424+
createJvmDataTableRows(pickleStep),
423425
createHookSteps(beforeStepHooks),
424426
createHookSteps(afterStepHooks),
425427
createEmbeddings(attachments),
@@ -453,25 +455,34 @@ private JvmArgument createJvmArgument(StepMatchArgument argument) {
453455
group.getStart().orElse(null));
454456
}
455457

456-
private List<JvmDataTableRow> createJvmDataTableRows(Step step) {
457-
return step.getDataTable().map(this::createJvmDataTableRows).orElse(null);
458+
private List<JvmDataTableRow> createJvmDataTableRows(PickleStep pickleStep) {
459+
return pickleStep.getArgument()
460+
.flatMap(PickleStepArgument::getDataTable)
461+
.map(this::createJvmDataTableRows)
462+
.orElse(null);
458463
}
459464

460-
private List<JvmDataTableRow> createJvmDataTableRows(DataTable argument) {
465+
private List<JvmDataTableRow> createJvmDataTableRows(PickleTable argument) {
461466
return argument.getRows().stream()
462467
.map(row -> new JvmDataTableRow(row.getCells().stream()
463-
.map(TableCell::getValue)
468+
.map(PickleTableCell::getValue)
464469
.collect(toList())))
465470
.collect(toList());
466471
}
467472

468-
private JvmDocString createJvmDocString(Step step) {
469-
return step.getDocString().map(this::createJvmDocString).orElse(null);
473+
private JvmDocString createJvmDocString(PickleStep pickleStep, Step step) {
474+
return pickleStep.getArgument()
475+
.flatMap(PickleStepArgument::getDocString)
476+
.map(docString -> createJvmDocString(docString, step)).orElse(null);
470477
}
471478

472-
private JvmDocString createJvmDocString(DocString docString) {
479+
private JvmDocString createJvmDocString(PickleDocString docString, Step step) {
473480
return new JvmDocString(
474-
docString.getLocation().getLine(),
481+
step.getDocString()
482+
.map(DocString::getLocation)
483+
// Can't happen. Pickle doc strings are made from step doc strings
484+
.orElseGet(step::getLocation)
485+
.getLine(),
475486
docString.getContent(),
476487
docString.getMediaType().orElse(null));
477488
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{"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"}}}
2+
{"testRunStarted":{"timestamp":{"seconds":1763644288,"nanos":306383552}}}
3+
{"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"}}
4+
{"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":[]}}
5+
{"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"]}}
6+
{"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"]}}
7+
{"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"}}
8+
{"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"}}
9+
{"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"}}
10+
{"stepDefinition":{"id":"201bab70-4dff-4aaa-8cc5-fe1b011aa2f7","pattern":{"source":"^.*pass.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"passing_step","methodParameterTypes":[]}}}}
11+
{"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"]}}}}
12+
{"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"]}}}}
13+
{"stepDefinition":{"id":"d7f5a650-a93f-4c20-941b-33b57f86540f","pattern":{"source":"^.*pending.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"pending_step","methodParameterTypes":[]}}}}
14+
{"stepDefinition":{"id":"e87b95ea-e317-4263-8926-41246394a73d","pattern":{"source":"^.*fail.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"failing_step","methodParameterTypes":[]}}}}
15+
{"stepDefinition":{"id":"77bffb18-ef09-46c7-8e05-6227de30f5ad","pattern":{"source":"^.*decaying.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"decaying_step","methodParameterTypes":[]}}}}
16+
{"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"]}}}}
17+
{"stepDefinition":{"id":"f7067c38-6bfc-416a-9f6a-d774ff1c3f3b","pattern":{"source":"^.*attach.*$","type":"REGULAR_EXPRESSION"},"sourceReference":{"javaMethod":{"className":"io.cucumber.jsonformatter.StepDefinitions","methodName":"attaching_step","methodParameterTypes":[]}}}}
18+
{"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":[]}}}}
19+
{"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":[]}}}}
20+
{"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"}}
21+
{"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"}}
22+
{"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":[]}]}]}}
23+
{"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}}}
24+
{"testStepStarted":{"testCaseStartedId":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","testStepId":"8e1e78b3-2a9b-4b3f-944a-ed7ec93b4c56","timestamp":{"seconds":1763644288,"nanos":379014456}}}
25+
{"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}}}
26+
{"testCaseFinished":{"testCaseStartedId":"d5dc6024-843f-4cfe-a56c-7e1fe0c6d5a3","timestamp":{"seconds":1763644288,"nanos":382824547},"willBeRetried":false}}
27+
{"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":[]}]}]}}
28+
{"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}}}
29+
{"testStepStarted":{"testCaseStartedId":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","testStepId":"925def37-3a8f-4a7f-b52b-2d7fddbe5bae","timestamp":{"seconds":1763644288,"nanos":384561183}}}
30+
{"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}}}
31+
{"testCaseFinished":{"testCaseStartedId":"ab43ac07-5cff-41e5-8b25-bc37c0438eee","timestamp":{"seconds":1763644288,"nanos":386516513},"willBeRetried":false}}
32+
{"testRunFinished":{"success":true,"timestamp":{"seconds":1763644288,"nanos":386880191}}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":[]}]

0 commit comments

Comments
 (0)