UNPKG

10.1 kBJavaScriptView Raw
1/**
2 * @license Angular v9.0.6
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { __extends, __decorate, __param, __metadata } from 'tslib';
8import { Injectable, Inject, ɵstringify, NgModule, Directive, Component, Pipe, createPlatformFactory, COMPILER_OPTIONS, Injector, CompilerFactory } from '@angular/core';
9import { TestComponentRenderer, ɵMetadataOverrider, ɵTestingCompilerFactory } from '@angular/core/testing';
10import { ɵplatformCoreDynamic, ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS } from '@angular/platform-browser-dynamic';
11import { BrowserTestingModule } from '@angular/platform-browser/testing';
12import { ɵgetDOM, DOCUMENT } from '@angular/common';
13import { CompileReflector, PipeResolver, DirectiveResolver, NgModuleResolver, ERROR_COMPONENT_TYPE } from '@angular/compiler';
14import { MockPipeResolver, MockDirectiveResolver, MockNgModuleResolver } from '@angular/compiler/testing';
15
16/**
17 * @license
18 * Copyright Google Inc. All Rights Reserved.
19 *
20 * Use of this source code is governed by an MIT-style license that can be
21 * found in the LICENSE file at https://angular.io/license
22 */
23/**
24 * A DOM based implementation of the TestComponentRenderer.
25 */
26var DOMTestComponentRenderer = /** @class */ (function (_super) {
27 __extends(DOMTestComponentRenderer, _super);
28 function DOMTestComponentRenderer(_doc) {
29 var _this = _super.call(this) || this;
30 _this._doc = _doc;
31 return _this;
32 }
33 DOMTestComponentRenderer.prototype.insertRootElement = function (rootElId) {
34 var template = ɵgetDOM().getDefaultDocument().createElement('template');
35 template.innerHTML = "<div id=\"" + rootElId + "\"></div>";
36 var rootEl = getContent(template).firstChild;
37 // TODO(juliemr): can/should this be optional?
38 var oldRoots = this._doc.querySelectorAll('[id^=root]');
39 for (var i = 0; i < oldRoots.length; i++) {
40 ɵgetDOM().remove(oldRoots[i]);
41 }
42 this._doc.body.appendChild(rootEl);
43 };
44 DOMTestComponentRenderer = __decorate([
45 Injectable(),
46 __param(0, Inject(DOCUMENT)),
47 __metadata("design:paramtypes", [Object])
48 ], DOMTestComponentRenderer);
49 return DOMTestComponentRenderer;
50}(TestComponentRenderer));
51function getContent(node) {
52 if ('content' in node) {
53 return node.content;
54 }
55 else {
56 return node;
57 }
58}
59
60/**
61 * @license
62 * Copyright Google Inc. All Rights Reserved.
63 *
64 * Use of this source code is governed by an MIT-style license that can be
65 * found in the LICENSE file at https://angular.io/license
66 */
67
68/**
69 * @license
70 * Copyright Google Inc. All Rights Reserved.
71 *
72 * Use of this source code is governed by an MIT-style license that can be
73 * found in the LICENSE file at https://angular.io/license
74 */
75var COMPILER_PROVIDERS = [
76 { provide: MockPipeResolver, deps: [CompileReflector] },
77 { provide: PipeResolver, useExisting: MockPipeResolver },
78 { provide: MockDirectiveResolver, deps: [CompileReflector] },
79 { provide: DirectiveResolver, useExisting: MockDirectiveResolver },
80 { provide: MockNgModuleResolver, deps: [CompileReflector] },
81 { provide: NgModuleResolver, useExisting: MockNgModuleResolver },
82];
83var TestingCompilerFactoryImpl = /** @class */ (function () {
84 function TestingCompilerFactoryImpl(_injector, _compilerFactory) {
85 this._injector = _injector;
86 this._compilerFactory = _compilerFactory;
87 }
88 TestingCompilerFactoryImpl.prototype.createTestingCompiler = function (options) {
89 var compiler = this._compilerFactory.createCompiler(options);
90 return new TestingCompilerImpl(compiler, compiler.injector.get(MockDirectiveResolver), compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
91 };
92 return TestingCompilerFactoryImpl;
93}());
94var TestingCompilerImpl = /** @class */ (function () {
95 function TestingCompilerImpl(_compiler, _directiveResolver, _pipeResolver, _moduleResolver) {
96 this._compiler = _compiler;
97 this._directiveResolver = _directiveResolver;
98 this._pipeResolver = _pipeResolver;
99 this._moduleResolver = _moduleResolver;
100 this._overrider = new ɵMetadataOverrider();
101 }
102 Object.defineProperty(TestingCompilerImpl.prototype, "injector", {
103 get: function () { return this._compiler.injector; },
104 enumerable: true,
105 configurable: true
106 });
107 TestingCompilerImpl.prototype.compileModuleSync = function (moduleType) {
108 return this._compiler.compileModuleSync(moduleType);
109 };
110 TestingCompilerImpl.prototype.compileModuleAsync = function (moduleType) {
111 return this._compiler.compileModuleAsync(moduleType);
112 };
113 TestingCompilerImpl.prototype.compileModuleAndAllComponentsSync = function (moduleType) {
114 return this._compiler.compileModuleAndAllComponentsSync(moduleType);
115 };
116 TestingCompilerImpl.prototype.compileModuleAndAllComponentsAsync = function (moduleType) {
117 return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
118 };
119 TestingCompilerImpl.prototype.getComponentFactory = function (component) {
120 return this._compiler.getComponentFactory(component);
121 };
122 TestingCompilerImpl.prototype.checkOverrideAllowed = function (type) {
123 if (this._compiler.hasAotSummary(type)) {
124 throw new Error(ɵstringify(type) + " was AOT compiled, so its metadata cannot be changed.");
125 }
126 };
127 TestingCompilerImpl.prototype.overrideModule = function (ngModule, override) {
128 this.checkOverrideAllowed(ngModule);
129 var oldMetadata = this._moduleResolver.resolve(ngModule, false);
130 this._moduleResolver.setNgModule(ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
131 this.clearCacheFor(ngModule);
132 };
133 TestingCompilerImpl.prototype.overrideDirective = function (directive, override) {
134 this.checkOverrideAllowed(directive);
135 var oldMetadata = this._directiveResolver.resolve(directive, false);
136 this._directiveResolver.setDirective(directive, this._overrider.overrideMetadata(Directive, oldMetadata, override));
137 this.clearCacheFor(directive);
138 };
139 TestingCompilerImpl.prototype.overrideComponent = function (component, override) {
140 this.checkOverrideAllowed(component);
141 var oldMetadata = this._directiveResolver.resolve(component, false);
142 this._directiveResolver.setDirective(component, this._overrider.overrideMetadata(Component, oldMetadata, override));
143 this.clearCacheFor(component);
144 };
145 TestingCompilerImpl.prototype.overridePipe = function (pipe, override) {
146 this.checkOverrideAllowed(pipe);
147 var oldMetadata = this._pipeResolver.resolve(pipe, false);
148 this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override));
149 this.clearCacheFor(pipe);
150 };
151 TestingCompilerImpl.prototype.loadAotSummaries = function (summaries) { this._compiler.loadAotSummaries(summaries); };
152 TestingCompilerImpl.prototype.clearCache = function () { this._compiler.clearCache(); };
153 TestingCompilerImpl.prototype.clearCacheFor = function (type) { this._compiler.clearCacheFor(type); };
154 TestingCompilerImpl.prototype.getComponentFromError = function (error) { return error[ERROR_COMPONENT_TYPE] || null; };
155 TestingCompilerImpl.prototype.getModuleId = function (moduleType) {
156 return this._moduleResolver.resolve(moduleType, true).id;
157 };
158 return TestingCompilerImpl;
159}());
160
161/**
162 * @license
163 * Copyright Google Inc. All Rights Reserved.
164 *
165 * Use of this source code is governed by an MIT-style license that can be
166 * found in the LICENSE file at https://angular.io/license
167 */
168var ɵ0 = { providers: COMPILER_PROVIDERS };
169/**
170 * Platform for dynamic tests
171 *
172 * @publicApi
173 */
174var platformCoreDynamicTesting = createPlatformFactory(ɵplatformCoreDynamic, 'coreDynamicTesting', [
175 { provide: COMPILER_OPTIONS, useValue: ɵ0, multi: true }, {
176 provide: ɵTestingCompilerFactory,
177 useClass: TestingCompilerFactoryImpl,
178 deps: [Injector, CompilerFactory]
179 }
180]);
181
182/**
183 * @license
184 * Copyright Google Inc. All Rights Reserved.
185 *
186 * Use of this source code is governed by an MIT-style license that can be
187 * found in the LICENSE file at https://angular.io/license
188 */
189
190/**
191 * @license
192 * Copyright Google Inc. All Rights Reserved.
193 *
194 * Use of this source code is governed by an MIT-style license that can be
195 * found in the LICENSE file at https://angular.io/license
196 */
197/**
198 * @publicApi
199 */
200var platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
201/**
202 * NgModule for testing.
203 *
204 * @publicApi
205 */
206var BrowserDynamicTestingModule = /** @class */ (function () {
207 function BrowserDynamicTestingModule() {
208 }
209 BrowserDynamicTestingModule = __decorate([
210 NgModule({
211 exports: [BrowserTestingModule],
212 providers: [
213 { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
214 ]
215 })
216 ], BrowserDynamicTestingModule);
217 return BrowserDynamicTestingModule;
218}());
219
220/**
221 * @license
222 * Copyright Google Inc. All Rights Reserved.
223 *
224 * Use of this source code is governed by an MIT-style license that can be
225 * found in the LICENSE file at https://angular.io/license
226 */
227
228/**
229 * @license
230 * Copyright Google Inc. All Rights Reserved.
231 *
232 * Use of this source code is governed by an MIT-style license that can be
233 * found in the LICENSE file at https://angular.io/license
234 */
235
236/**
237 * Generated bundle index. Do not edit.
238 */
239
240export { BrowserDynamicTestingModule, platformBrowserDynamicTesting, DOMTestComponentRenderer as ɵDOMTestComponentRenderer, COMPILER_PROVIDERS as ɵangular_packages_platform_browser_dynamic_testing_testing_a, TestingCompilerFactoryImpl as ɵangular_packages_platform_browser_dynamic_testing_testing_b, platformCoreDynamicTesting as ɵplatformCoreDynamicTesting };
241//# sourceMappingURL=testing.js.map