ReportDispatcher.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _defineProperty(obj, key, value) {
  7. if (key in obj) {
  8. Object.defineProperty(obj, key, {
  9. value: value,
  10. enumerable: true,
  11. configurable: true,
  12. writable: true
  13. });
  14. } else {
  15. obj[key] = value;
  16. }
  17. return obj;
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. */
  26. // This file is a heavily modified fork of Jasmine. Original license:
  27. /*
  28. Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  29. Permission is hereby granted, free of charge, to any person obtaining
  30. a copy of this software and associated documentation files (the
  31. "Software"), to deal in the Software without restriction, including
  32. without limitation the rights to use, copy, modify, merge, publish,
  33. distribute, sublicense, and/or sell copies of the Software, and to
  34. permit persons to whom the Software is furnished to do so, subject to
  35. the following conditions:
  36. The above copyright notice and this permission notice shall be
  37. included in all copies or substantial portions of the Software.
  38. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  39. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  40. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  41. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  42. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  43. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  44. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45. */
  46. class ReportDispatcher {
  47. // @ts-ignore
  48. // @ts-ignore
  49. // @ts-ignore
  50. // @ts-ignore
  51. // @ts-ignore
  52. // @ts-ignore
  53. constructor(methods) {
  54. _defineProperty(this, 'addReporter', void 0);
  55. _defineProperty(this, 'provideFallbackReporter', void 0);
  56. _defineProperty(this, 'clearReporters', void 0);
  57. _defineProperty(this, 'jasmineDone', void 0);
  58. _defineProperty(this, 'jasmineStarted', void 0);
  59. _defineProperty(this, 'specDone', void 0);
  60. _defineProperty(this, 'specStarted', void 0);
  61. _defineProperty(this, 'suiteDone', void 0);
  62. _defineProperty(this, 'suiteStarted', void 0);
  63. const dispatchedMethods = methods || [];
  64. for (let i = 0; i < dispatchedMethods.length; i++) {
  65. const method = dispatchedMethods[i];
  66. this[method] = (function(m) {
  67. return function() {
  68. dispatch(m, arguments);
  69. };
  70. })(method);
  71. }
  72. let reporters = [];
  73. let fallbackReporter = null;
  74. this.addReporter = function(reporter) {
  75. reporters.push(reporter);
  76. };
  77. this.provideFallbackReporter = function(reporter) {
  78. fallbackReporter = reporter;
  79. };
  80. this.clearReporters = function() {
  81. reporters = [];
  82. };
  83. return this;
  84. function dispatch(method, args) {
  85. if (reporters.length === 0 && fallbackReporter !== null) {
  86. reporters.push(fallbackReporter);
  87. }
  88. for (let i = 0; i < reporters.length; i++) {
  89. const reporter = reporters[i];
  90. if (reporter[method]) {
  91. // @ts-ignore
  92. reporter[method].apply(reporter, args);
  93. }
  94. }
  95. }
  96. }
  97. }
  98. exports.default = ReportDispatcher;