2 * @fileoverview TAP reporter
3 * @author Jonathan Kingston
7 var yaml = require("js-yaml");
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
14 * Returns a canonical error level string based upon the error message passed in.
15 * @param {object} message Individual error message provided by eslint
16 * @returns {String} Error level string
18 function getMessageType(message) {
19 if (message.fatal || message.severity === 2) {
27 * Takes in a JavaScript object and outputs a TAP diagnostics string
28 * @param {object} diagnostic JavaScript object to be embedded as YAML into output.
29 * @returns {string} diagnostics string with YAML embedded - TAP version 13 compliant
31 function outputDiagnostics(diagnostic) {
33 var output = prefix + "---\n";
34 output += prefix + yaml.safeDump(diagnostic).split("\n").join("\n" + prefix);
39 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
43 module.exports = function(results) {
44 var output = "TAP version 13\n1.." + results.length + "\n";
46 results.forEach(function(result, id) {
47 var messages = result.messages;
48 var testResult = "ok";
51 if (messages.length > 0) {
52 testResult = "not ok";
54 messages.forEach(function(message) {
56 message: message.message,
57 severity: getMessageType(message),
59 line: message.line || 0,
60 column: message.column || 0,
61 ruleId: message.ruleId || ""
65 // If we have multiple messages place them under a messages key
66 // The first error will be logged as message key
67 // This is to adhere to TAP 13 loosely defined specification of having a message key
68 if ("message" in diagnostics) {
69 if ("messages" in diagnostics) {
70 diagnostics.messages.push(diagnostic);
72 diagnostics.messages = [diagnostic];
75 diagnostics = diagnostic;
80 output += testResult + " " + (id + 1) + " - " + result.filePath + "\n";
82 // If we have an error include diagnostics
83 if (messages.length > 0) {
84 output += outputDiagnostics(diagnostics);