Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

junit.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @fileoverview jUnit Reporter
  3. * @author Jamund Ferguson
  4. */
  5. "use strict";
  6. const xmlEscape = require("../util/xml-escape");
  7. //------------------------------------------------------------------------------
  8. // Helper Functions
  9. //------------------------------------------------------------------------------
  10. /**
  11. * Returns the severity of warning or error
  12. * @param {Object} message message object to examine
  13. * @returns {string} severity level
  14. * @private
  15. */
  16. function getMessageType(message) {
  17. if (message.fatal || message.severity === 2) {
  18. return "Error";
  19. }
  20. return "Warning";
  21. }
  22. //------------------------------------------------------------------------------
  23. // Public Interface
  24. //------------------------------------------------------------------------------
  25. module.exports = function(results) {
  26. let output = "";
  27. output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  28. output += "<testsuites>\n";
  29. results.forEach(result => {
  30. const messages = result.messages;
  31. if (messages.length > 0) {
  32. output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
  33. messages.forEach(message => {
  34. const type = message.fatal ? "error" : "failure";
  35. output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}">`;
  36. output += `<${type} message="${xmlEscape(message.message || "")}">`;
  37. output += "<![CDATA[";
  38. output += `line ${message.line || 0}, col `;
  39. output += `${message.column || 0}, ${getMessageType(message)}`;
  40. output += ` - ${xmlEscape(message.message || "")}`;
  41. output += (message.ruleId ? ` (${message.ruleId})` : "");
  42. output += "]]>";
  43. output += `</${type}>`;
  44. output += "</testcase>\n";
  45. });
  46. output += "</testsuite>\n";
  47. } else {
  48. output += `<testsuite package="org.eslint" time="0" tests="1" errors="0" name="${result.filePath}">\n`;
  49. output += `<testcase time="0" name="${result.filePath}" />\n`;
  50. output += "</testsuite>\n";
  51. }
  52. });
  53. output += "</testsuites>\n";
  54. return output;
  55. };