2 * @fileoverview jUnit Reporter
3 * @author Jamund Ferguson
7 const xmlEscape = require("../xml-escape");
8 const path = require("path");
10 //------------------------------------------------------------------------------
12 //------------------------------------------------------------------------------
15 * Returns the severity of warning or error
16 * @param {Object} message message object to examine
17 * @returns {string} severity level
20 function getMessageType(message) {
21 if (message.fatal || message.severity === 2) {
29 * Returns a full file path without extension
30 * @param {string} filePath input file path
31 * @returns {string} file path without extension
34 function pathWithoutExt(filePath) {
35 return path.posix.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath)));
38 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
42 module.exports = function(results) {
46 output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
47 output += "<testsuites>\n";
49 results.forEach(result => {
51 const messages = result.messages;
52 const classname = pathWithoutExt(result.filePath);
54 if (messages.length > 0) {
55 output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
56 messages.forEach(message => {
57 const type = message.fatal ? "error" : "failure";
59 output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}" classname="${classname}">`;
60 output += `<${type} message="${xmlEscape(message.message || "")}">`;
61 output += "<![CDATA[";
62 output += `line ${message.line || 0}, col `;
63 output += `${message.column || 0}, ${getMessageType(message)}`;
64 output += ` - ${xmlEscape(message.message || "")}`;
65 output += (message.ruleId ? ` (${message.ruleId})` : "");
67 output += `</${type}>`;
68 output += "</testcase>\n";
70 output += "</testsuite>\n";
72 output += `<testsuite package="org.eslint" time="0" tests="1" errors="0" name="${result.filePath}">\n`;
73 output += `<testcase time="0" name="${result.filePath}" classname="${classname}" />\n`;
74 output += "</testsuite>\n";
79 output += "</testsuites>\n";