source: trip-planner-front/node_modules/zone.js/bundles/jasmine-patch.umd.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 16.4 KB
Line 
1'use strict';
2/**
3 * @license Angular v12.0.0-next.0
4 * (c) 2010-2020 Google LLC. https://angular.io/
5 * License: MIT
6 */
7(function (factory) {
8 typeof define === 'function' && define.amd ? define(factory) :
9 factory();
10}((function () {
11 'use strict';
12 /**
13 * @license
14 * Copyright Google LLC All Rights Reserved.
15 *
16 * Use of this source code is governed by an MIT-style license that can be
17 * found in the LICENSE file at https://angular.io/license
18 */
19 Zone.__load_patch('jasmine', function (global, Zone, api) {
20 var __extends = function (d, b) {
21 for (var p in b)
22 if (b.hasOwnProperty(p))
23 d[p] = b[p];
24 function __() {
25 this.constructor = d;
26 }
27 d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
28 };
29 // Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
30 // in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503)
31 if (!Zone)
32 throw new Error('Missing: zone.js');
33 if (typeof jest !== 'undefined') {
34 // return if jasmine is a light implementation inside jest
35 // in this case, we are running inside jest not jasmine
36 return;
37 }
38 if (typeof jasmine == 'undefined' || jasmine['__zone_patch__']) {
39 return;
40 }
41 jasmine['__zone_patch__'] = true;
42 var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
43 var ProxyZoneSpec = Zone['ProxyZoneSpec'];
44 if (!SyncTestZoneSpec)
45 throw new Error('Missing: SyncTestZoneSpec');
46 if (!ProxyZoneSpec)
47 throw new Error('Missing: ProxyZoneSpec');
48 var ambientZone = Zone.current;
49 // Create a synchronous-only zone in which to run `describe` blocks in order to raise an
50 // error if any asynchronous operations are attempted inside of a `describe` but outside of
51 // a `beforeEach` or `it`.
52 var syncZone = ambientZone.fork(new SyncTestZoneSpec('jasmine.describe'));
53 var symbol = Zone.__symbol__;
54 // whether patch jasmine clock when in fakeAsync
55 var disablePatchingJasmineClock = global[symbol('fakeAsyncDisablePatchingClock')] === true;
56 // the original variable name fakeAsyncPatchLock is not accurate, so the name will be
57 // fakeAsyncAutoFakeAsyncWhenClockPatched and if this enablePatchingJasmineClock is false, we also
58 // automatically disable the auto jump into fakeAsync feature
59 var enableAutoFakeAsyncWhenClockPatched = !disablePatchingJasmineClock &&
60 ((global[symbol('fakeAsyncPatchLock')] === true) ||
61 (global[symbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] === true));
62 var ignoreUnhandledRejection = global[symbol('ignoreUnhandledRejection')] === true;
63 if (!ignoreUnhandledRejection) {
64 var globalErrors_1 = jasmine.GlobalErrors;
65 if (globalErrors_1 && !jasmine[symbol('GlobalErrors')]) {
66 jasmine[symbol('GlobalErrors')] = globalErrors_1;
67 jasmine.GlobalErrors = function () {
68 var instance = new globalErrors_1();
69 var originalInstall = instance.install;
70 if (originalInstall && !instance[symbol('install')]) {
71 instance[symbol('install')] = originalInstall;
72 instance.install = function () {
73 var originalHandlers = process.listeners('unhandledRejection');
74 var r = originalInstall.apply(this, arguments);
75 process.removeAllListeners('unhandledRejection');
76 if (originalHandlers) {
77 originalHandlers.forEach(function (h) { return process.on('unhandledRejection', h); });
78 }
79 return r;
80 };
81 }
82 return instance;
83 };
84 }
85 }
86 // Monkey patch all of the jasmine DSL so that each function runs in appropriate zone.
87 var jasmineEnv = jasmine.getEnv();
88 ['describe', 'xdescribe', 'fdescribe'].forEach(function (methodName) {
89 var originalJasmineFn = jasmineEnv[methodName];
90 jasmineEnv[methodName] = function (description, specDefinitions) {
91 return originalJasmineFn.call(this, description, wrapDescribeInZone(specDefinitions));
92 };
93 });
94 ['it', 'xit', 'fit'].forEach(function (methodName) {
95 var originalJasmineFn = jasmineEnv[methodName];
96 jasmineEnv[symbol(methodName)] = originalJasmineFn;
97 jasmineEnv[methodName] = function (description, specDefinitions, timeout) {
98 arguments[1] = wrapTestInZone(specDefinitions);
99 return originalJasmineFn.apply(this, arguments);
100 };
101 });
102 ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(function (methodName) {
103 var originalJasmineFn = jasmineEnv[methodName];
104 jasmineEnv[symbol(methodName)] = originalJasmineFn;
105 jasmineEnv[methodName] = function (specDefinitions, timeout) {
106 arguments[0] = wrapTestInZone(specDefinitions);
107 return originalJasmineFn.apply(this, arguments);
108 };
109 });
110 if (!disablePatchingJasmineClock) {
111 // need to patch jasmine.clock().mockDate and jasmine.clock().tick() so
112 // they can work properly in FakeAsyncTest
113 var originalClockFn_1 = (jasmine[symbol('clock')] = jasmine['clock']);
114 jasmine['clock'] = function () {
115 var clock = originalClockFn_1.apply(this, arguments);
116 if (!clock[symbol('patched')]) {
117 clock[symbol('patched')] = symbol('patched');
118 var originalTick_1 = (clock[symbol('tick')] = clock.tick);
119 clock.tick = function () {
120 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
121 if (fakeAsyncZoneSpec) {
122 return fakeAsyncZoneSpec.tick.apply(fakeAsyncZoneSpec, arguments);
123 }
124 return originalTick_1.apply(this, arguments);
125 };
126 var originalMockDate_1 = (clock[symbol('mockDate')] = clock.mockDate);
127 clock.mockDate = function () {
128 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
129 if (fakeAsyncZoneSpec) {
130 var dateTime = arguments.length > 0 ? arguments[0] : new Date();
131 return fakeAsyncZoneSpec.setFakeBaseSystemTime.apply(fakeAsyncZoneSpec, dateTime && typeof dateTime.getTime === 'function' ? [dateTime.getTime()] :
132 arguments);
133 }
134 return originalMockDate_1.apply(this, arguments);
135 };
136 // for auto go into fakeAsync feature, we need the flag to enable it
137 if (enableAutoFakeAsyncWhenClockPatched) {
138 ['install', 'uninstall'].forEach(function (methodName) {
139 var originalClockFn = (clock[symbol(methodName)] = clock[methodName]);
140 clock[methodName] = function () {
141 var FakeAsyncTestZoneSpec = Zone['FakeAsyncTestZoneSpec'];
142 if (FakeAsyncTestZoneSpec) {
143 jasmine[symbol('clockInstalled')] = 'install' === methodName;
144 return;
145 }
146 return originalClockFn.apply(this, arguments);
147 };
148 });
149 }
150 }
151 return clock;
152 };
153 }
154 // monkey patch createSpyObj to make properties enumerable to true
155 if (!jasmine[Zone.__symbol__('createSpyObj')]) {
156 var originalCreateSpyObj_1 = jasmine.createSpyObj;
157 jasmine[Zone.__symbol__('createSpyObj')] = originalCreateSpyObj_1;
158 jasmine.createSpyObj = function () {
159 var args = Array.prototype.slice.call(arguments);
160 var propertyNames = args.length >= 3 ? args[2] : null;
161 var spyObj;
162 if (propertyNames) {
163 var defineProperty_1 = Object.defineProperty;
164 Object.defineProperty = function (obj, p, attributes) {
165 return defineProperty_1.call(this, obj, p, Object.assign(Object.assign({}, attributes), { configurable: true, enumerable: true }));
166 };
167 try {
168 spyObj = originalCreateSpyObj_1.apply(this, args);
169 }
170 finally {
171 Object.defineProperty = defineProperty_1;
172 }
173 }
174 else {
175 spyObj = originalCreateSpyObj_1.apply(this, args);
176 }
177 return spyObj;
178 };
179 }
180 /**
181 * Gets a function wrapping the body of a Jasmine `describe` block to execute in a
182 * synchronous-only zone.
183 */
184 function wrapDescribeInZone(describeBody) {
185 return function () {
186 return syncZone.run(describeBody, this, arguments);
187 };
188 }
189 function runInTestZone(testBody, applyThis, queueRunner, done) {
190 var isClockInstalled = !!jasmine[symbol('clockInstalled')];
191 var testProxyZoneSpec = queueRunner.testProxyZoneSpec;
192 var testProxyZone = queueRunner.testProxyZone;
193 if (isClockInstalled && enableAutoFakeAsyncWhenClockPatched) {
194 // auto run a fakeAsync
195 var fakeAsyncModule = Zone[Zone.__symbol__('fakeAsyncTest')];
196 if (fakeAsyncModule && typeof fakeAsyncModule.fakeAsync === 'function') {
197 testBody = fakeAsyncModule.fakeAsync(testBody);
198 }
199 }
200 if (done) {
201 return testProxyZone.run(testBody, applyThis, [done]);
202 }
203 else {
204 return testProxyZone.run(testBody, applyThis);
205 }
206 }
207 /**
208 * Gets a function wrapping the body of a Jasmine `it/beforeEach/afterEach` block to
209 * execute in a ProxyZone zone.
210 * This will run in `testProxyZone`. The `testProxyZone` will be reset by the `ZoneQueueRunner`
211 */
212 function wrapTestInZone(testBody) {
213 // The `done` callback is only passed through if the function expects at least one argument.
214 // Note we have to make a function with correct number of arguments, otherwise jasmine will
215 // think that all functions are sync or async.
216 return (testBody && (testBody.length ? function (done) {
217 return runInTestZone(testBody, this, this.queueRunner, done);
218 } : function () {
219 return runInTestZone(testBody, this, this.queueRunner);
220 }));
221 }
222 var QueueRunner = jasmine.QueueRunner;
223 jasmine.QueueRunner = (function (_super) {
224 __extends(ZoneQueueRunner, _super);
225 function ZoneQueueRunner(attrs) {
226 var _this = this;
227 if (attrs.onComplete) {
228 attrs.onComplete = (function (fn) { return function () {
229 // All functions are done, clear the test zone.
230 _this.testProxyZone = null;
231 _this.testProxyZoneSpec = null;
232 ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
233 }; })(attrs.onComplete);
234 }
235 var nativeSetTimeout = global[Zone.__symbol__('setTimeout')];
236 var nativeClearTimeout = global[Zone.__symbol__('clearTimeout')];
237 if (nativeSetTimeout) {
238 // should run setTimeout inside jasmine outside of zone
239 attrs.timeout = {
240 setTimeout: nativeSetTimeout ? nativeSetTimeout : global.setTimeout,
241 clearTimeout: nativeClearTimeout ? nativeClearTimeout : global.clearTimeout
242 };
243 }
244 // create a userContext to hold the queueRunner itself
245 // so we can access the testProxy in it/xit/beforeEach ...
246 if (jasmine.UserContext) {
247 if (!attrs.userContext) {
248 attrs.userContext = new jasmine.UserContext();
249 }
250 attrs.userContext.queueRunner = this;
251 }
252 else {
253 if (!attrs.userContext) {
254 attrs.userContext = {};
255 }
256 attrs.userContext.queueRunner = this;
257 }
258 // patch attrs.onException
259 var onException = attrs.onException;
260 attrs.onException = function (error) {
261 if (error &&
262 error.message ===
263 'Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.') {
264 // jasmine timeout, we can make the error message more
265 // reasonable to tell what tasks are pending
266 var proxyZoneSpec = this && this.testProxyZoneSpec;
267 if (proxyZoneSpec) {
268 var pendingTasksInfo = proxyZoneSpec.getAndClearPendingTasksInfo();
269 try {
270 // try catch here in case error.message is not writable
271 error.message += pendingTasksInfo;
272 }
273 catch (err) {
274 }
275 }
276 }
277 if (onException) {
278 onException.call(this, error);
279 }
280 };
281 _super.call(this, attrs);
282 }
283 ZoneQueueRunner.prototype.execute = function () {
284 var _this = this;
285 var zone = Zone.current;
286 var isChildOfAmbientZone = false;
287 while (zone) {
288 if (zone === ambientZone) {
289 isChildOfAmbientZone = true;
290 break;
291 }
292 zone = zone.parent;
293 }
294 if (!isChildOfAmbientZone)
295 throw new Error('Unexpected Zone: ' + Zone.current.name);
296 // This is the zone which will be used for running individual tests.
297 // It will be a proxy zone, so that the tests function can retroactively install
298 // different zones.
299 // Example:
300 // - In beforeEach() do childZone = Zone.current.fork(...);
301 // - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the
302 // zone outside of fakeAsync it will be able to escape the fakeAsync rules.
303 // - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add
304 // fakeAsync behavior to the childZone.
305 this.testProxyZoneSpec = new ProxyZoneSpec();
306 this.testProxyZone = ambientZone.fork(this.testProxyZoneSpec);
307 if (!Zone.currentTask) {
308 // if we are not running in a task then if someone would register a
309 // element.addEventListener and then calling element.click() the
310 // addEventListener callback would think that it is the top most task and would
311 // drain the microtask queue on element.click() which would be incorrect.
312 // For this reason we always force a task when running jasmine tests.
313 Zone.current.scheduleMicroTask('jasmine.execute().forceTask', function () { return QueueRunner.prototype.execute.call(_this); });
314 }
315 else {
316 _super.prototype.execute.call(this);
317 }
318 };
319 return ZoneQueueRunner;
320 })(QueueRunner);
321 });
322})));
Note: See TracBrowser for help on using the repository browser.