reporter-junit.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function JunitXmlReporter(opt){
  2. console.debug('Creating JunitXmlReporter');
  3. var that = this;
  4. this.format = 'junit';
  5. this.report = '';
  6. this.xml = '';
  7. this.currentSetData = '';
  8. this.currentGroupName = '';
  9. };
  10. JunitXmlReporter.prototype.getReport = function(){
  11. return this.report;
  12. };
  13. JunitXmlReporter.prototype.reportSpecResults = function(spec){
  14. var s = function(s){
  15. return s.replace(/\s/gi, '_');
  16. };
  17. var e = function(s){
  18. return s.replace(/\</gi, '&lt;').replace(/\>/gi, '&gt;').replace(/"/gi, "'");
  19. }
  20. var specName = s(this.currentGroupName) + "." + s(spec.suite.description) + "." + s(spec.description);
  21. var results = spec.results().getItems();
  22. for(var k in results){
  23. var result = results[k];
  24. var name = result.type + " " + result.matcherName + " " + (result.expected ? result.expected : "");
  25. name = e(name);
  26. specName = e(specName);
  27. if(result.passed()){
  28. this.xml += '<testcase classname="'+specName+'" name="'+name+'" time="'+result.time+'"/>';
  29. } else {
  30. this.xml += '<testcase classname="'+specName+'" name="'+name+'">';
  31. this.xml += '<failure><![CDATA[';
  32. this.xml += 'FAILURE in spec "' + spec.description + '": ';
  33. this.xml += result.message + "\n\n\n\n" + result.trace.stack;
  34. this.xml += ']]></failure>';
  35. this.xml += '</testcase>';
  36. }
  37. }
  38. };
  39. JunitXmlReporter.prototype.reportSuiteResults = function(suite){
  40. };
  41. JunitXmlReporter.prototype.reportRunnerResults = function(runner){
  42. };
  43. JunitXmlReporter.prototype.reportStartingGroup = function(name){
  44. this.currentGroupName = name;
  45. };
  46. JunitXmlReporter.prototype.updateReport = function(){
  47. this.report = "<testsuite>"+this.xml+"</testsuite>";
  48. };
  49. JunitXmlReporter.prototype.reset = function(){
  50. this.results = [];
  51. };
  52. exports.create = function(opt){
  53. return new JunitXmlReporter(opt);
  54. }