execution-display.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var colors_display_1 = require("./colors-display");
  4. var ExecutionDisplay = (function () {
  5. function ExecutionDisplay(configuration, logger, specs, displayProcessors) {
  6. this.configuration = configuration;
  7. this.logger = logger;
  8. this.specs = specs;
  9. this.suiteHierarchy = [];
  10. this.suiteHierarchyDisplayed = [];
  11. colors_display_1.ColorsDisplay.init(this.configuration);
  12. this.hasCustomDisplaySpecStarted = ExecutionDisplay.hasCustomDisplaySpecStarted(displayProcessors);
  13. }
  14. ExecutionDisplay.hasCustomDisplaySpecStarted = function (processors) {
  15. var isDisplayed = false;
  16. processors.forEach(function (processor) {
  17. var log = "foo";
  18. var result = processor.displaySpecStarted({ id: "bar", description: "bar", fullName: "bar" }, log);
  19. isDisplayed = isDisplayed || result !== log;
  20. });
  21. return isDisplayed;
  22. };
  23. ExecutionDisplay.prototype.jasmineStarted = function (suiteInfo) {
  24. this.logger.process(suiteInfo, function (displayProcessor, object, log) {
  25. return displayProcessor.displayJasmineStarted(object, log);
  26. });
  27. };
  28. ExecutionDisplay.prototype.specStarted = function (result) {
  29. if (this.hasCustomDisplaySpecStarted) {
  30. this.ensureSuiteDisplayed();
  31. this.logger.process(result, function (displayProcessor, object, log) {
  32. return displayProcessor.displaySpecStarted(object, log);
  33. });
  34. }
  35. };
  36. ExecutionDisplay.prototype.successful = function (result) {
  37. this.specs.successful.push(result);
  38. if (this.configuration.spec.displaySuccessful) {
  39. this.ensureSuiteDisplayed();
  40. this.logger.process(result, function (displayProcessor, object, log) {
  41. return displayProcessor.displaySuccessfulSpec(object, log);
  42. });
  43. }
  44. };
  45. ExecutionDisplay.prototype.failed = function (result) {
  46. this.specs.failed.push(result);
  47. if (this.configuration.spec.displayFailed) {
  48. this.ensureSuiteDisplayed();
  49. this.logger.process(result, function (displayProcessor, object, log) {
  50. return displayProcessor.displayFailedSpec(object, log);
  51. });
  52. if (this.configuration.spec.displayErrorMessages) {
  53. this.logger.increaseIndent();
  54. this.logger.process(result, function (displayProcessor, object, log) {
  55. return displayProcessor.displaySpecErrorMessages(object, log);
  56. });
  57. this.logger.decreaseIndent();
  58. }
  59. }
  60. };
  61. ExecutionDisplay.prototype.pending = function (result) {
  62. this.specs.pending.push(result);
  63. if (this.configuration.spec.displayPending) {
  64. this.ensureSuiteDisplayed();
  65. this.logger.process(result, function (displayProcessor, object, log) {
  66. return displayProcessor.displayPendingSpec(object, log);
  67. });
  68. }
  69. };
  70. ExecutionDisplay.prototype.suiteStarted = function (result) {
  71. this.suiteHierarchy.push(result);
  72. };
  73. ExecutionDisplay.prototype.suiteDone = function (result) {
  74. if (result && result.failedExpectations && result.failedExpectations.length) {
  75. this.failed(result);
  76. }
  77. var suite = this.suiteHierarchy.pop();
  78. if (this.suiteHierarchyDisplayed[this.suiteHierarchyDisplayed.length - 1] === suite) {
  79. this.suiteHierarchyDisplayed.pop();
  80. }
  81. this.logger.newLine();
  82. this.logger.decreaseIndent();
  83. };
  84. ExecutionDisplay.prototype.ensureSuiteDisplayed = function () {
  85. if (this.suiteHierarchy.length !== 0) {
  86. for (var i = this.suiteHierarchyDisplayed.length; i < this.suiteHierarchy.length; i++) {
  87. this.suiteHierarchyDisplayed.push(this.suiteHierarchy[i]);
  88. this.displaySuite(this.suiteHierarchy[i]);
  89. }
  90. }
  91. else {
  92. var name_1 = "Top level suite";
  93. var topLevelSuite = {
  94. description: name_1,
  95. fullName: name_1,
  96. id: name_1,
  97. };
  98. this.suiteHierarchy.push(topLevelSuite);
  99. this.suiteHierarchyDisplayed.push(topLevelSuite);
  100. this.displaySuite(topLevelSuite);
  101. }
  102. };
  103. ExecutionDisplay.prototype.displaySuite = function (suite) {
  104. this.logger.newLine();
  105. this.computeSuiteIndent();
  106. this.logger.process(suite, function (displayProcessor, object, log) {
  107. return displayProcessor.displaySuite(object, log);
  108. });
  109. this.logger.increaseIndent();
  110. };
  111. ExecutionDisplay.prototype.computeSuiteIndent = function () {
  112. var _this = this;
  113. this.logger.resetIndent();
  114. this.suiteHierarchyDisplayed.forEach(function () { return _this.logger.increaseIndent(); });
  115. };
  116. return ExecutionDisplay;
  117. }());
  118. exports.ExecutionDisplay = ExecutionDisplay;
  119. //# sourceMappingURL=execution-display.js.map