1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import * as i0 from '@angular/core';
|
8 | import { getDebugNode, RendererFactory2, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, InjectionToken, Injector, InjectFlags, ɵresetCompiledComponents, ɵflushModuleScopingQueueAsMuchAsPossible, Injectable, ɵclearOverrides, ɵoverrideComponentView, ɵINJECTOR_SCOPE, Optional, SkipSelf, ɵoverrideProvider, ɵivyEnabled } from '@angular/core';
|
9 | import { __awaiter, __decorate } from 'tslib';
|
10 | import { ResourceLoader } from '@angular/compiler';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function waitForAsync(fn) {
|
37 | const _Zone = typeof Zone !== 'undefined' ? Zone : null;
|
38 | if (!_Zone) {
|
39 | return function () {
|
40 | return Promise.reject('Zone is needed for the waitForAsync() test helper but could not be found. ' +
|
41 | 'Please make sure that your environment includes zone.js');
|
42 | };
|
43 | }
|
44 | const asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')];
|
45 | if (typeof asyncTest === 'function') {
|
46 | return asyncTest(fn);
|
47 | }
|
48 | return function () {
|
49 | return Promise.reject('zone-testing.js is needed for the async() test helper but could not be found. ' +
|
50 | 'Please make sure that your environment includes zone.js/testing');
|
51 | };
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | function async(fn) {
|
59 | return waitForAsync(fn);
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | class ComponentFixture {
|
75 | constructor(componentRef, ngZone, _autoDetect) {
|
76 | this.componentRef = componentRef;
|
77 | this.ngZone = ngZone;
|
78 | this._autoDetect = _autoDetect;
|
79 | this._isStable = true;
|
80 | this._isDestroyed = false;
|
81 | this._resolve = null;
|
82 | this._promise = null;
|
83 | this._onUnstableSubscription = null;
|
84 | this._onStableSubscription = null;
|
85 | this._onMicrotaskEmptySubscription = null;
|
86 | this._onErrorSubscription = null;
|
87 | this.changeDetectorRef = componentRef.changeDetectorRef;
|
88 | this.elementRef = componentRef.location;
|
89 | this.debugElement = getDebugNode(this.elementRef.nativeElement);
|
90 | this.componentInstance = componentRef.instance;
|
91 | this.nativeElement = this.elementRef.nativeElement;
|
92 | this.componentRef = componentRef;
|
93 | this.ngZone = ngZone;
|
94 | if (ngZone) {
|
95 |
|
96 |
|
97 | ngZone.runOutsideAngular(() => {
|
98 | this._onUnstableSubscription = ngZone.onUnstable.subscribe({
|
99 | next: () => {
|
100 | this._isStable = false;
|
101 | }
|
102 | });
|
103 | this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
104 | next: () => {
|
105 | if (this._autoDetect) {
|
106 |
|
107 |
|
108 | this.detectChanges(true);
|
109 | }
|
110 | }
|
111 | });
|
112 | this._onStableSubscription = ngZone.onStable.subscribe({
|
113 | next: () => {
|
114 | this._isStable = true;
|
115 |
|
116 | if (this._promise !== null) {
|
117 |
|
118 |
|
119 |
|
120 | scheduleMicroTask(() => {
|
121 | if (!ngZone.hasPendingMacrotasks) {
|
122 | if (this._promise !== null) {
|
123 | this._resolve(true);
|
124 | this._resolve = null;
|
125 | this._promise = null;
|
126 | }
|
127 | }
|
128 | });
|
129 | }
|
130 | }
|
131 | });
|
132 | this._onErrorSubscription = ngZone.onError.subscribe({
|
133 | next: (error) => {
|
134 | throw error;
|
135 | }
|
136 | });
|
137 | });
|
138 | }
|
139 | }
|
140 | _tick(checkNoChanges) {
|
141 | this.changeDetectorRef.detectChanges();
|
142 | if (checkNoChanges) {
|
143 | this.checkNoChanges();
|
144 | }
|
145 | }
|
146 | |
147 |
|
148 |
|
149 | detectChanges(checkNoChanges = true) {
|
150 | if (this.ngZone != null) {
|
151 |
|
152 |
|
153 | this.ngZone.run(() => {
|
154 | this._tick(checkNoChanges);
|
155 | });
|
156 | }
|
157 | else {
|
158 |
|
159 | this._tick(checkNoChanges);
|
160 | }
|
161 | }
|
162 | |
163 |
|
164 |
|
165 | checkNoChanges() {
|
166 | this.changeDetectorRef.checkNoChanges();
|
167 | }
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 | autoDetectChanges(autoDetect = true) {
|
174 | if (this.ngZone == null) {
|
175 | throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
|
176 | }
|
177 | this._autoDetect = autoDetect;
|
178 | this.detectChanges();
|
179 | }
|
180 | |
181 |
|
182 |
|
183 |
|
184 | isStable() {
|
185 | return this._isStable && !this.ngZone.hasPendingMacrotasks;
|
186 | }
|
187 | |
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | whenStable() {
|
194 | if (this.isStable()) {
|
195 | return Promise.resolve(false);
|
196 | }
|
197 | else if (this._promise !== null) {
|
198 | return this._promise;
|
199 | }
|
200 | else {
|
201 | this._promise = new Promise(res => {
|
202 | this._resolve = res;
|
203 | });
|
204 | return this._promise;
|
205 | }
|
206 | }
|
207 | _getRenderer() {
|
208 | if (this._renderer === undefined) {
|
209 | this._renderer = this.componentRef.injector.get(RendererFactory2, null);
|
210 | }
|
211 | return this._renderer;
|
212 | }
|
213 | |
214 |
|
215 |
|
216 | whenRenderingDone() {
|
217 | const renderer = this._getRenderer();
|
218 | if (renderer && renderer.whenRenderingDone) {
|
219 | return renderer.whenRenderingDone();
|
220 | }
|
221 | return this.whenStable();
|
222 | }
|
223 | |
224 |
|
225 |
|
226 | destroy() {
|
227 | if (!this._isDestroyed) {
|
228 | this.componentRef.destroy();
|
229 | if (this._onUnstableSubscription != null) {
|
230 | this._onUnstableSubscription.unsubscribe();
|
231 | this._onUnstableSubscription = null;
|
232 | }
|
233 | if (this._onStableSubscription != null) {
|
234 | this._onStableSubscription.unsubscribe();
|
235 | this._onStableSubscription = null;
|
236 | }
|
237 | if (this._onMicrotaskEmptySubscription != null) {
|
238 | this._onMicrotaskEmptySubscription.unsubscribe();
|
239 | this._onMicrotaskEmptySubscription = null;
|
240 | }
|
241 | if (this._onErrorSubscription != null) {
|
242 | this._onErrorSubscription.unsubscribe();
|
243 | this._onErrorSubscription = null;
|
244 | }
|
245 | this._isDestroyed = true;
|
246 | }
|
247 | }
|
248 | }
|
249 | function scheduleMicroTask(fn) {
|
250 | Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | const _Zone = typeof Zone !== 'undefined' ? Zone : null;
|
261 | const fakeAsyncTestModule = _Zone && _Zone[_Zone.__symbol__('fakeAsyncTest')];
|
262 | const fakeAsyncTestModuleNotLoadedErrorMessage = `zone-testing.js is needed for the fakeAsync() test helper but could not be found.
|
263 | Please make sure that your environment includes zone.js/testing`;
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | function resetFakeAsyncZone() {
|
271 | if (fakeAsyncTestModule) {
|
272 | return fakeAsyncTestModule.resetFakeAsyncZone();
|
273 | }
|
274 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
275 | }
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | function fakeAsync(fn) {
|
300 | if (fakeAsyncTestModule) {
|
301 | return fakeAsyncTestModule.fakeAsync(fn);
|
302 | }
|
303 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
304 | }
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | function tick(millis = 0, tickOptions = {
|
370 | processNewMacroTasksSynchronously: true
|
371 | }) {
|
372 | if (fakeAsyncTestModule) {
|
373 | return fakeAsyncTestModule.tick(millis, tickOptions);
|
374 | }
|
375 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
376 | }
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 | function flush(maxTurns) {
|
388 | if (fakeAsyncTestModule) {
|
389 | return fakeAsyncTestModule.flush(maxTurns);
|
390 | }
|
391 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
392 | }
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | function discardPeriodicTasks() {
|
399 | if (fakeAsyncTestModule) {
|
400 | return fakeAsyncTestModule.discardPeriodicTasks();
|
401 | }
|
402 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
403 | }
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 | function flushMicrotasks() {
|
410 | if (fakeAsyncTestModule) {
|
411 | return fakeAsyncTestModule.flushMicrotasks();
|
412 | }
|
413 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
414 | }
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | function resolveComponentResources(resourceResolver) {
|
456 |
|
457 | const componentResolved = [];
|
458 |
|
459 | const urlMap = new Map();
|
460 | function cachedResourceResolve(url) {
|
461 | let promise = urlMap.get(url);
|
462 | if (!promise) {
|
463 | const resp = resourceResolver(url);
|
464 | urlMap.set(url, promise = resp.then(unwrapResponse));
|
465 | }
|
466 | return promise;
|
467 | }
|
468 | componentResourceResolutionQueue.forEach((component, type) => {
|
469 | const promises = [];
|
470 | if (component.templateUrl) {
|
471 | promises.push(cachedResourceResolve(component.templateUrl).then((template) => {
|
472 | component.template = template;
|
473 | }));
|
474 | }
|
475 | const styleUrls = component.styleUrls;
|
476 | const styles = component.styles || (component.styles = []);
|
477 | const styleOffset = component.styles.length;
|
478 | styleUrls && styleUrls.forEach((styleUrl, index) => {
|
479 | styles.push('');
|
480 | promises.push(cachedResourceResolve(styleUrl).then((style) => {
|
481 | styles[styleOffset + index] = style;
|
482 | styleUrls.splice(styleUrls.indexOf(styleUrl), 1);
|
483 | if (styleUrls.length == 0) {
|
484 | component.styleUrls = undefined;
|
485 | }
|
486 | }));
|
487 | });
|
488 | const fullyResolved = Promise.all(promises).then(() => componentDefResolved(type));
|
489 | componentResolved.push(fullyResolved);
|
490 | });
|
491 | clearResolutionOfComponentResourcesQueue();
|
492 | return Promise.all(componentResolved).then(() => undefined);
|
493 | }
|
494 | let componentResourceResolutionQueue = new Map();
|
495 |
|
496 | const componentDefPendingResolution = new Set();
|
497 | function maybeQueueResolutionOfComponentResources(type, metadata) {
|
498 | if (componentNeedsResolution(metadata)) {
|
499 | componentResourceResolutionQueue.set(type, metadata);
|
500 | componentDefPendingResolution.add(type);
|
501 | }
|
502 | }
|
503 | function isComponentDefPendingResolution(type) {
|
504 | return componentDefPendingResolution.has(type);
|
505 | }
|
506 | function componentNeedsResolution(component) {
|
507 | return !!((component.templateUrl && !component.hasOwnProperty('template')) ||
|
508 | component.styleUrls && component.styleUrls.length);
|
509 | }
|
510 | function clearResolutionOfComponentResourcesQueue() {
|
511 | const old = componentResourceResolutionQueue;
|
512 | componentResourceResolutionQueue = new Map();
|
513 | return old;
|
514 | }
|
515 | function restoreComponentResolutionQueue(queue) {
|
516 | componentDefPendingResolution.clear();
|
517 | queue.forEach((_, type) => componentDefPendingResolution.add(type));
|
518 | componentResourceResolutionQueue = queue;
|
519 | }
|
520 | function isComponentResourceResolutionQueueEmpty() {
|
521 | return componentResourceResolutionQueue.size === 0;
|
522 | }
|
523 | function unwrapResponse(response) {
|
524 | return typeof response == 'string' ? response : response.text();
|
525 | }
|
526 | function componentDefResolved(type) {
|
527 | componentDefPendingResolution.delete(type);
|
528 | }
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 | let _nextReferenceId = 0;
|
538 | class MetadataOverrider {
|
539 | constructor() {
|
540 | this._references = new Map();
|
541 | }
|
542 | |
543 |
|
544 |
|
545 |
|
546 | overrideMetadata(metadataClass, oldMetadata, override) {
|
547 | const props = {};
|
548 | if (oldMetadata) {
|
549 | _valueProps(oldMetadata).forEach((prop) => props[prop] = oldMetadata[prop]);
|
550 | }
|
551 | if (override.set) {
|
552 | if (override.remove || override.add) {
|
553 | throw new Error(`Cannot set and add/remove ${ɵstringify(metadataClass)} at the same time!`);
|
554 | }
|
555 | setMetadata(props, override.set);
|
556 | }
|
557 | if (override.remove) {
|
558 | removeMetadata(props, override.remove, this._references);
|
559 | }
|
560 | if (override.add) {
|
561 | addMetadata(props, override.add);
|
562 | }
|
563 | return new metadataClass(props);
|
564 | }
|
565 | }
|
566 | function removeMetadata(metadata, remove, references) {
|
567 | const removeObjects = new Set();
|
568 | for (const prop in remove) {
|
569 | const removeValue = remove[prop];
|
570 | if (Array.isArray(removeValue)) {
|
571 | removeValue.forEach((value) => {
|
572 | removeObjects.add(_propHashKey(prop, value, references));
|
573 | });
|
574 | }
|
575 | else {
|
576 | removeObjects.add(_propHashKey(prop, removeValue, references));
|
577 | }
|
578 | }
|
579 | for (const prop in metadata) {
|
580 | const propValue = metadata[prop];
|
581 | if (Array.isArray(propValue)) {
|
582 | metadata[prop] = propValue.filter((value) => !removeObjects.has(_propHashKey(prop, value, references)));
|
583 | }
|
584 | else {
|
585 | if (removeObjects.has(_propHashKey(prop, propValue, references))) {
|
586 | metadata[prop] = undefined;
|
587 | }
|
588 | }
|
589 | }
|
590 | }
|
591 | function addMetadata(metadata, add) {
|
592 | for (const prop in add) {
|
593 | const addValue = add[prop];
|
594 | const propValue = metadata[prop];
|
595 | if (propValue != null && Array.isArray(propValue)) {
|
596 | metadata[prop] = propValue.concat(addValue);
|
597 | }
|
598 | else {
|
599 | metadata[prop] = addValue;
|
600 | }
|
601 | }
|
602 | }
|
603 | function setMetadata(metadata, set) {
|
604 | for (const prop in set) {
|
605 | metadata[prop] = set[prop];
|
606 | }
|
607 | }
|
608 | function _propHashKey(propName, propValue, references) {
|
609 | const replacer = (key, value) => {
|
610 | if (typeof value === 'function') {
|
611 | value = _serializeReference(value, references);
|
612 | }
|
613 | return value;
|
614 | };
|
615 | return `${propName}:${JSON.stringify(propValue, replacer)}`;
|
616 | }
|
617 | function _serializeReference(ref, references) {
|
618 | let id = references.get(ref);
|
619 | if (!id) {
|
620 | id = `${ɵstringify(ref)}${_nextReferenceId++}`;
|
621 | references.set(ref, id);
|
622 | }
|
623 | return id;
|
624 | }
|
625 | function _valueProps(obj) {
|
626 | const props = [];
|
627 |
|
628 | Object.keys(obj).forEach((prop) => {
|
629 | if (!prop.startsWith('_')) {
|
630 | props.push(prop);
|
631 | }
|
632 | });
|
633 |
|
634 | let proto = obj;
|
635 | while (proto = Object.getPrototypeOf(proto)) {
|
636 | Object.keys(proto).forEach((protoProp) => {
|
637 | const desc = Object.getOwnPropertyDescriptor(proto, protoProp);
|
638 | if (!protoProp.startsWith('_') && desc && 'get' in desc) {
|
639 | props.push(protoProp);
|
640 | }
|
641 | });
|
642 | }
|
643 | return props;
|
644 | }
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 | const reflection = new ɵReflectionCapabilities();
|
654 |
|
655 |
|
656 |
|
657 | class OverrideResolver {
|
658 | constructor() {
|
659 | this.overrides = new Map();
|
660 | this.resolved = new Map();
|
661 | }
|
662 | addOverride(type, override) {
|
663 | const overrides = this.overrides.get(type) || [];
|
664 | overrides.push(override);
|
665 | this.overrides.set(type, overrides);
|
666 | this.resolved.delete(type);
|
667 | }
|
668 | setOverrides(overrides) {
|
669 | this.overrides.clear();
|
670 | overrides.forEach(([type, override]) => {
|
671 | this.addOverride(type, override);
|
672 | });
|
673 | }
|
674 | getAnnotation(type) {
|
675 | const annotations = reflection.annotations(type);
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 | for (let i = annotations.length - 1; i >= 0; i--) {
|
682 | const annotation = annotations[i];
|
683 | const isKnownType = annotation instanceof Directive || annotation instanceof Component ||
|
684 | annotation instanceof Pipe || annotation instanceof NgModule;
|
685 | if (isKnownType) {
|
686 | return annotation instanceof this.type ? annotation : null;
|
687 | }
|
688 | }
|
689 | return null;
|
690 | }
|
691 | resolve(type) {
|
692 | let resolved = this.resolved.get(type) || null;
|
693 | if (!resolved) {
|
694 | resolved = this.getAnnotation(type);
|
695 | if (resolved) {
|
696 | const overrides = this.overrides.get(type);
|
697 | if (overrides) {
|
698 | const overrider = new MetadataOverrider();
|
699 | overrides.forEach(override => {
|
700 | resolved = overrider.overrideMetadata(this.type, resolved, override);
|
701 | });
|
702 | }
|
703 | }
|
704 | this.resolved.set(type, resolved);
|
705 | }
|
706 | return resolved;
|
707 | }
|
708 | }
|
709 | class DirectiveResolver extends OverrideResolver {
|
710 | get type() {
|
711 | return Directive;
|
712 | }
|
713 | }
|
714 | class ComponentResolver extends OverrideResolver {
|
715 | get type() {
|
716 | return Component;
|
717 | }
|
718 | }
|
719 | class PipeResolver extends OverrideResolver {
|
720 | get type() {
|
721 | return Pipe;
|
722 | }
|
723 | }
|
724 | class NgModuleResolver extends OverrideResolver {
|
725 | get type() {
|
726 | return NgModule;
|
727 | }
|
728 | }
|
729 |
|
730 | var TestingModuleOverride;
|
731 | (function (TestingModuleOverride) {
|
732 | TestingModuleOverride[TestingModuleOverride["DECLARATION"] = 0] = "DECLARATION";
|
733 | TestingModuleOverride[TestingModuleOverride["OVERRIDE_TEMPLATE"] = 1] = "OVERRIDE_TEMPLATE";
|
734 | })(TestingModuleOverride || (TestingModuleOverride = {}));
|
735 | function isTestingModuleOverride(value) {
|
736 | return value === TestingModuleOverride.DECLARATION ||
|
737 | value === TestingModuleOverride.OVERRIDE_TEMPLATE;
|
738 | }
|
739 | class R3TestBedCompiler {
|
740 | constructor(platform, additionalModuleTypes) {
|
741 | this.platform = platform;
|
742 | this.additionalModuleTypes = additionalModuleTypes;
|
743 | this.originalComponentResolutionQueue = null;
|
744 |
|
745 | this.declarations = [];
|
746 | this.imports = [];
|
747 | this.providers = [];
|
748 | this.schemas = [];
|
749 |
|
750 | this.pendingComponents = new Set();
|
751 | this.pendingDirectives = new Set();
|
752 | this.pendingPipes = new Set();
|
753 |
|
754 | this.seenComponents = new Set();
|
755 | this.seenDirectives = new Set();
|
756 |
|
757 | this.overriddenModules = new Set();
|
758 |
|
759 |
|
760 | this.existingComponentStyles = new Map();
|
761 | this.resolvers = initResolvers();
|
762 | this.componentToModuleScope = new Map();
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | this.initialNgDefs = new Map();
|
768 |
|
769 |
|
770 | this.defCleanupOps = [];
|
771 | this._injector = null;
|
772 | this.compilerProviders = null;
|
773 | this.providerOverrides = [];
|
774 | this.rootProviderOverrides = [];
|
775 |
|
776 |
|
777 | this.providerOverridesByModule = new Map();
|
778 | this.providerOverridesByToken = new Map();
|
779 | this.moduleProvidersOverridden = new Set();
|
780 | this.testModuleRef = null;
|
781 | class DynamicTestModule {
|
782 | }
|
783 | this.testModuleType = DynamicTestModule;
|
784 | }
|
785 | setCompilerProviders(providers) {
|
786 | this.compilerProviders = providers;
|
787 | this._injector = null;
|
788 | }
|
789 | configureTestingModule(moduleDef) {
|
790 |
|
791 | if (moduleDef.declarations !== undefined) {
|
792 | this.queueTypeArray(moduleDef.declarations, TestingModuleOverride.DECLARATION);
|
793 | this.declarations.push(...moduleDef.declarations);
|
794 | }
|
795 |
|
796 | if (moduleDef.imports !== undefined) {
|
797 | this.queueTypesFromModulesArray(moduleDef.imports);
|
798 | this.imports.push(...moduleDef.imports);
|
799 | }
|
800 | if (moduleDef.providers !== undefined) {
|
801 | this.providers.push(...moduleDef.providers);
|
802 | }
|
803 | if (moduleDef.schemas !== undefined) {
|
804 | this.schemas.push(...moduleDef.schemas);
|
805 | }
|
806 | }
|
807 | overrideModule(ngModule, override) {
|
808 | this.overriddenModules.add(ngModule);
|
809 |
|
810 | this.resolvers.module.addOverride(ngModule, override);
|
811 | const metadata = this.resolvers.module.resolve(ngModule);
|
812 | if (metadata === null) {
|
813 | throw invalidTypeError(ngModule.name, 'NgModule');
|
814 | }
|
815 | this.recompileNgModule(ngModule, metadata);
|
816 |
|
817 |
|
818 |
|
819 | this.queueTypesFromModulesArray([ngModule]);
|
820 | }
|
821 | overrideComponent(component, override) {
|
822 | this.resolvers.component.addOverride(component, override);
|
823 | this.pendingComponents.add(component);
|
824 | }
|
825 | overrideDirective(directive, override) {
|
826 | this.resolvers.directive.addOverride(directive, override);
|
827 | this.pendingDirectives.add(directive);
|
828 | }
|
829 | overridePipe(pipe, override) {
|
830 | this.resolvers.pipe.addOverride(pipe, override);
|
831 | this.pendingPipes.add(pipe);
|
832 | }
|
833 | overrideProvider(token, provider) {
|
834 | let providerDef;
|
835 | if (provider.useFactory !== undefined) {
|
836 | providerDef = {
|
837 | provide: token,
|
838 | useFactory: provider.useFactory,
|
839 | deps: provider.deps || [],
|
840 | multi: provider.multi
|
841 | };
|
842 | }
|
843 | else if (provider.useValue !== undefined) {
|
844 | providerDef = { provide: token, useValue: provider.useValue, multi: provider.multi };
|
845 | }
|
846 | else {
|
847 | providerDef = { provide: token };
|
848 | }
|
849 | const injectableDef = typeof token !== 'string' ? ɵgetInjectableDef(token) : null;
|
850 | const providedIn = injectableDef === null ? null : resolveForwardRef(injectableDef.providedIn);
|
851 | const overridesBucket = providedIn === 'root' ? this.rootProviderOverrides : this.providerOverrides;
|
852 | overridesBucket.push(providerDef);
|
853 |
|
854 | this.providerOverridesByToken.set(token, providerDef);
|
855 | if (injectableDef !== null && providedIn !== null && typeof providedIn !== 'string') {
|
856 | const existingOverrides = this.providerOverridesByModule.get(providedIn);
|
857 | if (existingOverrides !== undefined) {
|
858 | existingOverrides.push(providerDef);
|
859 | }
|
860 | else {
|
861 | this.providerOverridesByModule.set(providedIn, [providerDef]);
|
862 | }
|
863 | }
|
864 | }
|
865 | overrideTemplateUsingTestingModule(type, template) {
|
866 | const def = type[ɵNG_COMP_DEF];
|
867 | const hasStyleUrls = () => {
|
868 | const metadata = this.resolvers.component.resolve(type);
|
869 | return !!metadata.styleUrls && metadata.styleUrls.length > 0;
|
870 | };
|
871 | const overrideStyleUrls = !!def && !isComponentDefPendingResolution(type) && hasStyleUrls();
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 | const override = overrideStyleUrls ? { template, styles: [], styleUrls: [] } : { template };
|
880 | this.overrideComponent(type, { set: override });
|
881 | if (overrideStyleUrls && def.styles && def.styles.length > 0) {
|
882 | this.existingComponentStyles.set(type, def.styles);
|
883 | }
|
884 |
|
885 | this.componentToModuleScope.set(type, TestingModuleOverride.OVERRIDE_TEMPLATE);
|
886 | }
|
887 | compileComponents() {
|
888 | return __awaiter(this, void 0, void 0, function* () {
|
889 | this.clearComponentResolutionQueue();
|
890 |
|
891 | let needsAsyncResources = this.compileTypesSync();
|
892 |
|
893 | if (needsAsyncResources) {
|
894 | let resourceLoader;
|
895 | let resolver = (url) => {
|
896 | if (!resourceLoader) {
|
897 | resourceLoader = this.injector.get(ResourceLoader);
|
898 | }
|
899 | return Promise.resolve(resourceLoader.get(url));
|
900 | };
|
901 | yield resolveComponentResources(resolver);
|
902 | }
|
903 | });
|
904 | }
|
905 | finalize() {
|
906 |
|
907 | this.compileTypesSync();
|
908 |
|
909 | this.compileTestModule();
|
910 | this.applyTransitiveScopes();
|
911 | this.applyProviderOverrides();
|
912 |
|
913 |
|
914 | this.patchComponentsWithExistingStyles();
|
915 |
|
916 |
|
917 | this.componentToModuleScope.clear();
|
918 | const parentInjector = this.platform.injector;
|
919 | this.testModuleRef = new ɵRender3NgModuleRef(this.testModuleType, parentInjector);
|
920 |
|
921 |
|
922 | this.testModuleRef.injector.get(ApplicationInitStatus).runInitializers();
|
923 |
|
924 |
|
925 |
|
926 | const localeId = this.testModuleRef.injector.get(LOCALE_ID, ɵDEFAULT_LOCALE_ID);
|
927 | ɵsetLocaleId(localeId);
|
928 | return this.testModuleRef;
|
929 | }
|
930 | |
931 |
|
932 |
|
933 | _compileNgModuleSync(moduleType) {
|
934 | this.queueTypesFromModulesArray([moduleType]);
|
935 | this.compileTypesSync();
|
936 | this.applyProviderOverrides();
|
937 | this.applyProviderOverridesToModule(moduleType);
|
938 | this.applyTransitiveScopes();
|
939 | }
|
940 | |
941 |
|
942 |
|
943 | _compileNgModuleAsync(moduleType) {
|
944 | return __awaiter(this, void 0, void 0, function* () {
|
945 | this.queueTypesFromModulesArray([moduleType]);
|
946 | yield this.compileComponents();
|
947 | this.applyProviderOverrides();
|
948 | this.applyProviderOverridesToModule(moduleType);
|
949 | this.applyTransitiveScopes();
|
950 | });
|
951 | }
|
952 | |
953 |
|
954 |
|
955 | _getModuleResolver() {
|
956 | return this.resolvers.module;
|
957 | }
|
958 | |
959 |
|
960 |
|
961 | _getComponentFactories(moduleType) {
|
962 | return maybeUnwrapFn(moduleType.ɵmod.declarations).reduce((factories, declaration) => {
|
963 | const componentDef = declaration.ɵcmp;
|
964 | componentDef && factories.push(new ɵRender3ComponentFactory(componentDef, this.testModuleRef));
|
965 | return factories;
|
966 | }, []);
|
967 | }
|
968 | compileTypesSync() {
|
969 |
|
970 | let needsAsyncResources = false;
|
971 | this.pendingComponents.forEach(declaration => {
|
972 | needsAsyncResources = needsAsyncResources || isComponentDefPendingResolution(declaration);
|
973 | const metadata = this.resolvers.component.resolve(declaration);
|
974 | if (metadata === null) {
|
975 | throw invalidTypeError(declaration.name, 'Component');
|
976 | }
|
977 | this.maybeStoreNgDef(ɵNG_COMP_DEF, declaration);
|
978 | ɵcompileComponent(declaration, metadata);
|
979 | });
|
980 | this.pendingComponents.clear();
|
981 | this.pendingDirectives.forEach(declaration => {
|
982 | const metadata = this.resolvers.directive.resolve(declaration);
|
983 | if (metadata === null) {
|
984 | throw invalidTypeError(declaration.name, 'Directive');
|
985 | }
|
986 | this.maybeStoreNgDef(ɵNG_DIR_DEF, declaration);
|
987 | ɵcompileDirective(declaration, metadata);
|
988 | });
|
989 | this.pendingDirectives.clear();
|
990 | this.pendingPipes.forEach(declaration => {
|
991 | const metadata = this.resolvers.pipe.resolve(declaration);
|
992 | if (metadata === null) {
|
993 | throw invalidTypeError(declaration.name, 'Pipe');
|
994 | }
|
995 | this.maybeStoreNgDef(ɵNG_PIPE_DEF, declaration);
|
996 | ɵcompilePipe(declaration, metadata);
|
997 | });
|
998 | this.pendingPipes.clear();
|
999 | return needsAsyncResources;
|
1000 | }
|
1001 | applyTransitiveScopes() {
|
1002 | if (this.overriddenModules.size > 0) {
|
1003 |
|
1004 |
|
1005 |
|
1006 | const testingModuleDef = this.testModuleType[ɵNG_MOD_DEF];
|
1007 | const affectedModules = this.collectModulesAffectedByOverrides(testingModuleDef.imports);
|
1008 | if (affectedModules.size > 0) {
|
1009 | affectedModules.forEach(moduleType => {
|
1010 | this.storeFieldOfDefOnType(moduleType, ɵNG_MOD_DEF, 'transitiveCompileScopes');
|
1011 | moduleType[ɵNG_MOD_DEF].transitiveCompileScopes = null;
|
1012 | });
|
1013 | }
|
1014 | }
|
1015 | const moduleToScope = new Map();
|
1016 | const getScopeOfModule = (moduleType) => {
|
1017 | if (!moduleToScope.has(moduleType)) {
|
1018 | const isTestingModule = isTestingModuleOverride(moduleType);
|
1019 | const realType = isTestingModule ? this.testModuleType : moduleType;
|
1020 | moduleToScope.set(moduleType, ɵtransitiveScopesFor(realType));
|
1021 | }
|
1022 | return moduleToScope.get(moduleType);
|
1023 | };
|
1024 | this.componentToModuleScope.forEach((moduleType, componentType) => {
|
1025 | const moduleScope = getScopeOfModule(moduleType);
|
1026 | this.storeFieldOfDefOnType(componentType, ɵNG_COMP_DEF, 'directiveDefs');
|
1027 | this.storeFieldOfDefOnType(componentType, ɵNG_COMP_DEF, 'pipeDefs');
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 | this.storeFieldOfDefOnType(componentType, ɵNG_COMP_DEF, 'tView');
|
1033 | ɵpatchComponentDefWithScope(componentType.ɵcmp, moduleScope);
|
1034 | });
|
1035 | this.componentToModuleScope.clear();
|
1036 | }
|
1037 | applyProviderOverrides() {
|
1038 | const maybeApplyOverrides = (field) => (type) => {
|
1039 | const resolver = field === ɵNG_COMP_DEF ? this.resolvers.component : this.resolvers.directive;
|
1040 | const metadata = resolver.resolve(type);
|
1041 | if (this.hasProviderOverrides(metadata.providers)) {
|
1042 | this.patchDefWithProviderOverrides(type, field);
|
1043 | }
|
1044 | };
|
1045 | this.seenComponents.forEach(maybeApplyOverrides(ɵNG_COMP_DEF));
|
1046 | this.seenDirectives.forEach(maybeApplyOverrides(ɵNG_DIR_DEF));
|
1047 | this.seenComponents.clear();
|
1048 | this.seenDirectives.clear();
|
1049 | }
|
1050 | applyProviderOverridesToModule(moduleType) {
|
1051 | if (this.moduleProvidersOverridden.has(moduleType)) {
|
1052 | return;
|
1053 | }
|
1054 | this.moduleProvidersOverridden.add(moduleType);
|
1055 | const injectorDef = moduleType[ɵNG_INJ_DEF];
|
1056 | if (this.providerOverridesByToken.size > 0) {
|
1057 | const providers = [
|
1058 | ...injectorDef.providers,
|
1059 | ...(this.providerOverridesByModule.get(moduleType) || [])
|
1060 | ];
|
1061 | if (this.hasProviderOverrides(providers)) {
|
1062 | this.maybeStoreNgDef(ɵNG_INJ_DEF, moduleType);
|
1063 | this.storeFieldOfDefOnType(moduleType, ɵNG_INJ_DEF, 'providers');
|
1064 | injectorDef.providers = this.getOverriddenProviders(providers);
|
1065 | }
|
1066 |
|
1067 | const moduleDef = moduleType[ɵNG_MOD_DEF];
|
1068 | const imports = maybeUnwrapFn(moduleDef.imports);
|
1069 | for (const importedModule of imports) {
|
1070 | this.applyProviderOverridesToModule(importedModule);
|
1071 | }
|
1072 |
|
1073 |
|
1074 | for (const importedModule of flatten(injectorDef.imports)) {
|
1075 | if (isModuleWithProviders(importedModule)) {
|
1076 | this.defCleanupOps.push({
|
1077 | object: importedModule,
|
1078 | fieldName: 'providers',
|
1079 | originalValue: importedModule.providers
|
1080 | });
|
1081 | importedModule.providers = this.getOverriddenProviders(importedModule.providers);
|
1082 | }
|
1083 | }
|
1084 | }
|
1085 | }
|
1086 | patchComponentsWithExistingStyles() {
|
1087 | this.existingComponentStyles.forEach((styles, type) => type[ɵNG_COMP_DEF].styles = styles);
|
1088 | this.existingComponentStyles.clear();
|
1089 | }
|
1090 | queueTypeArray(arr, moduleType) {
|
1091 | for (const value of arr) {
|
1092 | if (Array.isArray(value)) {
|
1093 | this.queueTypeArray(value, moduleType);
|
1094 | }
|
1095 | else {
|
1096 | this.queueType(value, moduleType);
|
1097 | }
|
1098 | }
|
1099 | }
|
1100 | recompileNgModule(ngModule, metadata) {
|
1101 |
|
1102 | this.maybeStoreNgDef(ɵNG_MOD_DEF, ngModule);
|
1103 | this.maybeStoreNgDef(ɵNG_INJ_DEF, ngModule);
|
1104 | ɵcompileNgModuleDefs(ngModule, metadata);
|
1105 | }
|
1106 | queueType(type, moduleType) {
|
1107 | const component = this.resolvers.component.resolve(type);
|
1108 | if (component) {
|
1109 |
|
1110 |
|
1111 |
|
1112 | if (isComponentDefPendingResolution(type) || !type.hasOwnProperty(ɵNG_COMP_DEF)) {
|
1113 | this.pendingComponents.add(type);
|
1114 | }
|
1115 | this.seenComponents.add(type);
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 | if (!this.componentToModuleScope.has(type) ||
|
1132 | this.componentToModuleScope.get(type) === TestingModuleOverride.DECLARATION) {
|
1133 | this.componentToModuleScope.set(type, moduleType);
|
1134 | }
|
1135 | return;
|
1136 | }
|
1137 | const directive = this.resolvers.directive.resolve(type);
|
1138 | if (directive) {
|
1139 | if (!type.hasOwnProperty(ɵNG_DIR_DEF)) {
|
1140 | this.pendingDirectives.add(type);
|
1141 | }
|
1142 | this.seenDirectives.add(type);
|
1143 | return;
|
1144 | }
|
1145 | const pipe = this.resolvers.pipe.resolve(type);
|
1146 | if (pipe && !type.hasOwnProperty(ɵNG_PIPE_DEF)) {
|
1147 | this.pendingPipes.add(type);
|
1148 | return;
|
1149 | }
|
1150 | }
|
1151 | queueTypesFromModulesArray(arr) {
|
1152 |
|
1153 |
|
1154 |
|
1155 | const processedNgModuleDefs = new Set();
|
1156 | const queueTypesFromModulesArrayRecur = (arr) => {
|
1157 | for (const value of arr) {
|
1158 | if (Array.isArray(value)) {
|
1159 | queueTypesFromModulesArrayRecur(value);
|
1160 | }
|
1161 | else if (hasNgModuleDef(value)) {
|
1162 | const def = value.ɵmod;
|
1163 | if (processedNgModuleDefs.has(def)) {
|
1164 | continue;
|
1165 | }
|
1166 | processedNgModuleDefs.add(def);
|
1167 |
|
1168 |
|
1169 | this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
|
1170 | queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.imports));
|
1171 | queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.exports));
|
1172 | }
|
1173 | else if (isModuleWithProviders(value)) {
|
1174 | queueTypesFromModulesArrayRecur([value.ngModule]);
|
1175 | }
|
1176 | }
|
1177 | };
|
1178 | queueTypesFromModulesArrayRecur(arr);
|
1179 | }
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 | collectModulesAffectedByOverrides(arr) {
|
1188 | const seenModules = new Set();
|
1189 | const affectedModules = new Set();
|
1190 | const calcAffectedModulesRecur = (arr, path) => {
|
1191 | for (const value of arr) {
|
1192 | if (Array.isArray(value)) {
|
1193 |
|
1194 |
|
1195 | calcAffectedModulesRecur(value, path);
|
1196 | }
|
1197 | else if (hasNgModuleDef(value)) {
|
1198 | if (seenModules.has(value)) {
|
1199 |
|
1200 |
|
1201 |
|
1202 | if (affectedModules.has(value)) {
|
1203 | path.forEach(item => affectedModules.add(item));
|
1204 | }
|
1205 | continue;
|
1206 | }
|
1207 | seenModules.add(value);
|
1208 | if (this.overriddenModules.has(value)) {
|
1209 | path.forEach(item => affectedModules.add(item));
|
1210 | }
|
1211 |
|
1212 | const moduleDef = value[ɵNG_MOD_DEF];
|
1213 | calcAffectedModulesRecur(maybeUnwrapFn(moduleDef.imports), path.concat(value));
|
1214 | }
|
1215 | }
|
1216 | };
|
1217 | calcAffectedModulesRecur(arr, []);
|
1218 | return affectedModules;
|
1219 | }
|
1220 | maybeStoreNgDef(prop, type) {
|
1221 | if (!this.initialNgDefs.has(type)) {
|
1222 | const currentDef = Object.getOwnPropertyDescriptor(type, prop);
|
1223 | this.initialNgDefs.set(type, [prop, currentDef]);
|
1224 | }
|
1225 | }
|
1226 | storeFieldOfDefOnType(type, defField, fieldName) {
|
1227 | const def = type[defField];
|
1228 | const originalValue = def[fieldName];
|
1229 | this.defCleanupOps.push({ object: def, fieldName, originalValue });
|
1230 | }
|
1231 | |
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 | clearComponentResolutionQueue() {
|
1237 | if (this.originalComponentResolutionQueue === null) {
|
1238 | this.originalComponentResolutionQueue = new Map();
|
1239 | }
|
1240 | clearResolutionOfComponentResourcesQueue().forEach((value, key) => this.originalComponentResolutionQueue.set(key, value));
|
1241 | }
|
1242 | |
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 | restoreComponentResolutionQueue() {
|
1248 | if (this.originalComponentResolutionQueue !== null) {
|
1249 | restoreComponentResolutionQueue(this.originalComponentResolutionQueue);
|
1250 | this.originalComponentResolutionQueue = null;
|
1251 | }
|
1252 | }
|
1253 | restoreOriginalState() {
|
1254 |
|
1255 |
|
1256 | forEachRight(this.defCleanupOps, (op) => {
|
1257 | op.object[op.fieldName] = op.originalValue;
|
1258 | });
|
1259 |
|
1260 | this.initialNgDefs.forEach((value, type) => {
|
1261 | const [prop, descriptor] = value;
|
1262 | if (!descriptor) {
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 | delete type[prop];
|
1270 | }
|
1271 | else {
|
1272 | Object.defineProperty(type, prop, descriptor);
|
1273 | }
|
1274 | });
|
1275 | this.initialNgDefs.clear();
|
1276 | this.moduleProvidersOverridden.clear();
|
1277 | this.restoreComponentResolutionQueue();
|
1278 |
|
1279 | ɵsetLocaleId(ɵDEFAULT_LOCALE_ID);
|
1280 | }
|
1281 | compileTestModule() {
|
1282 | class RootScopeModule {
|
1283 | }
|
1284 | ɵcompileNgModuleDefs(RootScopeModule, {
|
1285 | providers: [...this.rootProviderOverrides],
|
1286 | });
|
1287 | const ngZone = new NgZone({ enableLongStackTrace: true });
|
1288 | const providers = [
|
1289 | { provide: NgZone, useValue: ngZone },
|
1290 | { provide: Compiler, useFactory: () => new R3TestCompiler(this) },
|
1291 | ...this.providers,
|
1292 | ...this.providerOverrides,
|
1293 | ];
|
1294 | const imports = [RootScopeModule, this.additionalModuleTypes, this.imports || []];
|
1295 |
|
1296 | ɵcompileNgModuleDefs(this.testModuleType, {
|
1297 | declarations: this.declarations,
|
1298 | imports,
|
1299 | schemas: this.schemas,
|
1300 | providers,
|
1301 | }, true);
|
1302 |
|
1303 | this.applyProviderOverridesToModule(this.testModuleType);
|
1304 | }
|
1305 | get injector() {
|
1306 | if (this._injector !== null) {
|
1307 | return this._injector;
|
1308 | }
|
1309 | const providers = [];
|
1310 | const compilerOptions = this.platform.injector.get(COMPILER_OPTIONS);
|
1311 | compilerOptions.forEach(opts => {
|
1312 | if (opts.providers) {
|
1313 | providers.push(opts.providers);
|
1314 | }
|
1315 | });
|
1316 | if (this.compilerProviders !== null) {
|
1317 | providers.push(...this.compilerProviders);
|
1318 | }
|
1319 |
|
1320 | class CompilerModule {
|
1321 | }
|
1322 | ɵcompileNgModuleDefs(CompilerModule, { providers });
|
1323 | const CompilerModuleFactory = new ɵNgModuleFactory(CompilerModule);
|
1324 | this._injector = CompilerModuleFactory.create(this.platform.injector).injector;
|
1325 | return this._injector;
|
1326 | }
|
1327 |
|
1328 | getSingleProviderOverrides(provider) {
|
1329 | const token = getProviderToken(provider);
|
1330 | return this.providerOverridesByToken.get(token) || null;
|
1331 | }
|
1332 | getProviderOverrides(providers) {
|
1333 | if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
|
1334 | return [];
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 | return flatten(flatten(providers, (provider) => this.getSingleProviderOverrides(provider) || []));
|
1341 | }
|
1342 | getOverriddenProviders(providers) {
|
1343 | if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
|
1344 | return [];
|
1345 | const flattenedProviders = flatten(providers);
|
1346 | const overrides = this.getProviderOverrides(flattenedProviders);
|
1347 | const overriddenProviders = [...flattenedProviders, ...overrides];
|
1348 | const final = [];
|
1349 | const seenOverriddenProviders = new Set();
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 | forEachRight(overriddenProviders, (provider) => {
|
1355 | const token = getProviderToken(provider);
|
1356 | if (this.providerOverridesByToken.has(token)) {
|
1357 | if (!seenOverriddenProviders.has(token)) {
|
1358 | seenOverriddenProviders.add(token);
|
1359 |
|
1360 |
|
1361 |
|
1362 | final.unshift(Object.assign(Object.assign({}, provider), { multi: false }));
|
1363 | }
|
1364 | }
|
1365 | else {
|
1366 | final.unshift(provider);
|
1367 | }
|
1368 | });
|
1369 | return final;
|
1370 | }
|
1371 | hasProviderOverrides(providers) {
|
1372 | return this.getProviderOverrides(providers).length > 0;
|
1373 | }
|
1374 | patchDefWithProviderOverrides(declaration, field) {
|
1375 | const def = declaration[field];
|
1376 | if (def && def.providersResolver) {
|
1377 | this.maybeStoreNgDef(field, declaration);
|
1378 | const resolver = def.providersResolver;
|
1379 | const processProvidersFn = (providers) => this.getOverriddenProviders(providers);
|
1380 | this.storeFieldOfDefOnType(declaration, field, 'providersResolver');
|
1381 | def.providersResolver = (ngDef) => resolver(ngDef, processProvidersFn);
|
1382 | }
|
1383 | }
|
1384 | }
|
1385 | function initResolvers() {
|
1386 | return {
|
1387 | module: new NgModuleResolver(),
|
1388 | component: new ComponentResolver(),
|
1389 | directive: new DirectiveResolver(),
|
1390 | pipe: new PipeResolver()
|
1391 | };
|
1392 | }
|
1393 | function hasNgModuleDef(value) {
|
1394 | return value.hasOwnProperty('ɵmod');
|
1395 | }
|
1396 | function maybeUnwrapFn(maybeFn) {
|
1397 | return maybeFn instanceof Function ? maybeFn() : maybeFn;
|
1398 | }
|
1399 | function flatten(values, mapFn) {
|
1400 | const out = [];
|
1401 | values.forEach(value => {
|
1402 | if (Array.isArray(value)) {
|
1403 | out.push(...flatten(value, mapFn));
|
1404 | }
|
1405 | else {
|
1406 | out.push(mapFn ? mapFn(value) : value);
|
1407 | }
|
1408 | });
|
1409 | return out;
|
1410 | }
|
1411 | function getProviderField(provider, field) {
|
1412 | return provider && typeof provider === 'object' && provider[field];
|
1413 | }
|
1414 | function getProviderToken(provider) {
|
1415 | return getProviderField(provider, 'provide') || provider;
|
1416 | }
|
1417 | function isModuleWithProviders(value) {
|
1418 | return value.hasOwnProperty('ngModule');
|
1419 | }
|
1420 | function forEachRight(values, fn) {
|
1421 | for (let idx = values.length - 1; idx >= 0; idx--) {
|
1422 | fn(values[idx], idx);
|
1423 | }
|
1424 | }
|
1425 | function invalidTypeError(name, expectedType) {
|
1426 | return new Error(`${name} class doesn't have @${expectedType} decorator or is missing metadata.`);
|
1427 | }
|
1428 | class R3TestCompiler {
|
1429 | constructor(testBed) {
|
1430 | this.testBed = testBed;
|
1431 | }
|
1432 | compileModuleSync(moduleType) {
|
1433 | this.testBed._compileNgModuleSync(moduleType);
|
1434 | return new ɵNgModuleFactory(moduleType);
|
1435 | }
|
1436 | compileModuleAsync(moduleType) {
|
1437 | return __awaiter(this, void 0, void 0, function* () {
|
1438 | yield this.testBed._compileNgModuleAsync(moduleType);
|
1439 | return new ɵNgModuleFactory(moduleType);
|
1440 | });
|
1441 | }
|
1442 | compileModuleAndAllComponentsSync(moduleType) {
|
1443 | const ngModuleFactory = this.compileModuleSync(moduleType);
|
1444 | const componentFactories = this.testBed._getComponentFactories(moduleType);
|
1445 | return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
|
1446 | }
|
1447 | compileModuleAndAllComponentsAsync(moduleType) {
|
1448 | return __awaiter(this, void 0, void 0, function* () {
|
1449 | const ngModuleFactory = yield this.compileModuleAsync(moduleType);
|
1450 | const componentFactories = this.testBed._getComponentFactories(moduleType);
|
1451 | return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
|
1452 | });
|
1453 | }
|
1454 | clearCache() { }
|
1455 | clearCacheFor(type) { }
|
1456 | getModuleId(moduleType) {
|
1457 | const meta = this.testBed._getModuleResolver().resolve(moduleType);
|
1458 | return meta && meta.id || undefined;
|
1459 | }
|
1460 | }
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 | const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 | class TestComponentRenderer {
|
1477 | insertRootElement(rootElementId) { }
|
1478 | removeAllRootElements() { }
|
1479 | }
|
1480 |
|
1481 |
|
1482 |
|
1483 | const ComponentFixtureAutoDetect = new InjectionToken('ComponentFixtureAutoDetect');
|
1484 |
|
1485 |
|
1486 |
|
1487 | const ComponentFixtureNoNgZone = new InjectionToken('ComponentFixtureNoNgZone');
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 | let _nextRootElementId$1 = 0;
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 | class TestBedRender3 {
|
1508 | constructor() {
|
1509 |
|
1510 | this.platform = null;
|
1511 | this.ngModule = null;
|
1512 | this._compiler = null;
|
1513 | this._testModuleRef = null;
|
1514 | this._activeFixtures = [];
|
1515 | this._globalCompilationChecked = false;
|
1516 | }
|
1517 | |
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 | static initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
1531 | const testBed = _getTestBedRender3();
|
1532 | testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
1533 | return testBed;
|
1534 | }
|
1535 | |
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 | static resetTestEnvironment() {
|
1541 | _getTestBedRender3().resetTestEnvironment();
|
1542 | }
|
1543 | static configureCompiler(config) {
|
1544 | _getTestBedRender3().configureCompiler(config);
|
1545 | return TestBedRender3;
|
1546 | }
|
1547 | |
1548 |
|
1549 |
|
1550 |
|
1551 | static configureTestingModule(moduleDef) {
|
1552 | _getTestBedRender3().configureTestingModule(moduleDef);
|
1553 | return TestBedRender3;
|
1554 | }
|
1555 | |
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 | static compileComponents() {
|
1561 | return _getTestBedRender3().compileComponents();
|
1562 | }
|
1563 | static overrideModule(ngModule, override) {
|
1564 | _getTestBedRender3().overrideModule(ngModule, override);
|
1565 | return TestBedRender3;
|
1566 | }
|
1567 | static overrideComponent(component, override) {
|
1568 | _getTestBedRender3().overrideComponent(component, override);
|
1569 | return TestBedRender3;
|
1570 | }
|
1571 | static overrideDirective(directive, override) {
|
1572 | _getTestBedRender3().overrideDirective(directive, override);
|
1573 | return TestBedRender3;
|
1574 | }
|
1575 | static overridePipe(pipe, override) {
|
1576 | _getTestBedRender3().overridePipe(pipe, override);
|
1577 | return TestBedRender3;
|
1578 | }
|
1579 | static overrideTemplate(component, template) {
|
1580 | _getTestBedRender3().overrideComponent(component, { set: { template, templateUrl: null } });
|
1581 | return TestBedRender3;
|
1582 | }
|
1583 | |
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 | static overrideTemplateUsingTestingModule(component, template) {
|
1590 | _getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
|
1591 | return TestBedRender3;
|
1592 | }
|
1593 | static overrideProvider(token, provider) {
|
1594 | _getTestBedRender3().overrideProvider(token, provider);
|
1595 | return TestBedRender3;
|
1596 | }
|
1597 | static inject(token, notFoundValue, flags) {
|
1598 | return _getTestBedRender3().inject(token, notFoundValue, flags);
|
1599 | }
|
1600 |
|
1601 | static get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
1602 | return _getTestBedRender3().inject(token, notFoundValue, flags);
|
1603 | }
|
1604 | static createComponent(component) {
|
1605 | return _getTestBedRender3().createComponent(component);
|
1606 | }
|
1607 | static resetTestingModule() {
|
1608 | _getTestBedRender3().resetTestingModule();
|
1609 | return TestBedRender3;
|
1610 | }
|
1611 | static shouldTearDownTestingModule() {
|
1612 | return _getTestBedRender3().shouldTearDownTestingModule();
|
1613 | }
|
1614 | static tearDownTestingModule() {
|
1615 | _getTestBedRender3().tearDownTestingModule();
|
1616 | }
|
1617 | |
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 | initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
1631 | if (this.platform || this.ngModule) {
|
1632 | throw new Error('Cannot set base providers because it has already been called');
|
1633 | }
|
1634 |
|
1635 |
|
1636 | TestBedRender3._environmentTeardownOptions =
|
1637 | typeof summariesOrOptions === 'function' ? undefined : summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
1638 | this.platform = platform;
|
1639 | this.ngModule = ngModule;
|
1640 | this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
1641 | }
|
1642 | |
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 | resetTestEnvironment() {
|
1648 | this.resetTestingModule();
|
1649 | this._compiler = null;
|
1650 | this.platform = null;
|
1651 | this.ngModule = null;
|
1652 | TestBedRender3._environmentTeardownOptions = undefined;
|
1653 | }
|
1654 | resetTestingModule() {
|
1655 | this.checkGlobalCompilationFinished();
|
1656 | ɵresetCompiledComponents();
|
1657 | if (this._compiler !== null) {
|
1658 | this.compiler.restoreOriginalState();
|
1659 | }
|
1660 | this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
1661 |
|
1662 |
|
1663 |
|
1664 | try {
|
1665 | this.destroyActiveFixtures();
|
1666 | }
|
1667 | finally {
|
1668 | try {
|
1669 | if (this.shouldTearDownTestingModule()) {
|
1670 | this.tearDownTestingModule();
|
1671 | }
|
1672 | }
|
1673 | finally {
|
1674 | this._testModuleRef = null;
|
1675 | this._instanceTeardownOptions = undefined;
|
1676 | }
|
1677 | }
|
1678 | }
|
1679 | configureCompiler(config) {
|
1680 | if (config.useJit != null) {
|
1681 | throw new Error('the Render3 compiler JiT mode is not configurable !');
|
1682 | }
|
1683 | if (config.providers !== undefined) {
|
1684 | this.compiler.setCompilerProviders(config.providers);
|
1685 | }
|
1686 | }
|
1687 | configureTestingModule(moduleDef) {
|
1688 | this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
|
1689 |
|
1690 |
|
1691 | this._instanceTeardownOptions = moduleDef.teardown;
|
1692 | this.compiler.configureTestingModule(moduleDef);
|
1693 | }
|
1694 | compileComponents() {
|
1695 | return this.compiler.compileComponents();
|
1696 | }
|
1697 | inject(token, notFoundValue, flags) {
|
1698 | if (token === TestBedRender3) {
|
1699 | return this;
|
1700 | }
|
1701 | const UNDEFINED = {};
|
1702 | const result = this.testModuleRef.injector.get(token, UNDEFINED, flags);
|
1703 | return result === UNDEFINED ? this.compiler.injector.get(token, notFoundValue, flags) :
|
1704 | result;
|
1705 | }
|
1706 |
|
1707 | get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
1708 | return this.inject(token, notFoundValue, flags);
|
1709 | }
|
1710 | execute(tokens, fn, context) {
|
1711 | const params = tokens.map(t => this.inject(t));
|
1712 | return fn.apply(context, params);
|
1713 | }
|
1714 | overrideModule(ngModule, override) {
|
1715 | this.assertNotInstantiated('overrideModule', 'override module metadata');
|
1716 | this.compiler.overrideModule(ngModule, override);
|
1717 | }
|
1718 | overrideComponent(component, override) {
|
1719 | this.assertNotInstantiated('overrideComponent', 'override component metadata');
|
1720 | this.compiler.overrideComponent(component, override);
|
1721 | }
|
1722 | overrideTemplateUsingTestingModule(component, template) {
|
1723 | this.assertNotInstantiated('R3TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
|
1724 | this.compiler.overrideTemplateUsingTestingModule(component, template);
|
1725 | }
|
1726 | overrideDirective(directive, override) {
|
1727 | this.assertNotInstantiated('overrideDirective', 'override directive metadata');
|
1728 | this.compiler.overrideDirective(directive, override);
|
1729 | }
|
1730 | overridePipe(pipe, override) {
|
1731 | this.assertNotInstantiated('overridePipe', 'override pipe metadata');
|
1732 | this.compiler.overridePipe(pipe, override);
|
1733 | }
|
1734 | |
1735 |
|
1736 |
|
1737 | overrideProvider(token, provider) {
|
1738 | this.assertNotInstantiated('overrideProvider', 'override provider');
|
1739 | this.compiler.overrideProvider(token, provider);
|
1740 | }
|
1741 | createComponent(type) {
|
1742 | const testComponentRenderer = this.inject(TestComponentRenderer);
|
1743 | const rootElId = `root${_nextRootElementId$1++}`;
|
1744 | testComponentRenderer.insertRootElement(rootElId);
|
1745 | const componentDef = type.ɵcmp;
|
1746 | if (!componentDef) {
|
1747 | throw new Error(`It looks like '${ɵstringify(type)}' has not been IVY compiled - it has no 'ɵcmp' field`);
|
1748 | }
|
1749 |
|
1750 | const noNgZone = this.inject(ComponentFixtureNoNgZone, false);
|
1751 |
|
1752 | const autoDetect = this.inject(ComponentFixtureAutoDetect, false);
|
1753 | const ngZone = noNgZone ? null : this.inject(NgZone, null);
|
1754 | const componentFactory = new ɵRender3ComponentFactory(componentDef);
|
1755 | const initComponent = () => {
|
1756 | const componentRef = componentFactory.create(Injector.NULL, [], `#${rootElId}`, this.testModuleRef);
|
1757 | return new ComponentFixture(componentRef, ngZone, autoDetect);
|
1758 | };
|
1759 | const fixture = ngZone ? ngZone.run(initComponent) : initComponent();
|
1760 | this._activeFixtures.push(fixture);
|
1761 | return fixture;
|
1762 | }
|
1763 | |
1764 |
|
1765 |
|
1766 |
|
1767 | get compiler() {
|
1768 | if (this._compiler === null) {
|
1769 | throw new Error(`Need to call TestBed.initTestEnvironment() first`);
|
1770 | }
|
1771 | return this._compiler;
|
1772 | }
|
1773 | |
1774 |
|
1775 |
|
1776 |
|
1777 | get testModuleRef() {
|
1778 | if (this._testModuleRef === null) {
|
1779 | this._testModuleRef = this.compiler.finalize();
|
1780 | }
|
1781 | return this._testModuleRef;
|
1782 | }
|
1783 | assertNotInstantiated(methodName, methodDescription) {
|
1784 | if (this._testModuleRef !== null) {
|
1785 | throw new Error(`Cannot ${methodDescription} when the test module has already been instantiated. ` +
|
1786 | `Make sure you are not using \`inject\` before \`${methodName}\`.`);
|
1787 | }
|
1788 | }
|
1789 | |
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 | checkGlobalCompilationFinished() {
|
1802 |
|
1803 |
|
1804 | if (!this._globalCompilationChecked && this._testModuleRef === null) {
|
1805 | ɵflushModuleScopingQueueAsMuchAsPossible();
|
1806 | }
|
1807 | this._globalCompilationChecked = true;
|
1808 | }
|
1809 | destroyActiveFixtures() {
|
1810 | let errorCount = 0;
|
1811 | this._activeFixtures.forEach((fixture) => {
|
1812 | try {
|
1813 | fixture.destroy();
|
1814 | }
|
1815 | catch (e) {
|
1816 | errorCount++;
|
1817 | console.error('Error during cleanup of component', {
|
1818 | component: fixture.componentInstance,
|
1819 | stacktrace: e,
|
1820 | });
|
1821 | }
|
1822 | });
|
1823 | this._activeFixtures = [];
|
1824 | if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
1825 | throw Error(`${errorCount} ${(errorCount === 1 ? 'component' : 'components')} ` +
|
1826 | `threw errors during cleanup`);
|
1827 | }
|
1828 | }
|
1829 | shouldRethrowTeardownErrors() {
|
1830 | var _a, _b;
|
1831 | const instanceOptions = this._instanceTeardownOptions;
|
1832 | const environmentOptions = TestBedRender3._environmentTeardownOptions;
|
1833 |
|
1834 | if (!instanceOptions && !environmentOptions) {
|
1835 | return TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
1836 | }
|
1837 |
|
1838 | return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : this.shouldTearDownTestingModule();
|
1839 | }
|
1840 | shouldTearDownTestingModule() {
|
1841 | var _a, _b, _c, _d;
|
1842 | return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedRender3._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
1843 | }
|
1844 | tearDownTestingModule() {
|
1845 | var _a;
|
1846 |
|
1847 | if (this._testModuleRef === null) {
|
1848 | return;
|
1849 | }
|
1850 |
|
1851 |
|
1852 | const testRenderer = this.inject(TestComponentRenderer);
|
1853 | try {
|
1854 | this._testModuleRef.destroy();
|
1855 | }
|
1856 | catch (e) {
|
1857 | if (this.shouldRethrowTeardownErrors()) {
|
1858 | throw e;
|
1859 | }
|
1860 | else {
|
1861 | console.error('Error during cleanup of a testing module', {
|
1862 | component: this._testModuleRef.instance,
|
1863 | stacktrace: e,
|
1864 | });
|
1865 | }
|
1866 | }
|
1867 | finally {
|
1868 | (_a = testRenderer.removeAllRootElements) === null || _a === void 0 ? void 0 : _a.call(testRenderer);
|
1869 | }
|
1870 | }
|
1871 | }
|
1872 | let testBed$1;
|
1873 | function _getTestBedRender3() {
|
1874 | return testBed$1 = testBed$1 || new TestBedRender3();
|
1875 | }
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 | function unimplemented() {
|
1885 | throw Error('unimplemented');
|
1886 | }
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 | class TestingCompiler extends Compiler {
|
1893 | get injector() {
|
1894 | throw unimplemented();
|
1895 | }
|
1896 | overrideModule(module, overrides) {
|
1897 | throw unimplemented();
|
1898 | }
|
1899 | overrideDirective(directive, overrides) {
|
1900 | throw unimplemented();
|
1901 | }
|
1902 | overrideComponent(component, overrides) {
|
1903 | throw unimplemented();
|
1904 | }
|
1905 | overridePipe(directive, overrides) {
|
1906 | throw unimplemented();
|
1907 | }
|
1908 | |
1909 |
|
1910 |
|
1911 |
|
1912 | loadAotSummaries(summaries) {
|
1913 | throw unimplemented();
|
1914 | }
|
1915 | |
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 | getComponentFactory(component) {
|
1921 | throw unimplemented();
|
1922 | }
|
1923 | |
1924 |
|
1925 |
|
1926 |
|
1927 | getComponentFromError(error) {
|
1928 | throw unimplemented();
|
1929 | }
|
1930 | }
|
1931 | TestingCompiler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TestingCompiler, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
1932 | TestingCompiler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TestingCompiler });
|
1933 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TestingCompiler, decorators: [{
|
1934 | type: Injectable
|
1935 | }] });
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 | class TestingCompilerFactory {
|
1942 | }
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 | let _nextRootElementId = 0;
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 | class TestBedViewEngine {
|
1963 | constructor() {
|
1964 | this._instantiated = false;
|
1965 | this._compiler = null;
|
1966 | this._moduleRef = null;
|
1967 | this._moduleFactory = null;
|
1968 | this._pendingModuleFactory = null;
|
1969 | this._compilerOptions = [];
|
1970 | this._moduleOverrides = [];
|
1971 | this._componentOverrides = [];
|
1972 | this._directiveOverrides = [];
|
1973 | this._pipeOverrides = [];
|
1974 | this._providers = [];
|
1975 | this._declarations = [];
|
1976 | this._imports = [];
|
1977 | this._schemas = [];
|
1978 | this._activeFixtures = [];
|
1979 | this._testEnvAotSummaries = () => [];
|
1980 | this._aotSummaries = [];
|
1981 | this._templateOverrides = [];
|
1982 | this._isRoot = true;
|
1983 | this._rootProviderOverrides = [];
|
1984 | this.platform = null;
|
1985 | this.ngModule = null;
|
1986 | }
|
1987 | |
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 | static initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
1999 | const testBed = _getTestBedViewEngine();
|
2000 | testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
2001 | return testBed;
|
2002 | }
|
2003 | |
2004 |
|
2005 |
|
2006 | static resetTestEnvironment() {
|
2007 | _getTestBedViewEngine().resetTestEnvironment();
|
2008 | }
|
2009 | static resetTestingModule() {
|
2010 | _getTestBedViewEngine().resetTestingModule();
|
2011 | return TestBedViewEngine;
|
2012 | }
|
2013 | |
2014 |
|
2015 |
|
2016 |
|
2017 | static configureCompiler(config) {
|
2018 | _getTestBedViewEngine().configureCompiler(config);
|
2019 | return TestBedViewEngine;
|
2020 | }
|
2021 | |
2022 |
|
2023 |
|
2024 |
|
2025 | static configureTestingModule(moduleDef) {
|
2026 | _getTestBedViewEngine().configureTestingModule(moduleDef);
|
2027 | return TestBedViewEngine;
|
2028 | }
|
2029 | |
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 | static compileComponents() {
|
2035 | return getTestBed().compileComponents();
|
2036 | }
|
2037 | static overrideModule(ngModule, override) {
|
2038 | _getTestBedViewEngine().overrideModule(ngModule, override);
|
2039 | return TestBedViewEngine;
|
2040 | }
|
2041 | static overrideComponent(component, override) {
|
2042 | _getTestBedViewEngine().overrideComponent(component, override);
|
2043 | return TestBedViewEngine;
|
2044 | }
|
2045 | static overrideDirective(directive, override) {
|
2046 | _getTestBedViewEngine().overrideDirective(directive, override);
|
2047 | return TestBedViewEngine;
|
2048 | }
|
2049 | static overridePipe(pipe, override) {
|
2050 | _getTestBedViewEngine().overridePipe(pipe, override);
|
2051 | return TestBedViewEngine;
|
2052 | }
|
2053 | static overrideTemplate(component, template) {
|
2054 | _getTestBedViewEngine().overrideComponent(component, { set: { template, templateUrl: null } });
|
2055 | return TestBedViewEngine;
|
2056 | }
|
2057 | |
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 | static overrideTemplateUsingTestingModule(component, template) {
|
2064 | _getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
|
2065 | return TestBedViewEngine;
|
2066 | }
|
2067 | static overrideProvider(token, provider) {
|
2068 | _getTestBedViewEngine().overrideProvider(token, provider);
|
2069 | return TestBedViewEngine;
|
2070 | }
|
2071 | static inject(token, notFoundValue, flags) {
|
2072 | return _getTestBedViewEngine().inject(token, notFoundValue, flags);
|
2073 | }
|
2074 |
|
2075 | static get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
2076 | return _getTestBedViewEngine().inject(token, notFoundValue, flags);
|
2077 | }
|
2078 | static createComponent(component) {
|
2079 | return _getTestBedViewEngine().createComponent(component);
|
2080 | }
|
2081 | static shouldTearDownTestingModule() {
|
2082 | return _getTestBedViewEngine().shouldTearDownTestingModule();
|
2083 | }
|
2084 | static tearDownTestingModule() {
|
2085 | _getTestBedViewEngine().tearDownTestingModule();
|
2086 | }
|
2087 | |
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 | initTestEnvironment(ngModule, platform, summariesOrOptions) {
|
2099 | if (this.platform || this.ngModule) {
|
2100 | throw new Error('Cannot set base providers because it has already been called');
|
2101 | }
|
2102 | this.platform = platform;
|
2103 | this.ngModule = ngModule;
|
2104 | if (typeof summariesOrOptions === 'function') {
|
2105 | this._testEnvAotSummaries = summariesOrOptions;
|
2106 | TestBedViewEngine._environmentTeardownOptions = undefined;
|
2107 | }
|
2108 | else {
|
2109 | this._testEnvAotSummaries = (summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.aotSummaries) || (() => []);
|
2110 | TestBedViewEngine._environmentTeardownOptions = summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
2111 | }
|
2112 | }
|
2113 | |
2114 |
|
2115 |
|
2116 | resetTestEnvironment() {
|
2117 | this.resetTestingModule();
|
2118 | this.platform = null;
|
2119 | this.ngModule = null;
|
2120 | this._testEnvAotSummaries = () => [];
|
2121 | TestBedViewEngine._environmentTeardownOptions = undefined;
|
2122 | }
|
2123 | resetTestingModule() {
|
2124 | ɵclearOverrides();
|
2125 | this._aotSummaries = [];
|
2126 | this._templateOverrides = [];
|
2127 | this._compiler = null;
|
2128 | this._moduleOverrides = [];
|
2129 | this._componentOverrides = [];
|
2130 | this._directiveOverrides = [];
|
2131 | this._pipeOverrides = [];
|
2132 | this._isRoot = true;
|
2133 | this._rootProviderOverrides = [];
|
2134 | this._moduleFactory = null;
|
2135 | this._pendingModuleFactory = null;
|
2136 | this._compilerOptions = [];
|
2137 | this._providers = [];
|
2138 | this._declarations = [];
|
2139 | this._imports = [];
|
2140 | this._schemas = [];
|
2141 |
|
2142 |
|
2143 |
|
2144 | try {
|
2145 | this.destroyActiveFixtures();
|
2146 | }
|
2147 | finally {
|
2148 | try {
|
2149 | if (this.shouldTearDownTestingModule()) {
|
2150 | this.tearDownTestingModule();
|
2151 | }
|
2152 | }
|
2153 | finally {
|
2154 | this._moduleRef = null;
|
2155 | this._instanceTeardownOptions = undefined;
|
2156 | this._instantiated = false;
|
2157 | }
|
2158 | }
|
2159 | }
|
2160 | configureCompiler(config) {
|
2161 | this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
|
2162 | this._compilerOptions.push(config);
|
2163 | }
|
2164 | configureTestingModule(moduleDef) {
|
2165 | this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
|
2166 | if (moduleDef.providers) {
|
2167 | this._providers.push(...moduleDef.providers);
|
2168 | }
|
2169 | if (moduleDef.declarations) {
|
2170 | this._declarations.push(...moduleDef.declarations);
|
2171 | }
|
2172 | if (moduleDef.imports) {
|
2173 | this._imports.push(...moduleDef.imports);
|
2174 | }
|
2175 | if (moduleDef.schemas) {
|
2176 | this._schemas.push(...moduleDef.schemas);
|
2177 | }
|
2178 | if (moduleDef.aotSummaries) {
|
2179 | this._aotSummaries.push(moduleDef.aotSummaries);
|
2180 | }
|
2181 |
|
2182 |
|
2183 | this._instanceTeardownOptions = moduleDef.teardown;
|
2184 | }
|
2185 | compileComponents() {
|
2186 | if (this._moduleFactory || this._instantiated) {
|
2187 | return Promise.resolve(null);
|
2188 | }
|
2189 | const moduleType = this._createCompilerAndModule();
|
2190 | this._pendingModuleFactory = moduleType;
|
2191 | return this._compiler.compileModuleAndAllComponentsAsync(moduleType).then(result => {
|
2192 |
|
2193 |
|
2194 |
|
2195 | if (this._pendingModuleFactory === moduleType) {
|
2196 | this._moduleFactory = result.ngModuleFactory;
|
2197 | this._pendingModuleFactory = null;
|
2198 | }
|
2199 | });
|
2200 | }
|
2201 | _initIfNeeded() {
|
2202 | if (this._instantiated) {
|
2203 | return;
|
2204 | }
|
2205 | if (!this._moduleFactory) {
|
2206 | try {
|
2207 | const moduleType = this._createCompilerAndModule();
|
2208 | this._moduleFactory =
|
2209 | this._compiler.compileModuleAndAllComponentsSync(moduleType).ngModuleFactory;
|
2210 | }
|
2211 | catch (e) {
|
2212 | const errorCompType = this._compiler.getComponentFromError(e);
|
2213 | if (errorCompType) {
|
2214 | throw new Error(`This test module uses the component ${ɵstringify(errorCompType)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
|
2215 | `Please call "TestBed.compileComponents" before your test.`);
|
2216 | }
|
2217 | else {
|
2218 | throw e;
|
2219 | }
|
2220 | }
|
2221 | }
|
2222 | for (const { component, templateOf } of this._templateOverrides) {
|
2223 | const compFactory = this._compiler.getComponentFactory(templateOf);
|
2224 | ɵoverrideComponentView(component, compFactory);
|
2225 | }
|
2226 | const ngZone = new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
|
2227 | const providers = [{ provide: NgZone, useValue: ngZone }];
|
2228 | const ngZoneInjector = Injector.create({
|
2229 | providers: providers,
|
2230 | parent: this.platform.injector,
|
2231 | name: this._moduleFactory.moduleType.name
|
2232 | });
|
2233 | this._moduleRef = this._moduleFactory.create(ngZoneInjector);
|
2234 |
|
2235 |
|
2236 | try {
|
2237 | this._moduleRef.injector.get(ApplicationInitStatus).runInitializers();
|
2238 | }
|
2239 | finally {
|
2240 | this._instantiated = true;
|
2241 | }
|
2242 | }
|
2243 | _createCompilerAndModule() {
|
2244 | const providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
|
2245 | const declarations = [...this._declarations, ...this._templateOverrides.map(entry => entry.templateOf)];
|
2246 | const rootScopeImports = [];
|
2247 | const rootProviderOverrides = this._rootProviderOverrides;
|
2248 | if (this._isRoot) {
|
2249 | let RootScopeModule = class RootScopeModule {
|
2250 | };
|
2251 | RootScopeModule = __decorate([
|
2252 | NgModule({
|
2253 | providers: [
|
2254 | ...rootProviderOverrides,
|
2255 | ],
|
2256 | jit: true,
|
2257 | })
|
2258 | ], RootScopeModule);
|
2259 | rootScopeImports.push(RootScopeModule);
|
2260 | }
|
2261 | providers.push({ provide: ɵINJECTOR_SCOPE, useValue: this._isRoot ? 'root' : null });
|
2262 | const imports = [rootScopeImports, this.ngModule, this._imports];
|
2263 | const schemas = this._schemas;
|
2264 | let DynamicTestModule = class DynamicTestModule {
|
2265 | };
|
2266 | DynamicTestModule = __decorate([
|
2267 | NgModule({ providers, declarations, imports, schemas, jit: true })
|
2268 | ], DynamicTestModule);
|
2269 | const compilerFactory = this.platform.injector.get(TestingCompilerFactory);
|
2270 | this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
|
2271 | for (const summary of [this._testEnvAotSummaries, ...this._aotSummaries]) {
|
2272 | this._compiler.loadAotSummaries(summary);
|
2273 | }
|
2274 | this._moduleOverrides.forEach((entry) => this._compiler.overrideModule(entry[0], entry[1]));
|
2275 | this._componentOverrides.forEach((entry) => this._compiler.overrideComponent(entry[0], entry[1]));
|
2276 | this._directiveOverrides.forEach((entry) => this._compiler.overrideDirective(entry[0], entry[1]));
|
2277 | this._pipeOverrides.forEach((entry) => this._compiler.overridePipe(entry[0], entry[1]));
|
2278 | return DynamicTestModule;
|
2279 | }
|
2280 | _assertNotInstantiated(methodName, methodDescription) {
|
2281 | if (this._instantiated) {
|
2282 | throw new Error(`Cannot ${methodDescription} when the test module has already been instantiated. ` +
|
2283 | `Make sure you are not using \`inject\` before \`${methodName}\`.`);
|
2284 | }
|
2285 | }
|
2286 | inject(token, notFoundValue, flags) {
|
2287 | this._initIfNeeded();
|
2288 | if (token === TestBed) {
|
2289 | return this;
|
2290 | }
|
2291 |
|
2292 |
|
2293 | const UNDEFINED = {};
|
2294 | const result = this._moduleRef.injector.get(token, UNDEFINED, flags);
|
2295 | return result === UNDEFINED ? this._compiler.injector.get(token, notFoundValue, flags) :
|
2296 | result;
|
2297 | }
|
2298 |
|
2299 | get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
2300 | return this.inject(token, notFoundValue, flags);
|
2301 | }
|
2302 | execute(tokens, fn, context) {
|
2303 | this._initIfNeeded();
|
2304 | const params = tokens.map(t => this.inject(t));
|
2305 | return fn.apply(context, params);
|
2306 | }
|
2307 | overrideModule(ngModule, override) {
|
2308 | this._assertNotInstantiated('overrideModule', 'override module metadata');
|
2309 | this._moduleOverrides.push([ngModule, override]);
|
2310 | }
|
2311 | overrideComponent(component, override) {
|
2312 | this._assertNotInstantiated('overrideComponent', 'override component metadata');
|
2313 | this._componentOverrides.push([component, override]);
|
2314 | }
|
2315 | overrideDirective(directive, override) {
|
2316 | this._assertNotInstantiated('overrideDirective', 'override directive metadata');
|
2317 | this._directiveOverrides.push([directive, override]);
|
2318 | }
|
2319 | overridePipe(pipe, override) {
|
2320 | this._assertNotInstantiated('overridePipe', 'override pipe metadata');
|
2321 | this._pipeOverrides.push([pipe, override]);
|
2322 | }
|
2323 | overrideProvider(token, provider) {
|
2324 | this._assertNotInstantiated('overrideProvider', 'override provider');
|
2325 | this.overrideProviderImpl(token, provider);
|
2326 | }
|
2327 | overrideProviderImpl(token, provider, deprecated = false) {
|
2328 | let def = null;
|
2329 | if (typeof token !== 'string' && (def = ɵgetInjectableDef(token)) && def.providedIn === 'root') {
|
2330 | if (provider.useFactory) {
|
2331 | this._rootProviderOverrides.push({ provide: token, useFactory: provider.useFactory, deps: provider.deps || [] });
|
2332 | }
|
2333 | else {
|
2334 | this._rootProviderOverrides.push({ provide: token, useValue: provider.useValue });
|
2335 | }
|
2336 | }
|
2337 | let flags = 0;
|
2338 | let value;
|
2339 | if (provider.useFactory) {
|
2340 | flags |= 1024 ;
|
2341 | value = provider.useFactory;
|
2342 | }
|
2343 | else {
|
2344 | flags |= 256 ;
|
2345 | value = provider.useValue;
|
2346 | }
|
2347 | const deps = (provider.deps || []).map((dep) => {
|
2348 | let depFlags = 0 ;
|
2349 | let depToken;
|
2350 | if (Array.isArray(dep)) {
|
2351 | dep.forEach((entry) => {
|
2352 | if (entry instanceof Optional) {
|
2353 | depFlags |= 2 ;
|
2354 | }
|
2355 | else if (entry instanceof SkipSelf) {
|
2356 | depFlags |= 1 ;
|
2357 | }
|
2358 | else {
|
2359 | depToken = entry;
|
2360 | }
|
2361 | });
|
2362 | }
|
2363 | else {
|
2364 | depToken = dep;
|
2365 | }
|
2366 | return [depFlags, depToken];
|
2367 | });
|
2368 | ɵoverrideProvider({ token, flags, deps, value, deprecatedBehavior: deprecated });
|
2369 | }
|
2370 | overrideTemplateUsingTestingModule(component, template) {
|
2371 | this._assertNotInstantiated('overrideTemplateUsingTestingModule', 'override template');
|
2372 | let OverrideComponent = class OverrideComponent {
|
2373 | };
|
2374 | OverrideComponent = __decorate([
|
2375 | Component({ selector: 'empty', template, jit: true })
|
2376 | ], OverrideComponent);
|
2377 | this._templateOverrides.push({ component, templateOf: OverrideComponent });
|
2378 | }
|
2379 | createComponent(component) {
|
2380 | this._initIfNeeded();
|
2381 | const componentFactory = this._compiler.getComponentFactory(component);
|
2382 | if (!componentFactory) {
|
2383 | throw new Error(`Cannot create the component ${ɵstringify(component)} as it was not imported into the testing module!`);
|
2384 | }
|
2385 |
|
2386 | const noNgZone = this.inject(ComponentFixtureNoNgZone, false);
|
2387 |
|
2388 | const autoDetect = this.inject(ComponentFixtureAutoDetect, false);
|
2389 | const ngZone = noNgZone ? null : this.inject(NgZone, null);
|
2390 | const testComponentRenderer = this.inject(TestComponentRenderer);
|
2391 | const rootElId = `root${_nextRootElementId++}`;
|
2392 | testComponentRenderer.insertRootElement(rootElId);
|
2393 | const initComponent = () => {
|
2394 | const componentRef = componentFactory.create(Injector.NULL, [], `#${rootElId}`, this._moduleRef);
|
2395 | return new ComponentFixture(componentRef, ngZone, autoDetect);
|
2396 | };
|
2397 | const fixture = !ngZone ? initComponent() : ngZone.run(initComponent);
|
2398 | this._activeFixtures.push(fixture);
|
2399 | return fixture;
|
2400 | }
|
2401 | destroyActiveFixtures() {
|
2402 | let errorCount = 0;
|
2403 | this._activeFixtures.forEach((fixture) => {
|
2404 | try {
|
2405 | fixture.destroy();
|
2406 | }
|
2407 | catch (e) {
|
2408 | errorCount++;
|
2409 | console.error('Error during cleanup of component', {
|
2410 | component: fixture.componentInstance,
|
2411 | stacktrace: e,
|
2412 | });
|
2413 | }
|
2414 | });
|
2415 | this._activeFixtures = [];
|
2416 | if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
2417 | throw Error(`${errorCount} ${(errorCount === 1 ? 'component' : 'components')} ` +
|
2418 | `threw errors during cleanup`);
|
2419 | }
|
2420 | }
|
2421 | shouldRethrowTeardownErrors() {
|
2422 | var _a, _b;
|
2423 | const instanceOptions = this._instanceTeardownOptions;
|
2424 | const environmentOptions = TestBedViewEngine._environmentTeardownOptions;
|
2425 |
|
2426 | if (!instanceOptions && !environmentOptions) {
|
2427 | return TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
2428 | }
|
2429 |
|
2430 | return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : this.shouldTearDownTestingModule();
|
2431 | }
|
2432 | shouldTearDownTestingModule() {
|
2433 | var _a, _b, _c, _d;
|
2434 | return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
2435 | }
|
2436 | tearDownTestingModule() {
|
2437 | var _a, _b, _c, _d, _e;
|
2438 |
|
2439 | if (this._moduleRef === null) {
|
2440 | return;
|
2441 | }
|
2442 |
|
2443 |
|
2444 | const testRenderer = this.inject(TestComponentRenderer);
|
2445 | try {
|
2446 | this._moduleRef.destroy();
|
2447 | }
|
2448 | catch (e) {
|
2449 | if ((_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.rethrowErrors) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.rethrowErrors) !== null && _d !== void 0 ? _d : true) {
|
2450 | throw e;
|
2451 | }
|
2452 | else {
|
2453 | console.error('Error during cleanup of a testing module', {
|
2454 | component: this._moduleRef.instance,
|
2455 | stacktrace: e,
|
2456 | });
|
2457 | }
|
2458 | }
|
2459 | finally {
|
2460 | (_e = testRenderer === null || testRenderer === void 0 ? void 0 : testRenderer.removeAllRootElements) === null || _e === void 0 ? void 0 : _e.call(testRenderer);
|
2461 | }
|
2462 | }
|
2463 | }
|
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 | const TestBed = ɵivyEnabled ? TestBedRender3 : TestBedViewEngine;
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 | const getTestBed = ɵivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
|
2485 | let testBed;
|
2486 | function _getTestBedViewEngine() {
|
2487 | return testBed = testBed || new TestBedViewEngine();
|
2488 | }
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 |
|
2508 | function inject(tokens, fn) {
|
2509 | const testBed = getTestBed();
|
2510 |
|
2511 | return function () {
|
2512 | return testBed.execute(tokens, fn, this);
|
2513 | };
|
2514 | }
|
2515 |
|
2516 |
|
2517 |
|
2518 | class InjectSetupWrapper {
|
2519 | constructor(_moduleDef) {
|
2520 | this._moduleDef = _moduleDef;
|
2521 | }
|
2522 | _addModule() {
|
2523 | const moduleDef = this._moduleDef();
|
2524 | if (moduleDef) {
|
2525 | getTestBed().configureTestingModule(moduleDef);
|
2526 | }
|
2527 | }
|
2528 | inject(tokens, fn) {
|
2529 | const self = this;
|
2530 |
|
2531 | return function () {
|
2532 | self._addModule();
|
2533 | return inject(tokens, fn).call(this);
|
2534 | };
|
2535 | }
|
2536 | }
|
2537 | function withModule(moduleDef, fn) {
|
2538 | if (fn) {
|
2539 |
|
2540 | return function () {
|
2541 | const testBed = getTestBed();
|
2542 | if (moduleDef) {
|
2543 | testBed.configureTestingModule(moduleDef);
|
2544 | }
|
2545 | return fn.apply(this);
|
2546 | };
|
2547 | }
|
2548 | return new InjectSetupWrapper(() => moduleDef);
|
2549 | }
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 | const _global = (typeof window === 'undefined' ? global : window);
|
2559 |
|
2560 | if (_global.beforeEach) {
|
2561 | _global.beforeEach(getCleanupHook(false));
|
2562 | }
|
2563 |
|
2564 |
|
2565 |
|
2566 | if (_global.afterEach) {
|
2567 | _global.afterEach(getCleanupHook(true));
|
2568 | }
|
2569 | function getCleanupHook(expectedTeardownValue) {
|
2570 | return () => {
|
2571 | if (TestBed.shouldTearDownTestingModule() ===
|
2572 | expectedTeardownValue) {
|
2573 | TestBed.resetTestingModule();
|
2574 | resetFakeAsyncZone();
|
2575 | }
|
2576 | };
|
2577 | }
|
2578 |
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 | const __core_private_testing_placeholder__ = '';
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 | export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, InjectSetupWrapper, TestBed, TestComponentRenderer, __core_private_testing_placeholder__, async, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, MetadataOverrider as ɵMetadataOverrider, TestingCompiler as ɵTestingCompiler, TestingCompilerFactory as ɵTestingCompilerFactory };
|
2627 |
|