Skip to content

Commit

Permalink
Fix: Allow HTML formatter to handle no meta data (#11566)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyavolodin committed Mar 30, 2019
1 parent 87a5c03 commit c06d38c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/formatters/html.js
Expand Up @@ -119,6 +119,8 @@ module.exports = function(results, data) {
let totalErrors,
totalWarnings;

const metaData = data ? data.rulesMeta : {};

totalErrors = 0;
totalWarnings = 0;

Expand All @@ -132,6 +134,6 @@ module.exports = function(results, data) {
date: new Date(),
reportColor: renderColor(totalErrors, totalWarnings),
reportSummary: renderSummary(totalErrors, totalWarnings),
results: renderResults(results, data.rulesMeta)
results: renderResults(results, metaData)
});
};
15 changes: 15 additions & 0 deletions tests/lib/formatters/html.js
Expand Up @@ -115,6 +115,21 @@ describe("formatter:html", () => {
checkHeaderRow($, $("tr")[0], { bgColor: "bg-2", group: "f-0", file: "foo.js", problems: "1 problem (1 error, 0 warnings)" });
checkContentRow($, $("tr")[1], { group: "f-0", lineCol: "5:10", color: "clr-2", message: "Unexpected foo.", ruleId: "foo" });
});

it("should not fail if metadata is not available", () => {
const result = formatter(code.results);

const $ = cheerio.load(result);

// Check overview
checkOverview($, { bgColor: "bg-2", problems: "1 problem (1 error, 0 warnings)" });

// Check rows
assert.strictEqual($("tr").length, 2, "Check that there are two (1 header, 1 content)");
assert.strictEqual($("tr[data-group|=\"f\"]").length, 1, "Check that is 1 header row (implying 1 content row)");
checkHeaderRow($, $("tr")[0], { bgColor: "bg-2", group: "f-0", file: "foo.js", problems: "1 problem (1 error, 0 warnings)" });
checkContentRow($, $("tr")[1], { group: "f-0", lineCol: "5:10", color: "clr-2", message: "Unexpected foo.", ruleId: "foo" });
});
});

describe("when passed a single warning message", () => {
Expand Down

0 comments on commit c06d38c

Please sign in to comment.