Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Manage severity of 1 with TAP reporter (fixes #11110) #11221

Merged
merged 1 commit into from Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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