JsApiReporter.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* eslint-disable sort-keys */
  47. const noopTimer = {
  48. start() {},
  49. elapsed() {
  50. return 0;
  51. }
  52. };
  53. class JsApiReporter {
  54. constructor(options) {
  55. _defineProperty(this, 'started', void 0);
  56. _defineProperty(this, 'finished', void 0);
  57. _defineProperty(this, 'runDetails', void 0);
  58. _defineProperty(this, 'jasmineStarted', void 0);
  59. _defineProperty(this, 'jasmineDone', void 0);
  60. _defineProperty(this, 'status', void 0);
  61. _defineProperty(this, 'executionTime', void 0);
  62. _defineProperty(this, 'suiteStarted', void 0);
  63. _defineProperty(this, 'suiteDone', void 0);
  64. _defineProperty(this, 'suiteResults', void 0);
  65. _defineProperty(this, 'suites', void 0);
  66. _defineProperty(this, 'specResults', void 0);
  67. _defineProperty(this, 'specDone', void 0);
  68. _defineProperty(this, 'specs', void 0);
  69. _defineProperty(this, 'specStarted', void 0);
  70. const timer = options.timer || noopTimer;
  71. let status = 'loaded';
  72. this.started = false;
  73. this.finished = false;
  74. this.runDetails = {};
  75. this.jasmineStarted = () => {
  76. this.started = true;
  77. status = 'started';
  78. timer.start();
  79. };
  80. let executionTime;
  81. function validateAfterAllExceptions({failedExpectations}) {
  82. if (failedExpectations && failedExpectations.length > 0) {
  83. throw failedExpectations[0];
  84. }
  85. }
  86. this.jasmineDone = function (runDetails) {
  87. validateAfterAllExceptions(runDetails);
  88. this.finished = true;
  89. this.runDetails = runDetails;
  90. executionTime = timer.elapsed();
  91. status = 'done';
  92. };
  93. this.status = function () {
  94. return status;
  95. };
  96. const suites = [];
  97. const suites_hash = {};
  98. this.specStarted = function () {};
  99. this.suiteStarted = function (result) {
  100. suites_hash[result.id] = result;
  101. };
  102. this.suiteDone = function (result) {
  103. storeSuite(result);
  104. };
  105. this.suiteResults = function (index, length) {
  106. return suites.slice(index, index + length);
  107. };
  108. function storeSuite(result) {
  109. suites.push(result);
  110. suites_hash[result.id] = result;
  111. }
  112. this.suites = function () {
  113. return suites_hash;
  114. };
  115. const specs = [];
  116. this.specDone = function (result) {
  117. specs.push(result);
  118. };
  119. this.specResults = function (index, length) {
  120. return specs.slice(index, index + length);
  121. };
  122. this.specs = function () {
  123. return specs;
  124. };
  125. this.executionTime = function () {
  126. return executionTime;
  127. };
  128. }
  129. }
  130. exports.default = JsApiReporter;