Blame view

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