jasmine_light.js 4.9 KB

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