Skip to content

Commit e57576f

Browse files
committed
Fix data table and tags handling in JSON formatter
1 parent f222435 commit e57576f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/cucumber/listener/json_formatter.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ var JsonFormatter = function() {
2929
var tableContents = step.getDataTable().getContents();
3030
var raw = tableContents.raw();
3131
var tableProperties = [];
32-
for (rawRow in raw) {
33-
var row = {line: undefined, cells: raw[rawRow]};
32+
raw.forEach(function (rawRow) {
33+
var row = {line: undefined, cells: rawRow};
3434
tableProperties.push(row);
35-
}
35+
});
3636
stepProperties['rows'] = tableProperties;
3737
}
3838
gherkinJsonFormatter.step(stepProperties);
3939
}
4040

4141
self.formatTags = function formatTags(tags, parentTags) {
4242
var tagsProperties = [];
43-
for (tag in tags) {
43+
tags.forEach(function (tag) {
4444
var isParentTag = false;
45-
for (parentTag in parentTags) {
46-
if ((tags[tag].getName() == parentTags[parentTag].getName()) && (tags[tag].getLine() == parentTags[parentTag].getLine())) {
47-
isParentTag = true;
48-
}
45+
if (parentTags) {
46+
parentTags.forEach(function (parentTag) {
47+
if ((tag.getName() == parentTag.getName()) && (tag.getLine() == parentTag.getLine())) {
48+
isParentTag = true;
49+
}
50+
});
4951
}
5052
if (!isParentTag) {
51-
tagsProperties.push({name: tags[tag].getName(), line: tags[tag].getLine()});
53+
tagsProperties.push({name: tag.getName(), line: tag.getLine()});
5254
}
53-
}
55+
});
5456
return tagsProperties;
5557
}
5658

spec/cucumber/listener/json_formatter_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function () {
210210
});
211211

212212
describe("formatTags()", function () {
213-
it("returns the given tags in the format expected by the JSON formatter", function (){
213+
it("returns the given tags in the format expected by the JSON formatter", function () {
214214
var tags = [
215215
createSpyWithStubs("tag", {getName: "tag_one", getLine:1}),
216216
createSpyWithStubs("tag", {getName: "tag_two", getLine:2}),

0 commit comments

Comments
 (0)