1 /** JavaScript API reporter. 2 * 3 * @constructor 4 */ 5 jasmine.JsApiReporter = function() { 6 this.started = false; 7 this.finished = false; 8 this.suites_ = []; 9 this.results_ = {}; 10 }; 11 12 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { 13 this.started = true; 14 var suites = runner.suites(); 15 for (var i = 0; i < suites.length; i++) { 16 var suite = suites[i]; 17 this.suites_.push(this.summarize_(suite)); 18 } 19 }; 20 21 jasmine.JsApiReporter.prototype.suites = function() { 22 return this.suites_; 23 }; 24 25 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { 26 var isSuite = suiteOrSpec instanceof jasmine.Suite; 27 var summary = { 28 id: suiteOrSpec.id, 29 name: suiteOrSpec.description, 30 type: isSuite ? 'suite' : 'spec', 31 children: [] 32 }; 33 if (isSuite) { 34 var specs = suiteOrSpec.specs(); 35 for (var i = 0; i < specs.length; i++) { 36 summary.children.push(this.summarize_(specs[i])); 37 } 38 } 39 return summary; 40 }; 41 42 jasmine.JsApiReporter.prototype.results = function() { 43 return this.results_; 44 }; 45 46 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { 47 return this.results_[specId]; 48 }; 49 50 //noinspection JSUnusedLocalSymbols 51 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { 52 this.finished = true; 53 }; 54 55 //noinspection JSUnusedLocalSymbols 56 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { 57 }; 58 59 //noinspection JSUnusedLocalSymbols 60 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { 61 this.results_[spec.id] = { 62 messages: spec.results().getItems(), 63 result: spec.results().failedCount > 0 ? "failed" : "passed" 64 }; 65 }; 66 67 //noinspection JSUnusedLocalSymbols 68 jasmine.JsApiReporter.prototype.log = function(str) { 69 }; 70 71 jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ 72 var results = {}; 73 for (var i = 0; i < specIds.length; i++) { 74 var specId = specIds[i]; 75 results[specId] = this.summarizeResult_(this.results_[specId]); 76 } 77 return results; 78 }; 79 80 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ 81 var summaryMessages = []; 82 for (var messageIndex in result.messages) { 83 var resultMessage = result.messages[messageIndex]; 84 summaryMessages.push({ 85 text: resultMessage.text, 86 passed: resultMessage.passed ? resultMessage.passed() : true, 87 type: resultMessage.type, 88 message: resultMessage.message, 89 trace: { 90 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined 91 } 92 }); 93 }; 94 95 var summaryResult = { 96 result : result.result, 97 messages : summaryMessages 98 }; 99 100 return summaryResult; 101 }; 102 103