~ps-jenkins/cordova-ubuntu-tests/latestsnapshot-2.11+14.04.20131106-0ubuntu1

« back to all changes in this revision

Viewing changes to www/autotest/html/TrivialReporter.js

  • Committer: VĂ­ctor R. Ruiz
  • Date: 2013-07-25 13:09:34 UTC
  • Revision ID: victor.ruiz@canonical.com-20130725130934-d4q95mh8eehbv363
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @deprecated Use jasmine.HtmlReporter instead
 
2
 */
 
3
jasmine.TrivialReporter = function(doc) {
 
4
  this.document = doc || document;
 
5
  this.suiteDivs = {};
 
6
  this.logRunningSpecs = false;
 
7
};
 
8
 
 
9
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
 
10
  var el = document.createElement(type);
 
11
 
 
12
  for (var i = 2; i < arguments.length; i++) {
 
13
    var child = arguments[i];
 
14
 
 
15
    if (typeof child === 'string') {
 
16
      el.appendChild(document.createTextNode(child));
 
17
    } else {
 
18
      if (child) { el.appendChild(child); }
 
19
    }
 
20
  }
 
21
 
 
22
  for (var attr in attrs) {
 
23
    if (attr == "className") {
 
24
      el[attr] = attrs[attr];
 
25
    } else {
 
26
      el.setAttribute(attr, attrs[attr]);
 
27
    }
 
28
  }
 
29
 
 
30
  return el;
 
31
};
 
32
 
 
33
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
 
34
  var showPassed, showSkipped;
 
35
 
 
36
  this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
 
37
      this.createDom('div', { className: 'banner' },
 
38
        this.createDom('div', { className: 'logo' },
 
39
            this.createDom('span', { className: 'title' }, "Jasmine"),
 
40
            this.createDom('span', { className: 'version' }, runner.env.versionString())),
 
41
        this.createDom('div', { className: 'options' },
 
42
            "Show ",
 
43
            showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
 
44
            this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
 
45
            showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
 
46
            this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
 
47
            )
 
48
          ),
 
49
 
 
50
      this.runnerDiv = this.createDom('div', { className: 'runner running' },
 
51
          this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
 
52
          this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
 
53
          this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
 
54
      );
 
55
 
 
56
  this.document.body.appendChild(this.outerDiv);
 
57
 
 
58
  var suites = runner.suites();
 
59
  for (var i = 0; i < suites.length; i++) {
 
60
    var suite = suites[i];
 
61
    var suiteDiv = this.createDom('div', { className: 'suite' },
 
62
        this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
 
63
        this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
 
64
    this.suiteDivs[suite.id] = suiteDiv;
 
65
    var parentDiv = this.outerDiv;
 
66
    if (suite.parentSuite) {
 
67
      parentDiv = this.suiteDivs[suite.parentSuite.id];
 
68
    }
 
69
    parentDiv.appendChild(suiteDiv);
 
70
  }
 
71
 
 
72
  this.startedAt = new Date();
 
73
 
 
74
  var self = this;
 
75
  showPassed.onclick = function(evt) {
 
76
    if (showPassed.checked) {
 
77
      self.outerDiv.className += ' show-passed';
 
78
    } else {
 
79
      self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
 
80
    }
 
81
  };
 
82
 
 
83
  showSkipped.onclick = function(evt) {
 
84
    if (showSkipped.checked) {
 
85
      self.outerDiv.className += ' show-skipped';
 
86
    } else {
 
87
      self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
 
88
    }
 
89
  };
 
90
};
 
91
 
 
92
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
 
93
  var results = runner.results();
 
94
  var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
 
95
  this.runnerDiv.setAttribute("class", className);
 
96
  //do it twice for IE
 
97
  this.runnerDiv.setAttribute("className", className);
 
98
  var specs = runner.specs();
 
99
  var specCount = 0;
 
100
  for (var i = 0; i < specs.length; i++) {
 
101
    if (this.specFilter(specs[i])) {
 
102
      specCount++;
 
103
    }
 
104
  }
 
105
  var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
 
106
  message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
 
107
  this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
 
108
 
 
109
  this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
 
110
};
 
111
 
 
112
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
 
113
  var results = suite.results();
 
114
  var status = results.passed() ? 'passed' : 'failed';
 
115
  if (results.totalCount === 0) { // todo: change this to check results.skipped
 
116
    status = 'skipped';
 
117
  }
 
118
  this.suiteDivs[suite.id].className += " " + status;
 
119
};
 
120
 
 
121
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
 
122
  if (this.logRunningSpecs) {
 
123
    this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
 
124
  }
 
125
};
 
126
 
 
127
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
 
128
  var results = spec.results();
 
129
  var status = results.passed() ? 'passed' : 'failed';
 
130
  if (results.skipped) {
 
131
    status = 'skipped';
 
132
  }
 
133
  var specDiv = this.createDom('div', { className: 'spec '  + status },
 
134
      this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
 
135
      this.createDom('a', {
 
136
        className: 'description',
 
137
        href: '?spec=' + encodeURIComponent(spec.getFullName()),
 
138
        title: spec.getFullName()
 
139
      }, spec.description));
 
140
 
 
141
 
 
142
  var resultItems = results.getItems();
 
143
  var messagesDiv = this.createDom('div', { className: 'messages' });
 
144
  for (var i = 0; i < resultItems.length; i++) {
 
145
    var result = resultItems[i];
 
146
 
 
147
    if (result.type == 'log') {
 
148
      messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
 
149
    } else if (result.type == 'expect' && result.passed && !result.passed()) {
 
150
      messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
 
151
 
 
152
      if (result.trace.stack) {
 
153
        messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
 
154
      }
 
155
    }
 
156
  }
 
157
 
 
158
  if (messagesDiv.childNodes.length > 0) {
 
159
    specDiv.appendChild(messagesDiv);
 
160
  }
 
161
 
 
162
  this.suiteDivs[spec.suite.id].appendChild(specDiv);
 
163
};
 
164
 
 
165
jasmine.TrivialReporter.prototype.log = function() {
 
166
  var console = jasmine.getGlobal().console;
 
167
  if (console && console.log) {
 
168
    if (console.log.apply) {
 
169
      console.log.apply(console, arguments);
 
170
    } else {
 
171
      console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
 
172
    }
 
173
  }
 
174
};
 
175
 
 
176
jasmine.TrivialReporter.prototype.getLocation = function() {
 
177
  return this.document.location;
 
178
};
 
179
 
 
180
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
 
181
  var paramMap = {};
 
182
  var params = this.getLocation().search.substring(1).split('&');
 
183
  for (var i = 0; i < params.length; i++) {
 
184
    var p = params[i].split('=');
 
185
    paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
 
186
  }
 
187
 
 
188
  if (!paramMap.spec) {
 
189
    return true;
 
190
  }
 
191
  return spec.getFullName().indexOf(paramMap.spec) === 0;
 
192
};