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   var messagesLength = result.messages.length
 83   for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
 84     var resultMessage = result.messages[messageIndex];
 85     summaryMessages.push({
 86       text: resultMessage.text,
 87       passed: resultMessage.passed ? resultMessage.passed() : true,
 88       type: resultMessage.type,
 89       message: resultMessage.message,
 90       trace: {
 91         stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
 92       }
 93     });
 94   };
 95 
 96   var summaryResult = {
 97     result : result.result,
 98     messages : summaryMessages
 99   };
100 
101   return summaryResult;
102 };
103 
104