reporter-simple.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var cp = function(o){ if(typeof o != 'object') return o; var n = {}; for(var k in o) n[k] = o[k]; return n; };
  2. function SimpleReporter(opt){
  3. console.debug('Creating SimpleReporter');
  4. var that = this;
  5. this.format = 'simple';
  6. this._report = {};
  7. this.results = [];
  8. this.currentSet = 0;
  9. };
  10. SimpleReporter.prototype.getReport = function(){
  11. return cp(this._report);
  12. };
  13. SimpleReporter.prototype.reportStartingGroup = function(name){
  14. this.results[this.currentSet] = this.results[this.currentSet] || {};
  15. this.results[this.currentSet].name = name;
  16. }
  17. SimpleReporter.prototype.reportSpecResults = function(spec){
  18. var items = spec.results().getItems();
  19. for (var i = 0; i < items.length; i++){
  20. if( ! items[i].passed_){
  21. this.results[this.currentSet] = this.results[this.currentSet] || {};
  22. this.results[this.currentSet].failures = this.results[this.currentSet].failures || [];
  23. var failureReport = items[i];
  24. failureReport.suite = spec.suite.description;
  25. failureReport.spec = spec.description;
  26. failureReport.group = this.results[this.currentSet].name;
  27. this.results[this.currentSet].failures.push(failureReport);
  28. }
  29. }
  30. }
  31. SimpleReporter.prototype.reportRunnerResults = function(runner){
  32. var results = runner.results();
  33. this.results[this.currentSet] = this.results[this.currentSet] || {};
  34. this.results[this.currentSet].passed = results.passedCount;
  35. this.results[this.currentSet].failed = results.failedCount;
  36. this.results[this.currentSet].total = results.totalCount;
  37. this.currentSet++;
  38. }
  39. SimpleReporter.prototype.updateReport = function(){
  40. var totalPassed = 0,
  41. totalFailed = 0,
  42. totalTests = 0,
  43. totalSuites = 0,
  44. failureDetails = [];
  45. for(var k in this.results){
  46. var result = this.results[k];
  47. totalPassed += result.passed;
  48. totalFailed += result.failed;
  49. totalTests += result.total;
  50. totalSuites++;
  51. if(result.failures){
  52. for(var j = 0; j < result.failures.length; j++){
  53. failureDetails.push(result.failures[j]);
  54. }
  55. }
  56. }
  57. this._report = {
  58. details: cp(this.results),
  59. passed: totalPassed,
  60. failed: totalFailed,
  61. total: totalTests,
  62. suites: totalSuites,
  63. failureDetails: cp(failureDetails),
  64. status: (totalFailed == 0) ? "Passed" : "Failed"
  65. };
  66. };
  67. SimpleReporter.prototype.reset = function(){
  68. this.results = [];
  69. };
  70. exports.create = function(opt){
  71. return new SimpleReporter(opt);
  72. }