jasmineLight.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. 'use strict';
  2. var _createSpy = _interopRequireDefault(require('./createSpy'));
  3. var _Env = _interopRequireDefault(require('./Env'));
  4. var _JsApiReporter = _interopRequireDefault(require('./JsApiReporter'));
  5. var _ReportDispatcher = _interopRequireDefault(require('./ReportDispatcher'));
  6. var _Spec = _interopRequireDefault(require('./Spec'));
  7. var _spyRegistry = _interopRequireDefault(require('./spyRegistry'));
  8. var _Suite = _interopRequireDefault(require('./Suite'));
  9. var _Timer = _interopRequireDefault(require('./Timer'));
  10. function _interopRequireDefault(obj) {
  11. return obj && obj.__esModule ? obj : {default: obj};
  12. }
  13. function _objectSpread(target) {
  14. for (var i = 1; i < arguments.length; i++) {
  15. var source = arguments[i] != null ? arguments[i] : {};
  16. var ownKeys = Object.keys(source);
  17. if (typeof Object.getOwnPropertySymbols === 'function') {
  18. ownKeys = ownKeys.concat(
  19. Object.getOwnPropertySymbols(source).filter(function(sym) {
  20. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  21. })
  22. );
  23. }
  24. ownKeys.forEach(function(key) {
  25. _defineProperty(target, key, source[key]);
  26. });
  27. }
  28. return target;
  29. }
  30. function _defineProperty(obj, key, value) {
  31. if (key in obj) {
  32. Object.defineProperty(obj, key, {
  33. value: value,
  34. enumerable: true,
  35. configurable: true,
  36. writable: true
  37. });
  38. } else {
  39. obj[key] = value;
  40. }
  41. return obj;
  42. }
  43. const create = function create(createOptions) {
  44. const j$ = _objectSpread({}, createOptions);
  45. j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000;
  46. j$.getEnv = function(options) {
  47. const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options)); //jasmine. singletons in here (setTimeout blah blah).
  48. return env;
  49. };
  50. j$.createSpy = _createSpy.default;
  51. j$.Env = (0, _Env.default)(j$);
  52. j$.JsApiReporter = _JsApiReporter.default;
  53. j$.ReportDispatcher = _ReportDispatcher.default;
  54. j$.Spec = _Spec.default;
  55. j$.SpyRegistry = _spyRegistry.default;
  56. j$.Suite = _Suite.default;
  57. j$.Timer = _Timer.default;
  58. j$.version = '2.5.2-light';
  59. return j$;
  60. };
  61. const _interface = function _interface(jasmine, env) {
  62. const jasmineInterface = {
  63. describe(description, specDefinitions) {
  64. return env.describe(description, specDefinitions);
  65. },
  66. xdescribe(description, specDefinitions) {
  67. return env.xdescribe(description, specDefinitions);
  68. },
  69. fdescribe(description, specDefinitions) {
  70. return env.fdescribe(description, specDefinitions);
  71. },
  72. it() {
  73. return env.it.apply(env, arguments);
  74. },
  75. xit() {
  76. return env.xit.apply(env, arguments);
  77. },
  78. fit() {
  79. return env.fit.apply(env, arguments);
  80. },
  81. beforeEach() {
  82. if (typeof arguments[0] !== 'function') {
  83. throw new Error(
  84. 'Invalid first argument. It must be a callback function.'
  85. );
  86. }
  87. return env.beforeEach.apply(env, arguments);
  88. },
  89. afterEach() {
  90. if (typeof arguments[0] !== 'function') {
  91. throw new Error(
  92. 'Invalid first argument. It must be a callback function.'
  93. );
  94. }
  95. return env.afterEach.apply(env, arguments);
  96. },
  97. beforeAll() {
  98. if (typeof arguments[0] !== 'function') {
  99. throw new Error(
  100. 'Invalid first argument. It must be a callback function.'
  101. );
  102. }
  103. return env.beforeAll.apply(env, arguments);
  104. },
  105. afterAll() {
  106. if (typeof arguments[0] !== 'function') {
  107. throw new Error(
  108. 'Invalid first argument. It must be a callback function.'
  109. );
  110. }
  111. return env.afterAll.apply(env, arguments);
  112. },
  113. pending() {
  114. return env.pending.apply(env, arguments);
  115. },
  116. fail() {
  117. return env.fail.apply(env, arguments);
  118. },
  119. spyOn(obj, methodName, accessType) {
  120. return env.spyOn(obj, methodName, accessType);
  121. },
  122. jsApiReporter: new jasmine.JsApiReporter({
  123. timer: new jasmine.Timer()
  124. }),
  125. jasmine
  126. };
  127. return jasmineInterface;
  128. }; // Interface is a reserved word in strict mode, so can't export it as ESM
  129. module.exports = {
  130. create,
  131. interface: _interface
  132. };