spec-reporter.js 4.6 KB

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