spec-reporter.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SpecReporter = void 0;
  4. var ConfigurationParser = require("./configuration-parser");
  5. var execution_display_1 = require("./display/execution-display");
  6. var logger_1 = require("./display/logger");
  7. var summary_display_1 = require("./display/summary-display");
  8. var execution_metrics_1 = require("./execution-metrics");
  9. var default_processor_1 = require("./processors/default-processor");
  10. var pretty_stacktrace_processor_1 = require("./processors/pretty-stacktrace-processor");
  11. var spec_colors_processor_1 = require("./processors/spec-colors-processor");
  12. var spec_durations_processor_1 = require("./processors/spec-durations-processor");
  13. var spec_prefixes_processor_1 = require("./processors/spec-prefixes-processor");
  14. var suite_numbering_processor_1 = require("./processors/suite-numbering-processor");
  15. var theme_1 = require("./theme");
  16. var SpecReporter = /** @class */ (function () {
  17. function SpecReporter(configuration) {
  18. this.specs = {
  19. failed: [],
  20. pending: [],
  21. successful: []
  22. };
  23. this.configuration = ConfigurationParser.parse(configuration);
  24. this.theme = new theme_1.Theme(this.configuration);
  25. var displayProcessors = SpecReporter.initProcessors(this.configuration, this.theme);
  26. var print = this.configuration.print;
  27. this.logger = new logger_1.Logger(displayProcessors, print);
  28. this.display = new execution_display_1.ExecutionDisplay(this.configuration, this.logger, this.specs, displayProcessors);
  29. this.summary = new summary_display_1.SummaryDisplay(this.configuration, this.theme, this.logger, this.specs);
  30. this.metrics = new execution_metrics_1.ExecutionMetrics();
  31. }
  32. SpecReporter.initProcessors = function (configuration, theme) {
  33. var displayProcessors = [
  34. new default_processor_1.DefaultProcessor(configuration, theme),
  35. new spec_prefixes_processor_1.SpecPrefixesProcessor(configuration, theme),
  36. new spec_colors_processor_1.SpecColorsProcessor(configuration, theme),
  37. new pretty_stacktrace_processor_1.PrettyStacktraceProcessor(configuration, theme)
  38. ];
  39. if (configuration.spec.displayDuration) {
  40. displayProcessors.push(new spec_durations_processor_1.SpecDurationsProcessor(configuration, theme));
  41. }
  42. if (configuration.suite.displayNumber) {
  43. displayProcessors.push(new suite_numbering_processor_1.SuiteNumberingProcessor(configuration, theme));
  44. }
  45. if (configuration.customProcessors) {
  46. configuration.customProcessors.forEach(function (Processor) {
  47. displayProcessors.push(new Processor(configuration, theme));
  48. });
  49. }
  50. return displayProcessors;
  51. };
  52. SpecReporter.prototype.jasmineStarted = function (suiteInfo) {
  53. this.metrics.start(suiteInfo);
  54. this.display.jasmineStarted(suiteInfo);
  55. };
  56. SpecReporter.prototype.jasmineDone = function (runDetails) {
  57. this.metrics.stop(runDetails);
  58. if (runDetails.failedExpectations && runDetails.failedExpectations.length) {
  59. var error = this.runDetailsToResult(runDetails);
  60. this.metrics.globalErrors.push(error);
  61. this.display.failed(error);
  62. }
  63. this.summary.display(this.metrics);
  64. };
  65. SpecReporter.prototype.suiteStarted = function (result) {
  66. this.display.suiteStarted(result);
  67. };
  68. SpecReporter.prototype.suiteDone = function (result) {
  69. this.display.suiteDone(result);
  70. if (result.failedExpectations.length) {
  71. this.metrics.globalErrors.push(result);
  72. }
  73. };
  74. SpecReporter.prototype.specStarted = function (result) {
  75. this.metrics.startSpec();
  76. this.display.specStarted(result);
  77. };
  78. SpecReporter.prototype.specDone = function (result) {
  79. this.metrics.stopSpec(result);
  80. if (result.status === "pending") {
  81. this.metrics.pendingSpecs++;
  82. this.display.pending(result);
  83. }
  84. else if (result.status === "passed") {
  85. this.metrics.successfulSpecs++;
  86. this.display.successful(result);
  87. }
  88. else if (result.status === "failed") {
  89. this.metrics.failedSpecs++;
  90. this.display.failed(result);
  91. }
  92. };
  93. SpecReporter.prototype.runDetailsToResult = function (runDetails) {
  94. return {
  95. description: "Non-spec failure",
  96. failedExpectations: runDetails.failedExpectations.map(function (expectation) {
  97. return {
  98. actual: "",
  99. expected: "",
  100. matcherName: "",
  101. message: expectation.message,
  102. passed: false,
  103. stack: expectation.stack,
  104. };
  105. }),
  106. fullName: "Non-spec failure",
  107. id: "Non-spec failure",
  108. duration: null,
  109. properties: null
  110. };
  111. };
  112. return SpecReporter;
  113. }());
  114. exports.SpecReporter = SpecReporter;
  115. //# sourceMappingURL=spec-reporter.js.map