execution-display.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var colors_display_1 = require("./display/colors-display");
  4. var default_processor_1 = require("./display/processors/default-processor");
  5. var spec_colors_processor_1 = require("./display/processors/spec-colors-processor");
  6. var spec_durations_processor_1 = require("./display/processors/spec-durations-processor");
  7. var spec_prefixes_processor_1 = require("./display/processors/spec-prefixes-processor");
  8. var suite_numbering_processor_1 = require("./display/processors/suite-numbering-processor");
  9. var ExecutionDisplay = (function () {
  10. function ExecutionDisplay(configuration) {
  11. this.configuration = configuration;
  12. this.indent = " ";
  13. this.currentIndent = "";
  14. this.suiteHierarchy = [];
  15. this.suiteHierarchyDisplayed = [];
  16. this.successfulSpecs = [];
  17. this.failedSpecs = [];
  18. this.pendingSpecs = [];
  19. this.lastWasNewLine = false;
  20. colors_display_1.ColorsDisplay.init(this.configuration);
  21. this.displayProcessors = ExecutionDisplay.initProcessors(this.configuration);
  22. this.hasCustomDisplaySpecStarted = ExecutionDisplay.hasCustomDisplaySpecStarted(this.displayProcessors);
  23. }
  24. ExecutionDisplay.initProcessors = function (configuration) {
  25. var displayProcessors = [
  26. new default_processor_1.DefaultProcessor(configuration),
  27. new spec_prefixes_processor_1.SpecPrefixesProcessor(configuration),
  28. new spec_colors_processor_1.SpecColorsProcessor(configuration),
  29. ];
  30. if (configuration.spec.displayDuration) {
  31. displayProcessors.push(new spec_durations_processor_1.SpecDurationsProcessor(configuration));
  32. }
  33. if (configuration.suite.displayNumber) {
  34. displayProcessors.push(new suite_numbering_processor_1.SuiteNumberingProcessor(configuration));
  35. }
  36. if (configuration.customProcessors) {
  37. configuration.customProcessors.forEach(function (Processor) {
  38. displayProcessors.push(new Processor(configuration));
  39. });
  40. }
  41. return displayProcessors;
  42. };
  43. ExecutionDisplay.hasCustomDisplaySpecStarted = function (processors) {
  44. var isDisplayed = false;
  45. processors.forEach(function (processor) {
  46. var log = "foo";
  47. var result = processor.displaySpecStarted({ id: "bar", description: "bar", fullName: "bar" }, log);
  48. isDisplayed = isDisplayed || result !== log;
  49. });
  50. return isDisplayed;
  51. };
  52. ExecutionDisplay.prototype.jasmineStarted = function (suiteInfo) {
  53. this.process(suiteInfo, function (displayProcessor, object, log) {
  54. return displayProcessor.displayJasmineStarted(object, log);
  55. });
  56. };
  57. ExecutionDisplay.prototype.summary = function (metrics) {
  58. var pluralizedSpec = (metrics.totalSpecsDefined === 1 ? " spec" : " specs");
  59. var execution = "Executed " + metrics.executedSpecs + " of " + metrics.totalSpecsDefined + pluralizedSpec;
  60. var successful = (metrics.failedSpecs === 0) ? " SUCCESS" : "";
  61. var failed = (metrics.failedSpecs > 0) ? " (" + metrics.failedSpecs + " FAILED)" : "";
  62. var pending = (metrics.pendingSpecs > 0) ? " (" + metrics.pendingSpecs + " PENDING)" : "";
  63. var skipped = (metrics.skippedSpecs > 0) ? " (" + metrics.skippedSpecs + " SKIPPED)" : "";
  64. var duration = this.configuration.summary.displayDuration ? " in " + metrics.duration : "";
  65. this.resetIndent();
  66. this.newLine();
  67. if (this.configuration.summary.displaySuccessful && metrics.successfulSpecs > 0) {
  68. this.successesSummary();
  69. }
  70. if (this.configuration.summary.displayFailed && metrics.failedSpecs > 0) {
  71. this.failuresSummary();
  72. }
  73. if (this.configuration.summary.displayPending && metrics.pendingSpecs > 0) {
  74. this.pendingsSummary();
  75. }
  76. this.log(execution + successful.successful + failed.failed + pending.pending + skipped + duration + ".");
  77. if (metrics.random) {
  78. this.log("Randomized with seed " + metrics.seed + ".");
  79. }
  80. };
  81. ExecutionDisplay.prototype.specStarted = function (result) {
  82. if (this.hasCustomDisplaySpecStarted) {
  83. this.ensureSuiteDisplayed();
  84. this.process(result, function (displayProcessor, object, log) {
  85. return displayProcessor.displaySpecStarted(object, log);
  86. });
  87. }
  88. };
  89. ExecutionDisplay.prototype.successful = function (result) {
  90. this.successfulSpecs.push(result);
  91. if (this.configuration.spec.displaySuccessful) {
  92. this.ensureSuiteDisplayed();
  93. this.process(result, function (displayProcessor, object, log) {
  94. return displayProcessor.displaySuccessfulSpec(object, log);
  95. });
  96. }
  97. };
  98. ExecutionDisplay.prototype.failed = function (result) {
  99. this.failedSpecs.push(result);
  100. if (this.configuration.spec.displayFailed) {
  101. this.ensureSuiteDisplayed();
  102. this.process(result, function (displayProcessor, object, log) {
  103. return displayProcessor.displayFailedSpec(object, log);
  104. });
  105. if (this.configuration.spec.displayErrorMessages) {
  106. this.increaseIndent();
  107. this.process(result, function (displayProcessor, object, log) {
  108. return displayProcessor.displaySpecErrorMessages(object, log);
  109. });
  110. this.decreaseIndent();
  111. }
  112. }
  113. };
  114. ExecutionDisplay.prototype.pending = function (result) {
  115. this.pendingSpecs.push(result);
  116. if (this.configuration.spec.displayPending) {
  117. this.ensureSuiteDisplayed();
  118. this.process(result, function (displayProcessor, object, log) {
  119. return displayProcessor.displayPendingSpec(object, log);
  120. });
  121. }
  122. };
  123. ExecutionDisplay.prototype.suiteStarted = function (result) {
  124. this.suiteHierarchy.push(result);
  125. };
  126. ExecutionDisplay.prototype.suiteDone = function () {
  127. var suite = this.suiteHierarchy.pop();
  128. if (this.suiteHierarchyDisplayed[this.suiteHierarchyDisplayed.length - 1] === suite) {
  129. this.suiteHierarchyDisplayed.pop();
  130. }
  131. this.newLine();
  132. this.decreaseIndent();
  133. };
  134. ExecutionDisplay.prototype.successesSummary = function () {
  135. this.log("**************************************************");
  136. this.log("* Successes *");
  137. this.log("**************************************************");
  138. this.newLine();
  139. for (var i = 0; i < this.successfulSpecs.length; i++) {
  140. this.successfulSummary(this.successfulSpecs[i], i + 1);
  141. this.newLine();
  142. }
  143. this.newLine();
  144. this.resetIndent();
  145. };
  146. ExecutionDisplay.prototype.successfulSummary = function (spec, index) {
  147. this.log(index + ") " + spec.fullName);
  148. };
  149. ExecutionDisplay.prototype.failuresSummary = function () {
  150. this.log("**************************************************");
  151. this.log("* Failures *");
  152. this.log("**************************************************");
  153. this.newLine();
  154. for (var i = 0; i < this.failedSpecs.length; i++) {
  155. this.failedSummary(this.failedSpecs[i], i + 1);
  156. this.newLine();
  157. }
  158. this.newLine();
  159. this.resetIndent();
  160. };
  161. ExecutionDisplay.prototype.failedSummary = function (spec, index) {
  162. this.log(index + ") " + spec.fullName);
  163. if (this.configuration.summary.displayErrorMessages) {
  164. this.increaseIndent();
  165. this.process(spec, function (displayProcessor, object, log) {
  166. return displayProcessor.displaySummaryErrorMessages(object, log);
  167. });
  168. this.decreaseIndent();
  169. }
  170. };
  171. ExecutionDisplay.prototype.pendingsSummary = function () {
  172. this.log("**************************************************");
  173. this.log("* Pending *");
  174. this.log("**************************************************");
  175. this.newLine();
  176. for (var i = 0; i < this.pendingSpecs.length; i++) {
  177. this.pendingSummary(this.pendingSpecs[i], i + 1);
  178. this.newLine();
  179. }
  180. this.newLine();
  181. this.resetIndent();
  182. };
  183. ExecutionDisplay.prototype.pendingSummary = function (spec, index) {
  184. this.log(index + ") " + spec.fullName);
  185. this.increaseIndent();
  186. var pendingReason = spec.pendingReason ? spec.pendingReason : "No reason given";
  187. this.log(pendingReason.pending);
  188. this.resetIndent();
  189. };
  190. ExecutionDisplay.prototype.ensureSuiteDisplayed = function () {
  191. if (this.suiteHierarchy.length !== 0) {
  192. for (var i = this.suiteHierarchyDisplayed.length; i < this.suiteHierarchy.length; i++) {
  193. this.suiteHierarchyDisplayed.push(this.suiteHierarchy[i]);
  194. this.displaySuite(this.suiteHierarchy[i]);
  195. }
  196. }
  197. else {
  198. var name_1 = "Top level suite";
  199. var topLevelSuite = {
  200. description: name_1,
  201. fullName: name_1,
  202. id: name_1,
  203. };
  204. this.suiteHierarchy.push(topLevelSuite);
  205. this.suiteHierarchyDisplayed.push(topLevelSuite);
  206. this.displaySuite(topLevelSuite);
  207. }
  208. };
  209. ExecutionDisplay.prototype.displaySuite = function (suite) {
  210. this.newLine();
  211. this.computeSuiteIndent();
  212. this.process(suite, function (displayProcessor, object, log) {
  213. return displayProcessor.displaySuite(object, log);
  214. });
  215. this.increaseIndent();
  216. };
  217. ExecutionDisplay.prototype.process = function (object, processFunction) {
  218. var log = "";
  219. this.displayProcessors.forEach(function (displayProcessor) {
  220. log = processFunction(displayProcessor, object, log);
  221. });
  222. this.log(log);
  223. };
  224. ExecutionDisplay.prototype.computeSuiteIndent = function () {
  225. var _this = this;
  226. this.resetIndent();
  227. this.suiteHierarchyDisplayed.forEach(function () { return _this.increaseIndent(); });
  228. };
  229. ExecutionDisplay.prototype.log = function (stuff) {
  230. var _this = this;
  231. stuff.split("\n").forEach(function (line) {
  232. console.log(line !== "" ? _this.currentIndent + line : line);
  233. });
  234. this.lastWasNewLine = false;
  235. };
  236. ExecutionDisplay.prototype.newLine = function () {
  237. if (!this.lastWasNewLine) {
  238. console.log("");
  239. this.lastWasNewLine = true;
  240. }
  241. };
  242. ExecutionDisplay.prototype.resetIndent = function () {
  243. this.currentIndent = "";
  244. };
  245. ExecutionDisplay.prototype.increaseIndent = function () {
  246. this.currentIndent += this.indent;
  247. };
  248. ExecutionDisplay.prototype.decreaseIndent = function () {
  249. this.currentIndent = this.currentIndent.substr(0, this.currentIndent.length - this.indent.length);
  250. };
  251. return ExecutionDisplay;
  252. }());
  253. exports.ExecutionDisplay = ExecutionDisplay;
  254. //# sourceMappingURL=execution-display.js.map