js_api_reporter.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = JsApiReporter;
  6. /**
  7. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. *
  12. */
  13. // This file is a heavily modified fork of Jasmine. Original license:
  14. /*
  15. Copyright (c) 2008-2016 Pivotal Labs
  16. Permission is hereby granted, free of charge, to any person obtaining
  17. a copy of this software and associated documentation files (the
  18. "Software"), to deal in the Software without restriction, including
  19. without limitation the rights to use, copy, modify, merge, publish,
  20. distribute, sublicense, and/or sell copies of the Software, and to
  21. permit persons to whom the Software is furnished to do so, subject to
  22. the following conditions:
  23. The above copyright notice and this permission notice shall be
  24. included in all copies or substantial portions of the Software.
  25. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. */
  33. /* eslint-disable sort-keys */
  34. const noopTimer = {
  35. start: function() {},
  36. elapsed: function() {
  37. return 0;
  38. }
  39. };
  40. function JsApiReporter(options) {
  41. const timer = options.timer || noopTimer;
  42. let status = 'loaded';
  43. this.started = false;
  44. this.finished = false;
  45. this.runDetails = {};
  46. this.jasmineStarted = function() {
  47. this.started = true;
  48. status = 'started';
  49. timer.start();
  50. };
  51. let executionTime;
  52. function validateAfterAllExceptions(_ref) {
  53. let failedExpectations = _ref.failedExpectations;
  54. if (failedExpectations && failedExpectations.length > 0) {
  55. throw failedExpectations[0];
  56. }
  57. }
  58. this.jasmineDone = function(runDetails) {
  59. validateAfterAllExceptions(runDetails);
  60. this.finished = true;
  61. this.runDetails = runDetails;
  62. executionTime = timer.elapsed();
  63. status = 'done';
  64. };
  65. this.status = function() {
  66. return status;
  67. };
  68. const suites = [];
  69. const suites_hash = {};
  70. this.suiteStarted = function(result) {
  71. suites_hash[result.id] = result;
  72. };
  73. this.suiteDone = function(result) {
  74. storeSuite(result);
  75. };
  76. this.suiteResults = function(index, length) {
  77. return suites.slice(index, index + length);
  78. };
  79. function storeSuite(result) {
  80. suites.push(result);
  81. suites_hash[result.id] = result;
  82. }
  83. this.suites = function() {
  84. return suites_hash;
  85. };
  86. const specs = [];
  87. this.specDone = function(result) {
  88. specs.push(result);
  89. };
  90. this.specResults = function(index, length) {
  91. return specs.slice(index, index + length);
  92. };
  93. this.specs = function() {
  94. return specs;
  95. };
  96. this.executionTime = function() {
  97. return executionTime;
  98. };
  99. }