Skip to content

Commit

Permalink
Code style and fix tabulate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romeovs committed Feb 13, 2021
1 parent 157e8d9 commit 68b59a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/tabulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ function toFolder(path) {
}

function getStatement(file) {
const { branches, functions, lines } = file;
return [branches, functions, lines].reduce((prev, curr) => ({
hit: prev.hit + (curr.hit || 0),
found: prev.found + (curr.found || 0),
}), {
hit: 0,
found: 0,
})
const { branches, functions, lines } = file

return [branches, functions, lines].reduce(function(acc, curr) {
if (!curr) {
return acc
}

return {
hit: acc.hit + curr.hit,
found: acc.found + curr.found,
}
}, { hit: 0, found: 0 })
}

function toRow(file, indent, options) {
Expand Down
8 changes: 6 additions & 2 deletions src/tabulate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ test("tabulate should generate a correct table", function() {
tbody(
tr(
th("File"),
th("Stmts"),
th("Branches"),
th("Funcs"),
th("Lines"),
Expand All @@ -139,12 +140,13 @@ test("tabulate should generate a correct table", function() {
"index.js",
),
),
td("100%"),
td("N/A"),
td("100%"),
td("N/A"),
td(),
),
tr(td({ colspan: 5 }, b("src"))),
tr(td({ colspan: 6 }, b("src"))),
tr(
td(
"   ",
Expand All @@ -155,6 +157,7 @@ test("tabulate should generate a correct table", function() {
"foo.js",
),
),
td(b("89.66%")),
td("100%"),
td(b("66.67%")),
td(b("91.30%")),
Expand All @@ -167,7 +170,7 @@ test("tabulate should generate a correct table", function() {
),
),
),
tr(td({ colspan: 5 }, b("src/bar"))),
tr(td({ colspan: 6 }, b("src/bar"))),
tr(
td(
"   ",
Expand All @@ -178,6 +181,7 @@ test("tabulate should generate a correct table", function() {
"baz.js",
),
),
td(b("53.85%")),
td("N/A"),
td(b("66.67%")),
td(b("50%")),
Expand Down

0 comments on commit 68b59a6

Please sign in to comment.