summary-display.js 6.0 KB

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