Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include executed scenarios and steps from outlines in the JSON output #704

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cucumber.runtime.formatter;

import gherkin.formatter.JSONFormatter;
import gherkin.formatter.model.Examples;
import gherkin.formatter.model.Scenario;
import gherkin.formatter.model.ScenarioOutline;
import gherkin.formatter.model.Step;

public class CucumberJSONFormatter extends JSONFormatter {
private boolean inScenarioOutline = false;

public CucumberJSONFormatter(Appendable out) {
super(out);
}

@Override
public void scenarioOutline(ScenarioOutline scenarioOutline) {
inScenarioOutline = true;
}

@Override
public void examples(Examples examples) {
// NoOp
}

@Override
public void startOfScenarioLifeCycle(Scenario scenario) {
inScenarioOutline = false;
super.startOfScenarioLifeCycle(scenario);
}

@Override
public void step(Step step) {
if (!inScenarioOutline) {
super.step(step);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;
import gherkin.formatter.Formatter;
import gherkin.formatter.JSONFormatter;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -37,7 +36,7 @@ public class FormatterFactory {
put("html", HTMLFormatter.class);
put("pretty", CucumberPrettyFormatter.class);
put("progress", ProgressFormatter.class);
put("json", JSONFormatter.class);
put("json", CucumberJSONFormatter.class);
put("usage", UsageFormatter.class);
put("rerun", RerunFormatter.class);
}};
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/cucumber/runtime/RuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cucumber.api.PendingException;
import cucumber.api.Scenario;
import cucumber.runtime.formatter.CucumberJSONFormatter;
import cucumber.runtime.io.ClasspathResourceLoader;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void runs_feature_with_json_formatter() throws Exception {
" Scenario: scenario name\n" +
" When s\n");
StringBuilder out = new StringBuilder();
JSONFormatter jsonFormatter = new JSONFormatter(out);
JSONFormatter jsonFormatter = new CucumberJSONFormatter(out);
List<Backend> backends = asList(mock(Backend.class));
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,69 +97,6 @@
],
"type": "scenario"
},
{
"id": "feature-3;scenariooutline-1",
"description": "",
"name": "ScenarioOutline_1",
"keyword": "Scenario Outline",
"line": 14,
"steps": [
{
"name": "so_1 \u003ca\u003e",
"keyword": "Given ",
"line": 15
},
{
"name": "so_2 \u003cc\u003e cucumbers",
"keyword": "When ",
"line": 16
},
{
"name": "\u003cb\u003e so_3",
"keyword": "Then ",
"line": 17
}
],
"examples": [
{
"id": "feature-3;scenariooutline-1;",
"description": "",
"name": "",
"keyword": "Examples",
"line": 19,
"rows": [
{
"id": "feature-3;scenariooutline-1;;1",
"cells": [
"a",
"b",
"c"
],
"line": 20
},
{
"id": "feature-3;scenariooutline-1;;2",
"cells": [
"12",
"5",
"7"
],
"line": 21
},
{
"id": "feature-3;scenariooutline-1;;3",
"cells": [
"20",
"5",
"15"
],
"line": 22
}
]
}
],
"type": "scenario_outline"
},
{
"description": "",
"name": "",
Expand Down