summary-display.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var SummaryDisplay = (function () {
  4. function SummaryDisplay(logger, configuration, specs) {
  5. this.logger = logger;
  6. this.configuration = configuration;
  7. this.specs = specs;
  8. }
  9. SummaryDisplay.prototype.display = function (metrics) {
  10. var pluralizedSpec = (metrics.totalSpecsDefined === 1 ? " spec" : " specs");
  11. var execution = "Executed " + metrics.executedSpecs + " of " + metrics.totalSpecsDefined + pluralizedSpec;
  12. var status = "";
  13. if (metrics.failedSpecs === 0 && metrics.globalErrors.length === 0) {
  14. status = (metrics.totalSpecsDefined === metrics.executedSpecs) ?
  15. " SUCCESS".successful : " INCOMPLETE".pending;
  16. }
  17. var failed = (metrics.failedSpecs > 0) ? " (" + metrics.failedSpecs + " FAILED)" : "";
  18. var pending = (metrics.pendingSpecs > 0) ? " (" + metrics.pendingSpecs + " PENDING)" : "";
  19. var skipped = (metrics.skippedSpecs > 0) ? " (" + metrics.skippedSpecs + " SKIPPED)" : "";
  20. var errors = (metrics.globalErrors.length > 1) ? " (" + metrics.globalErrors.length + " ERRORS)" : "";
  21. errors = (metrics.globalErrors.length === 1) ? " (" + metrics.globalErrors.length + " ERROR)" : errors;
  22. var duration = this.configuration.summary.displayDuration ? " in " + metrics.duration : "";
  23. this.logger.resetIndent();
  24. this.logger.newLine();
  25. if (this.configuration.summary.displaySuccessful && metrics.successfulSpecs > 0) {
  26. this.successesSummary();
  27. }
  28. if (this.configuration.summary.displayFailed && metrics.failedSpecs > 0) {
  29. this.failuresSummary();
  30. }
  31. if (this.configuration.summary.displayFailed && metrics.globalErrors.length > 0) {
  32. this.errorsSummary(metrics.globalErrors);
  33. }
  34. if (this.configuration.summary.displayPending && metrics.pendingSpecs > 0) {
  35. this.pendingsSummary();
  36. }
  37. this.logger.log(execution + status + errors.failed + failed.failed
  38. + pending.pending + skipped.pending + duration + ".");
  39. if (metrics.random) {
  40. this.logger.log("Randomized with seed " + metrics.seed + ".");
  41. }
  42. };
  43. SummaryDisplay.prototype.successesSummary = function () {
  44. this.logger.log("**************************************************");
  45. this.logger.log("* Successes *");
  46. this.logger.log("**************************************************");
  47. this.logger.newLine();
  48. for (var i = 0; i < this.specs.successful.length; i++) {
  49. this.successfulSummary(this.specs.successful[i], i + 1);
  50. this.logger.newLine();
  51. }
  52. this.logger.newLine();
  53. this.logger.resetIndent();
  54. };
  55. SummaryDisplay.prototype.successfulSummary = function (spec, index) {
  56. this.logger.log(index + ") " + spec.fullName);
  57. };
  58. SummaryDisplay.prototype.failuresSummary = function () {
  59. this.logger.log("**************************************************");
  60. this.logger.log("* Failures *");
  61. this.logger.log("**************************************************");
  62. this.logger.newLine();
  63. for (var i = 0; i < this.specs.failed.length; i++) {
  64. this.failedSummary(this.specs.failed[i], i + 1);
  65. this.logger.newLine();
  66. }
  67. this.logger.newLine();
  68. this.logger.resetIndent();
  69. };
  70. SummaryDisplay.prototype.failedSummary = function (spec, index) {
  71. this.logger.log(index + ") " + spec.fullName);
  72. if (this.configuration.summary.displayErrorMessages) {
  73. this.logger.increaseIndent();
  74. this.logger.process(spec, function (displayProcessor, object, log) {
  75. return displayProcessor.displaySummaryErrorMessages(object, log);
  76. });
  77. this.logger.decreaseIndent();
  78. }
  79. };
  80. SummaryDisplay.prototype.pendingsSummary = function () {
  81. this.logger.log("**************************************************");
  82. this.logger.log("* Pending *");
  83. this.logger.log("**************************************************");
  84. this.logger.newLine();
  85. for (var i = 0; i < this.specs.pending.length; i++) {
  86. this.pendingSummary(this.specs.pending[i], i + 1);
  87. this.logger.newLine();
  88. }
  89. this.logger.newLine();
  90. this.logger.resetIndent();
  91. };
  92. SummaryDisplay.prototype.pendingSummary = function (spec, index) {
  93. this.logger.log(index + ") " + spec.fullName);
  94. this.logger.increaseIndent();
  95. var pendingReason = spec.pendingReason ? spec.pendingReason : "No reason given";
  96. this.logger.log(pendingReason.pending);
  97. this.logger.resetIndent();
  98. };
  99. SummaryDisplay.prototype.errorsSummary = function (errors) {
  100. this.logger.log("**************************************************");
  101. this.logger.log("* Errors *");
  102. this.logger.log("**************************************************");
  103. this.logger.newLine();
  104. for (var i = 0; i < errors.length; i++) {
  105. this.errorSummary(errors[i], i + 1);
  106. this.logger.newLine();
  107. }
  108. this.logger.newLine();
  109. this.logger.resetIndent();
  110. };
  111. SummaryDisplay.prototype.errorSummary = function (error, index) {
  112. this.logger.log(index + ") " + error.fullName);
  113. this.logger.increaseIndent();
  114. this.logger.process(error, function (displayProcessor, object, log) {
  115. return displayProcessor.displaySummaryErrorMessages(object, log);
  116. });
  117. this.logger.decreaseIndent();
  118. };
  119. return SummaryDisplay;
  120. }());
  121. exports.SummaryDisplay = SummaryDisplay;
  122. //# sourceMappingURL=summary-display.js.map