UNPKG

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