PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/thirdparty/jasmine-ajax/examples/prototype/spec/javascripts/jasmine-0.11.1/jasmine-html.js

http://github.com/silverstripe/sapphire
JavaScript | 182 lines | 153 code | 28 blank | 1 comment | 38 complexity | b210d63f57edb2168493079abc203403 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, CC-BY-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. jasmine.TrivialReporter = function(doc) {
  2. this.document = doc || document;
  3. this.suiteDivs = {};
  4. this.logRunningSpecs = false;
  5. };
  6. jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
  7. var el = document.createElement(type);
  8. for (var i = 2; i < arguments.length; i++) {
  9. var child = arguments[i];
  10. if (typeof child === 'string') {
  11. el.appendChild(document.createTextNode(child));
  12. } else {
  13. if (child) { el.appendChild(child); }
  14. }
  15. }
  16. for (var attr in attrs) {
  17. if (attr == "className") {
  18. el[attr] = attrs[attr];
  19. } else {
  20. el.setAttribute(attr, attrs[attr]);
  21. }
  22. }
  23. return el;
  24. };
  25. jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
  26. var showPassed, showSkipped;
  27. this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
  28. this.createDom('div', { className: 'banner' },
  29. this.createDom('div', { className: 'logo' },
  30. "Jasmine",
  31. this.createDom('span', { className: 'version' }, runner.env.versionString())),
  32. this.createDom('div', { className: 'options' },
  33. "Show ",
  34. showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
  35. this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
  36. showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
  37. this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
  38. )
  39. ),
  40. this.runnerDiv = this.createDom('div', { className: 'runner running' },
  41. this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
  42. this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
  43. this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
  44. );
  45. this.document.body.appendChild(this.outerDiv);
  46. var suites = runner.suites();
  47. for (var i = 0; i < suites.length; i++) {
  48. var suite = suites[i];
  49. var suiteDiv = this.createDom('div', { className: 'suite' },
  50. this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
  51. this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
  52. this.suiteDivs[suite.id] = suiteDiv;
  53. var parentDiv = this.outerDiv;
  54. if (suite.parentSuite) {
  55. parentDiv = this.suiteDivs[suite.parentSuite.id];
  56. }
  57. parentDiv.appendChild(suiteDiv);
  58. }
  59. this.startedAt = new Date();
  60. var self = this;
  61. showPassed.onchange = function(evt) {
  62. if (evt.target.checked) {
  63. self.outerDiv.className += ' show-passed';
  64. } else {
  65. self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
  66. }
  67. };
  68. showSkipped.onchange = function(evt) {
  69. if (evt.target.checked) {
  70. self.outerDiv.className += ' show-skipped';
  71. } else {
  72. self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
  73. }
  74. };
  75. };
  76. jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
  77. var results = runner.results();
  78. var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
  79. this.runnerDiv.setAttribute("class", className);
  80. //do it twice for IE
  81. this.runnerDiv.setAttribute("className", className);
  82. var specs = runner.specs();
  83. var specCount = 0;
  84. for (var i = 0; i < specs.length; i++) {
  85. if (this.specFilter(specs[i])) {
  86. specCount++;
  87. }
  88. }
  89. var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
  90. message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
  91. this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
  92. this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
  93. };
  94. jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
  95. var results = suite.results();
  96. var status = results.passed() ? 'passed' : 'failed';
  97. if (results.totalCount == 0) { // todo: change this to check results.skipped
  98. status = 'skipped';
  99. }
  100. this.suiteDivs[suite.id].className += " " + status;
  101. };
  102. jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
  103. if (this.logRunningSpecs) {
  104. this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
  105. }
  106. };
  107. jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
  108. var results = spec.results();
  109. var status = results.passed() ? 'passed' : 'failed';
  110. if (results.skipped) {
  111. status = 'skipped';
  112. }
  113. var specDiv = this.createDom('div', { className: 'spec ' + status },
  114. this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
  115. this.createDom('a', {
  116. className: 'description',
  117. href: '?spec=' + encodeURIComponent(spec.getFullName()),
  118. title: spec.getFullName()
  119. }, spec.description));
  120. var resultItems = results.getItems();
  121. var messagesDiv = this.createDom('div', { className: 'messages' });
  122. for (var i = 0; i < resultItems.length; i++) {
  123. var result = resultItems[i];
  124. if (result.type == 'log') {
  125. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
  126. } else if (result.type == 'expect' && result.passed && !result.passed()) {
  127. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
  128. if (result.trace.stack) {
  129. messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
  130. }
  131. }
  132. }
  133. if (messagesDiv.childNodes.length > 0) {
  134. specDiv.appendChild(messagesDiv);
  135. }
  136. this.suiteDivs[spec.suite.id].appendChild(specDiv);
  137. };
  138. jasmine.TrivialReporter.prototype.log = function() {
  139. var console = jasmine.getGlobal().console;
  140. if (console && console.log) console.log.apply(console, arguments);
  141. };
  142. jasmine.TrivialReporter.prototype.getLocation = function() {
  143. return this.document.location;
  144. };
  145. jasmine.TrivialReporter.prototype.specFilter = function(spec) {
  146. var paramMap = {};
  147. var params = this.getLocation().search.substring(1).split('&');
  148. for (var i = 0; i < params.length; i++) {
  149. var p = params[i].split('=');
  150. paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
  151. }
  152. if (!paramMap["spec"]) return true;
  153. return spec.getFullName().indexOf(paramMap["spec"]) == 0;
  154. };