testing.js 9.8 KB

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