Skip to content

Commit

Permalink
Fix: Manage severity of 1 with TAP reporter (fixes #11110) (#11221)
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 authored and nzakas committed Jan 16, 2019
1 parent 000f495 commit 9194f45
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/formatters/tap.js
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
70 changes: 67 additions & 3 deletions tests/lib/formatters/tap.js
Expand Up @@ -72,15 +72,78 @@ describe("formatter:tap", () => {
}]
}];

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

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

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 warning string", () => {
const result = formatter(code);

assert.include(result, "ok");
assert.notInclude(result, "not 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.notInclude(result, "not 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 +209,8 @@ describe("formatter:tap", () => {
const result = formatter(code);

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

Expand Down

0 comments on commit 9194f45

Please sign in to comment.