1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { __extends, __decorate, __param, __metadata } from 'tslib';
|
8 | import { Injectable, Inject, ɵstringify, NgModule, Directive, Component, Pipe, createPlatformFactory, COMPILER_OPTIONS, Injector, CompilerFactory } from '@angular/core';
|
9 | import { TestComponentRenderer, ɵMetadataOverrider, ɵTestingCompilerFactory } from '@angular/core/testing';
|
10 | import { ɵplatformCoreDynamic, ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS } from '@angular/platform-browser-dynamic';
|
11 | import { BrowserTestingModule } from '@angular/platform-browser/testing';
|
12 | import { ɵgetDOM, DOCUMENT } from '@angular/common';
|
13 | import { CompileReflector, PipeResolver, DirectiveResolver, NgModuleResolver, ERROR_COMPONENT_TYPE } from '@angular/compiler';
|
14 | import { MockPipeResolver, MockDirectiveResolver, MockNgModuleResolver } from '@angular/compiler/testing';
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | var DOMTestComponentRenderer = (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 |
|
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));
|
51 | function getContent(node) {
|
52 | if ('content' in node) {
|
53 | return node.content;
|
54 | }
|
55 | else {
|
56 | return node;
|
57 | }
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | var 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 | ];
|
83 | var TestingCompilerFactoryImpl = (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 | }());
|
94 | var TestingCompilerImpl = (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 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | var ɵ0 = { providers: COMPILER_PROVIDERS };
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | var 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 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | var platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | var BrowserDynamicTestingModule = (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 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | export { 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 |
|