/** * @fileoverview jUnit Reporter * @author Jamund Ferguson */ "use strict"; const xmlEscape = require("../xml-escape"); const path = require("path"); //------------------------------------------------------------------------------ // Helper Functions //------------------------------------------------------------------------------ /** * Returns the severity of warning or error * @param {Object} message message object to examine * @returns {string} severity level * @private */ function getMessageType(message) { if (message.fatal || message.severity === 2) { return "Error"; } return "Warning"; } /** * Returns a full file path without extension * @param {string} filePath input file path * @returns {string} file path without extension * @private */ function pathWithoutExt(filePath) { return path.join(path.dirname(filePath), path.basename(filePath, path.extname(filePath))); } //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ module.exports = function(results) { let output = ""; output += "\n"; output += "\n"; results.forEach(result => { const messages = result.messages; const classname = pathWithoutExt(result.filePath); if (messages.length > 0) { output += `\n`; messages.forEach(message => { const type = message.fatal ? "error" : "failure"; output += ``; output += `<${type} message="${xmlEscape(message.message || "")}">`; output += ""; output += ``; output += "\n"; }); output += "\n"; } else { output += `\n`; output += `\n`; output += "\n"; } }); output += "\n"; return output; };