jasmineLight.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.create = exports._interface = void 0;
  6. var _Env = _interopRequireDefault(require('./Env'));
  7. var _JsApiReporter = _interopRequireDefault(require('./JsApiReporter'));
  8. var _ReportDispatcher = _interopRequireDefault(require('./ReportDispatcher'));
  9. var _Spec = _interopRequireDefault(require('./Spec'));
  10. var _Suite = _interopRequireDefault(require('./Suite'));
  11. var _Timer = _interopRequireDefault(require('./Timer'));
  12. var _createSpy = _interopRequireDefault(require('./createSpy'));
  13. var _spyRegistry = _interopRequireDefault(require('./spyRegistry'));
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {default: obj};
  16. }
  17. /**
  18. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  19. *
  20. * This source code is licensed under the MIT license found in the
  21. * LICENSE file in the root directory of this source tree.
  22. *
  23. */
  24. // This file is a heavily modified fork of Jasmine. Original license:
  25. /*
  26. Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  27. Permission is hereby granted, free of charge, to any person obtaining
  28. a copy of this software and associated documentation files (the
  29. "Software"), to deal in the Software without restriction, including
  30. without limitation the rights to use, copy, modify, merge, publish,
  31. distribute, sublicense, and/or sell copies of the Software, and to
  32. permit persons to whom the Software is furnished to do so, subject to
  33. the following conditions:
  34. The above copyright notice and this permission notice shall be
  35. included in all copies or substantial portions of the Software.
  36. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  37. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  38. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  39. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  40. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  41. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  42. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  43. */
  44. /* eslint-disable sort-keys, local/prefer-spread-eventually, local/prefer-rest-params-eventually */
  45. const create = function (createOptions) {
  46. const j$ = {...createOptions};
  47. j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000;
  48. j$.getEnv = function () {
  49. const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env()); //jasmine. singletons in here (setTimeout blah blah).
  50. return env;
  51. };
  52. j$.createSpy = _createSpy.default;
  53. j$.Env = (0, _Env.default)(j$);
  54. j$.JsApiReporter = _JsApiReporter.default;
  55. j$.ReportDispatcher = _ReportDispatcher.default;
  56. j$.Spec = _Spec.default;
  57. j$.SpyRegistry = _spyRegistry.default;
  58. j$.Suite = _Suite.default;
  59. j$.Timer = _Timer.default;
  60. j$.version = '2.5.2-light';
  61. return j$;
  62. }; // Interface is a reserved word in strict mode, so can't export it as ESM
  63. exports.create = create;
  64. const _interface = function (jasmine, env) {
  65. const jasmineInterface = {
  66. describe(description, specDefinitions) {
  67. return env.describe(description, specDefinitions);
  68. },
  69. xdescribe(description, specDefinitions) {
  70. return env.xdescribe(description, specDefinitions);
  71. },
  72. fdescribe(description, specDefinitions) {
  73. return env.fdescribe(description, specDefinitions);
  74. },
  75. it() {
  76. return env.it.apply(env, arguments);
  77. },
  78. xit() {
  79. return env.xit.apply(env, arguments);
  80. },
  81. fit() {
  82. return env.fit.apply(env, arguments);
  83. },
  84. beforeEach() {
  85. if (typeof arguments[0] !== 'function') {
  86. throw new Error(
  87. 'Invalid first argument. It must be a callback function.'
  88. );
  89. }
  90. return env.beforeEach.apply(env, arguments);
  91. },
  92. afterEach() {
  93. if (typeof arguments[0] !== 'function') {
  94. throw new Error(
  95. 'Invalid first argument. It must be a callback function.'
  96. );
  97. }
  98. return env.afterEach.apply(env, arguments);
  99. },
  100. beforeAll() {
  101. if (typeof arguments[0] !== 'function') {
  102. throw new Error(
  103. 'Invalid first argument. It must be a callback function.'
  104. );
  105. }
  106. return env.beforeAll.apply(env, arguments);
  107. },
  108. afterAll() {
  109. if (typeof arguments[0] !== 'function') {
  110. throw new Error(
  111. 'Invalid first argument. It must be a callback function.'
  112. );
  113. }
  114. return env.afterAll.apply(env, arguments);
  115. },
  116. pending() {
  117. return env.pending.apply(env, arguments);
  118. },
  119. fail() {
  120. return env.fail.apply(env, arguments);
  121. },
  122. spyOn(obj, methodName, accessType) {
  123. return env.spyOn(obj, methodName, accessType);
  124. },
  125. jsApiReporter: new jasmine.JsApiReporter({
  126. timer: new jasmine.Timer()
  127. }),
  128. jasmine
  129. };
  130. return jasmineInterface;
  131. };
  132. exports._interface = _interface;