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.topLevelSuites(); 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 34 if (isSuite) { 35 var children = suiteOrSpec.children(); 36 for (var i = 0; i < children.length; i++) { 37 summary.children.push(this.summarize_(children[i])); 38 } 39 } 40 return summary; 41 }; 42 43 jasmine.JsApiReporter.prototype.results = function() { 44 return this.results_; 45 }; 46 47 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { 48 return this.results_[specId]; 49 }; 50 51 //noinspection JSUnusedLocalSymbols 52 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { 53 this.finished = true; 54 }; 55 56 //noinspection JSUnusedLocalSymbols 57 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { 58 }; 59 60 //noinspection JSUnusedLocalSymbols 61 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { 62 this.results_[spec.id] = { 63 messages: spec.results().getItems(), 64 result: spec.results().failedCount > 0 ? "failed" : "passed" 65 }; 66 }; 67 68 //noinspection JSUnusedLocalSymbols 69 jasmine.JsApiReporter.prototype.log = function(str) { 70 }; 71 72 jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ 73 var results = {}; 74 for (var i = 0; i < specIds.length; i++) { 75 var specId = specIds[i]; 76 results[specId] = this.summarizeResult_(this.results_[specId]); 77 } 78 return results; 79 }; 80 81 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ 82 var summaryMessages = []; 83 var messagesLength = result.messages.length; 84 for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) { 85 var resultMessage = result.messages[messageIndex]; 86 summaryMessages.push({ 87 text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, 88 passed: resultMessage.passed ? resultMessage.passed() : true, 89 type: resultMessage.type, 90 message: resultMessage.message, 91 trace: { 92 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined 93 } 94 }); 95 } 96 97 return { 98 result : result.result, 99 messages : summaryMessages 100 }; 101 }; 102 103