Skip to content

Commit

Permalink
Fix: Manage severity of 1 with TAP reporter (fixes #11110)
Browse files Browse the repository at this point in the history
When using TAP reporter, both messages with severity of 1 or 2 were listed as errors (`not ok`). This changes aims at reporting warnings as `ok` messages.
  • Loading branch information
GabrielCousin committed Dec 29, 2018
1 parent 258b654 commit 1952cd5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
11 changes: 7 additions & 4 deletions lib/formatters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function getMessageType(message) {
return "error";
}
return "warning";

}

/**
Expand Down Expand Up @@ -50,19 +49,23 @@ module.exports = function(results) {
let diagnostics = {};

if (messages.length > 0) {
testResult = "not ok";

messages.forEach(message => {
const severity = getMessageType(message);
const diagnostic = {
message: message.message,
severity: getMessageType(message),
severity,
data: {
line: message.line || 0,
column: message.column || 0,
ruleId: message.ruleId || ""
}
};

// This ensures a warning message is not flagged as error
if (severity === "error") {
testResult = "not ok";
}

/*
* If we have multiple messages place them under a messages key
* The first error will be logged as message key
Expand Down
65 changes: 63 additions & 2 deletions tests/lib/formatters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,68 @@ describe("formatter:tap", () => {
});
});

describe("when passed multiple messages", () => {
describe("when passed a message with a severity of 1", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 1,
line: 5,
column: 10,
ruleId: "foo"
}]
}];

it("should return a an warning string", () => {
const result = formatter(code);

assert.include(result, "ok");
assert.include(result, "warning");
});
});

describe("when passed multiple messages with a severity of 1", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Foo.",
severity: 1,
line: 5,
column: 10,
ruleId: "foo"
}, {
message: "Bar.",
severity: 1,
line: 6,
column: 11,
ruleId: "bar"
}, {
message: "Baz.",
severity: 1,
line: 7,
column: 12,
ruleId: "baz"
}]
}];

it("should return a string with multiple entries", () => {
const result = formatter(code);

assert.include(result, "ok");
assert.include(result, "messages");
assert.include(result, "Foo.");
assert.include(result, "line: 5");
assert.include(result, "column: 10");
assert.include(result, "Bar.");
assert.include(result, "line: 6");
assert.include(result, "column: 11");
assert.include(result, "Baz.");
assert.include(result, "line: 7");
assert.include(result, "column: 12");
});
});

describe("when passed multiple messages with different error severity", () => {
const code = [{
filePath: "foo.js",
messages: [{
Expand Down Expand Up @@ -146,7 +207,7 @@ describe("formatter:tap", () => {
const result = formatter(code);

assert.include(result, "not ok 1");
assert.include(result, "not ok 2");
assert.include(result, "ok 2");
});
});

Expand Down

0 comments on commit 1952cd5

Please sign in to comment.