123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { COMPILER_OPTIONS, CompilerFactory, Component, Directive, Inject, Injectable, Injector, NgModule, Pipe, createPlatformFactory, ɵstringify } from '@angular/core';
  7. import { TestComponentRenderer, ɵTestingCompilerFactory } from '@angular/core/testing';
  8. import { ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ɵplatformCoreDynamic } from '@angular/platform-browser-dynamic';
  9. import { BrowserTestingModule } from '@angular/platform-browser/testing';
  10. import { __extends } from 'tslib';
  11. import { DOCUMENT, ɵgetDOM } from '@angular/platform-browser';
  12. import { CompileReflector, DirectiveResolver, ERROR_COMPONENT_TYPE, NgModuleResolver, PipeResolver } from '@angular/compiler';
  13. import { MockDirectiveResolver, MockNgModuleResolver, MockPipeResolver } from '@angular/compiler/testing';
  14. /**
  15. * @fileoverview added by tsickle
  16. * @suppress {checkTypes} checked by tsc
  17. */
  18. /**
  19. * @license
  20. * Copyright Google Inc. All Rights Reserved.
  21. *
  22. * Use of this source code is governed by an MIT-style license that can be
  23. * found in the LICENSE file at https://angular.io/license
  24. */
  25. /**
  26. * A DOM based implementation of the TestComponentRenderer.
  27. */
  28. var DOMTestComponentRenderer = /** @class */ (function (_super) {
  29. __extends(DOMTestComponentRenderer, _super);
  30. function DOMTestComponentRenderer(_doc /** TODO #9100 */) {
  31. var _this = _super.call(this) || this;
  32. _this._doc = _doc;
  33. return _this;
  34. }
  35. /**
  36. * @param {?} rootElId
  37. * @return {?}
  38. */
  39. DOMTestComponentRenderer.prototype.insertRootElement = /**
  40. * @param {?} rootElId
  41. * @return {?}
  42. */
  43. function (rootElId) {
  44. var /** @type {?} */ rootEl = /** @type {?} */ (ɵgetDOM().firstChild(ɵgetDOM().content(ɵgetDOM().createTemplate("<div id=\"" + rootElId + "\"></div>"))));
  45. // TODO(juliemr): can/should this be optional?
  46. var /** @type {?} */ oldRoots = ɵgetDOM().querySelectorAll(this._doc, '[id^=root]');
  47. for (var /** @type {?} */ i = 0; i < oldRoots.length; i++) {
  48. ɵgetDOM().remove(oldRoots[i]);
  49. }
  50. ɵgetDOM().appendChild(this._doc.body, rootEl);
  51. };
  52. DOMTestComponentRenderer.decorators = [
  53. { type: Injectable },
  54. ];
  55. /** @nocollapse */
  56. DOMTestComponentRenderer.ctorParameters = function () { return [
  57. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] },] },
  58. ]; };
  59. return DOMTestComponentRenderer;
  60. }(TestComponentRenderer));
  61. /**
  62. * @fileoverview added by tsickle
  63. * @suppress {checkTypes} checked by tsc
  64. */
  65. /**
  66. * @license
  67. * Copyright Google Inc. All Rights Reserved.
  68. *
  69. * Use of this source code is governed by an MIT-style license that can be
  70. * found in the LICENSE file at https://angular.io/license
  71. */
  72. var _nextReferenceId = 0;
  73. var MetadataOverrider = /** @class */ (function () {
  74. function MetadataOverrider() {
  75. this._references = new Map();
  76. }
  77. /**
  78. * Creates a new instance for the given metadata class
  79. * based on an old instance and overrides.
  80. */
  81. /**
  82. * Creates a new instance for the given metadata class
  83. * based on an old instance and overrides.
  84. * @template C, T
  85. * @param {?} metadataClass
  86. * @param {?} oldMetadata
  87. * @param {?} override
  88. * @return {?}
  89. */
  90. MetadataOverrider.prototype.overrideMetadata = /**
  91. * Creates a new instance for the given metadata class
  92. * based on an old instance and overrides.
  93. * @template C, T
  94. * @param {?} metadataClass
  95. * @param {?} oldMetadata
  96. * @param {?} override
  97. * @return {?}
  98. */
  99. function (metadataClass, oldMetadata, override) {
  100. var /** @type {?} */ props = {};
  101. if (oldMetadata) {
  102. _valueProps(oldMetadata).forEach(function (prop) { return props[prop] = (/** @type {?} */ (oldMetadata))[prop]; });
  103. }
  104. if (override.set) {
  105. if (override.remove || override.add) {
  106. throw new Error("Cannot set and add/remove " + ɵstringify(metadataClass) + " at the same time!");
  107. }
  108. setMetadata(props, override.set);
  109. }
  110. if (override.remove) {
  111. removeMetadata(props, override.remove, this._references);
  112. }
  113. if (override.add) {
  114. addMetadata(props, override.add);
  115. }
  116. return new metadataClass(/** @type {?} */ (props));
  117. };
  118. return MetadataOverrider;
  119. }());
  120. /**
  121. * @param {?} metadata
  122. * @param {?} remove
  123. * @param {?} references
  124. * @return {?}
  125. */
  126. function removeMetadata(metadata, remove, references) {
  127. var /** @type {?} */ removeObjects = new Set();
  128. var _loop_1 = function (prop) {
  129. var /** @type {?} */ removeValue = remove[prop];
  130. if (removeValue instanceof Array) {
  131. removeValue.forEach(function (value) { removeObjects.add(_propHashKey(prop, value, references)); });
  132. }
  133. else {
  134. removeObjects.add(_propHashKey(prop, removeValue, references));
  135. }
  136. };
  137. for (var /** @type {?} */ prop in remove) {
  138. _loop_1(prop);
  139. }
  140. var _loop_2 = function (prop) {
  141. var /** @type {?} */ propValue = metadata[prop];
  142. if (propValue instanceof Array) {
  143. metadata[prop] = propValue.filter(function (value) { return !removeObjects.has(_propHashKey(prop, value, references)); });
  144. }
  145. else {
  146. if (removeObjects.has(_propHashKey(prop, propValue, references))) {
  147. metadata[prop] = undefined;
  148. }
  149. }
  150. };
  151. for (var /** @type {?} */ prop in metadata) {
  152. _loop_2(prop);
  153. }
  154. }
  155. /**
  156. * @param {?} metadata
  157. * @param {?} add
  158. * @return {?}
  159. */
  160. function addMetadata(metadata, add) {
  161. for (var /** @type {?} */ prop in add) {
  162. var /** @type {?} */ addValue = add[prop];
  163. var /** @type {?} */ propValue = metadata[prop];
  164. if (propValue != null && propValue instanceof Array) {
  165. metadata[prop] = propValue.concat(addValue);
  166. }
  167. else {
  168. metadata[prop] = addValue;
  169. }
  170. }
  171. }
  172. /**
  173. * @param {?} metadata
  174. * @param {?} set
  175. * @return {?}
  176. */
  177. function setMetadata(metadata, set) {
  178. for (var /** @type {?} */ prop in set) {
  179. metadata[prop] = set[prop];
  180. }
  181. }
  182. /**
  183. * @param {?} propName
  184. * @param {?} propValue
  185. * @param {?} references
  186. * @return {?}
  187. */
  188. function _propHashKey(propName, propValue, references) {
  189. var /** @type {?} */ replacer = function (key, value) {
  190. if (typeof value === 'function') {
  191. value = _serializeReference(value, references);
  192. }
  193. return value;
  194. };
  195. return propName + ":" + JSON.stringify(propValue, replacer);
  196. }
  197. /**
  198. * @param {?} ref
  199. * @param {?} references
  200. * @return {?}
  201. */
  202. function _serializeReference(ref, references) {
  203. var /** @type {?} */ id = references.get(ref);
  204. if (!id) {
  205. id = "" + ɵstringify(ref) + _nextReferenceId++;
  206. references.set(ref, id);
  207. }
  208. return id;
  209. }
  210. /**
  211. * @param {?} obj
  212. * @return {?}
  213. */
  214. function _valueProps(obj) {
  215. var /** @type {?} */ props = [];
  216. // regular public props
  217. Object.keys(obj).forEach(function (prop) {
  218. if (!prop.startsWith('_')) {
  219. props.push(prop);
  220. }
  221. });
  222. // getters
  223. var /** @type {?} */ proto = obj;
  224. while (proto = Object.getPrototypeOf(proto)) {
  225. Object.keys(proto).forEach(function (protoProp) {
  226. var /** @type {?} */ desc = Object.getOwnPropertyDescriptor(proto, protoProp);
  227. if (!protoProp.startsWith('_') && desc && 'get' in desc) {
  228. props.push(protoProp);
  229. }
  230. });
  231. }
  232. return props;
  233. }
  234. /**
  235. * @fileoverview added by tsickle
  236. * @suppress {checkTypes} checked by tsc
  237. */
  238. /**
  239. * @license
  240. * Copyright Google Inc. All Rights Reserved.
  241. *
  242. * Use of this source code is governed by an MIT-style license that can be
  243. * found in the LICENSE file at https://angular.io/license
  244. */
  245. var COMPILER_PROVIDERS = [
  246. { provide: MockPipeResolver, deps: [CompileReflector] },
  247. { provide: PipeResolver, useExisting: MockPipeResolver },
  248. { provide: MockDirectiveResolver, deps: [CompileReflector] },
  249. { provide: DirectiveResolver, useExisting: MockDirectiveResolver },
  250. { provide: MockNgModuleResolver, deps: [CompileReflector] },
  251. { provide: NgModuleResolver, useExisting: MockNgModuleResolver },
  252. ];
  253. var TestingCompilerFactoryImpl = /** @class */ (function () {
  254. function TestingCompilerFactoryImpl(_injector, _compilerFactory) {
  255. this._injector = _injector;
  256. this._compilerFactory = _compilerFactory;
  257. }
  258. /**
  259. * @param {?} options
  260. * @return {?}
  261. */
  262. TestingCompilerFactoryImpl.prototype.createTestingCompiler = /**
  263. * @param {?} options
  264. * @return {?}
  265. */
  266. function (options) {
  267. var /** @type {?} */ compiler = /** @type {?} */ (this._compilerFactory.createCompiler(options));
  268. return new TestingCompilerImpl(compiler, compiler.injector.get(MockDirectiveResolver), compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
  269. };
  270. return TestingCompilerFactoryImpl;
  271. }());
  272. var TestingCompilerImpl = /** @class */ (function () {
  273. function TestingCompilerImpl(_compiler, _directiveResolver, _pipeResolver, _moduleResolver) {
  274. this._compiler = _compiler;
  275. this._directiveResolver = _directiveResolver;
  276. this._pipeResolver = _pipeResolver;
  277. this._moduleResolver = _moduleResolver;
  278. this._overrider = new MetadataOverrider();
  279. }
  280. Object.defineProperty(TestingCompilerImpl.prototype, "injector", {
  281. get: /**
  282. * @return {?}
  283. */
  284. function () { return this._compiler.injector; },
  285. enumerable: true,
  286. configurable: true
  287. });
  288. /**
  289. * @template T
  290. * @param {?} moduleType
  291. * @return {?}
  292. */
  293. TestingCompilerImpl.prototype.compileModuleSync = /**
  294. * @template T
  295. * @param {?} moduleType
  296. * @return {?}
  297. */
  298. function (moduleType) {
  299. return this._compiler.compileModuleSync(moduleType);
  300. };
  301. /**
  302. * @template T
  303. * @param {?} moduleType
  304. * @return {?}
  305. */
  306. TestingCompilerImpl.prototype.compileModuleAsync = /**
  307. * @template T
  308. * @param {?} moduleType
  309. * @return {?}
  310. */
  311. function (moduleType) {
  312. return this._compiler.compileModuleAsync(moduleType);
  313. };
  314. /**
  315. * @template T
  316. * @param {?} moduleType
  317. * @return {?}
  318. */
  319. TestingCompilerImpl.prototype.compileModuleAndAllComponentsSync = /**
  320. * @template T
  321. * @param {?} moduleType
  322. * @return {?}
  323. */
  324. function (moduleType) {
  325. return this._compiler.compileModuleAndAllComponentsSync(moduleType);
  326. };
  327. /**
  328. * @template T
  329. * @param {?} moduleType
  330. * @return {?}
  331. */
  332. TestingCompilerImpl.prototype.compileModuleAndAllComponentsAsync = /**
  333. * @template T
  334. * @param {?} moduleType
  335. * @return {?}
  336. */
  337. function (moduleType) {
  338. return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
  339. };
  340. /**
  341. * @template T
  342. * @param {?} component
  343. * @return {?}
  344. */
  345. TestingCompilerImpl.prototype.getComponentFactory = /**
  346. * @template T
  347. * @param {?} component
  348. * @return {?}
  349. */
  350. function (component) {
  351. return this._compiler.getComponentFactory(component);
  352. };
  353. /**
  354. * @param {?} type
  355. * @return {?}
  356. */
  357. TestingCompilerImpl.prototype.checkOverrideAllowed = /**
  358. * @param {?} type
  359. * @return {?}
  360. */
  361. function (type) {
  362. if (this._compiler.hasAotSummary(type)) {
  363. throw new Error(ɵstringify(type) + " was AOT compiled, so its metadata cannot be changed.");
  364. }
  365. };
  366. /**
  367. * @param {?} ngModule
  368. * @param {?} override
  369. * @return {?}
  370. */
  371. TestingCompilerImpl.prototype.overrideModule = /**
  372. * @param {?} ngModule
  373. * @param {?} override
  374. * @return {?}
  375. */
  376. function (ngModule, override) {
  377. this.checkOverrideAllowed(ngModule);
  378. var /** @type {?} */ oldMetadata = this._moduleResolver.resolve(ngModule, false);
  379. this._moduleResolver.setNgModule(ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
  380. this.clearCacheFor(ngModule);
  381. };
  382. /**
  383. * @param {?} directive
  384. * @param {?} override
  385. * @return {?}
  386. */
  387. TestingCompilerImpl.prototype.overrideDirective = /**
  388. * @param {?} directive
  389. * @param {?} override
  390. * @return {?}
  391. */
  392. function (directive, override) {
  393. this.checkOverrideAllowed(directive);
  394. var /** @type {?} */ oldMetadata = this._directiveResolver.resolve(directive, false);
  395. this._directiveResolver.setDirective(directive, this._overrider.overrideMetadata(Directive, /** @type {?} */ ((oldMetadata)), override));
  396. this.clearCacheFor(directive);
  397. };
  398. /**
  399. * @param {?} component
  400. * @param {?} override
  401. * @return {?}
  402. */
  403. TestingCompilerImpl.prototype.overrideComponent = /**
  404. * @param {?} component
  405. * @param {?} override
  406. * @return {?}
  407. */
  408. function (component, override) {
  409. this.checkOverrideAllowed(component);
  410. var /** @type {?} */ oldMetadata = this._directiveResolver.resolve(component, false);
  411. this._directiveResolver.setDirective(component, this._overrider.overrideMetadata(Component, /** @type {?} */ ((oldMetadata)), override));
  412. this.clearCacheFor(component);
  413. };
  414. /**
  415. * @param {?} pipe
  416. * @param {?} override
  417. * @return {?}
  418. */
  419. TestingCompilerImpl.prototype.overridePipe = /**
  420. * @param {?} pipe
  421. * @param {?} override
  422. * @return {?}
  423. */
  424. function (pipe, override) {
  425. this.checkOverrideAllowed(pipe);
  426. var /** @type {?} */ oldMetadata = this._pipeResolver.resolve(pipe, false);
  427. this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override));
  428. this.clearCacheFor(pipe);
  429. };
  430. /**
  431. * @param {?} summaries
  432. * @return {?}
  433. */
  434. TestingCompilerImpl.prototype.loadAotSummaries = /**
  435. * @param {?} summaries
  436. * @return {?}
  437. */
  438. function (summaries) { this._compiler.loadAotSummaries(summaries); };
  439. /**
  440. * @return {?}
  441. */
  442. TestingCompilerImpl.prototype.clearCache = /**
  443. * @return {?}
  444. */
  445. function () { this._compiler.clearCache(); };
  446. /**
  447. * @param {?} type
  448. * @return {?}
  449. */
  450. TestingCompilerImpl.prototype.clearCacheFor = /**
  451. * @param {?} type
  452. * @return {?}
  453. */
  454. function (type) { this._compiler.clearCacheFor(type); };
  455. /**
  456. * @param {?} error
  457. * @return {?}
  458. */
  459. TestingCompilerImpl.prototype.getComponentFromError = /**
  460. * @param {?} error
  461. * @return {?}
  462. */
  463. function (error) { return (/** @type {?} */ (error))[ERROR_COMPONENT_TYPE] || null; };
  464. return TestingCompilerImpl;
  465. }());
  466. /**
  467. * @fileoverview added by tsickle
  468. * @suppress {checkTypes} checked by tsc
  469. */
  470. /**
  471. * @license
  472. * Copyright Google Inc. All Rights Reserved.
  473. *
  474. * Use of this source code is governed by an MIT-style license that can be
  475. * found in the LICENSE file at https://angular.io/license
  476. */
  477. /**
  478. * Platform for dynamic tests
  479. *
  480. * \@experimental
  481. */
  482. var platformCoreDynamicTesting = createPlatformFactory(ɵplatformCoreDynamic, 'coreDynamicTesting', [
  483. { provide: COMPILER_OPTIONS, useValue: { providers: COMPILER_PROVIDERS }, multi: true }, {
  484. provide: ɵTestingCompilerFactory,
  485. useClass: TestingCompilerFactoryImpl,
  486. deps: [Injector, CompilerFactory]
  487. }
  488. ]);
  489. /**
  490. * @fileoverview added by tsickle
  491. * @suppress {checkTypes} checked by tsc
  492. */
  493. /**
  494. * @license
  495. * Copyright Google Inc. All Rights Reserved.
  496. *
  497. * Use of this source code is governed by an MIT-style license that can be
  498. * found in the LICENSE file at https://angular.io/license
  499. */
  500. /**
  501. * @fileoverview added by tsickle
  502. * @suppress {checkTypes} checked by tsc
  503. */
  504. /**
  505. * @license
  506. * Copyright Google Inc. All Rights Reserved.
  507. *
  508. * Use of this source code is governed by an MIT-style license that can be
  509. * found in the LICENSE file at https://angular.io/license
  510. */
  511. /**
  512. * \@stable
  513. */
  514. var platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
  515. /**
  516. * NgModule for testing.
  517. *
  518. * \@stable
  519. */
  520. var BrowserDynamicTestingModule = /** @class */ (function () {
  521. function BrowserDynamicTestingModule() {
  522. }
  523. BrowserDynamicTestingModule.decorators = [
  524. { type: NgModule, args: [{
  525. exports: [BrowserTestingModule],
  526. providers: [
  527. { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
  528. ]
  529. },] },
  530. ];
  531. /** @nocollapse */
  532. BrowserDynamicTestingModule.ctorParameters = function () { return []; };
  533. return BrowserDynamicTestingModule;
  534. }());
  535. /**
  536. * @fileoverview added by tsickle
  537. * @suppress {checkTypes} checked by tsc
  538. */
  539. /**
  540. * @license
  541. * Copyright Google Inc. All Rights Reserved.
  542. *
  543. * Use of this source code is governed by an MIT-style license that can be
  544. * found in the LICENSE file at https://angular.io/license
  545. */
  546. /**
  547. * @module
  548. * @description
  549. * Entry point for all public APIs of this package.
  550. */
  551. /**
  552. * @fileoverview added by tsickle
  553. * @suppress {checkTypes} checked by tsc
  554. */
  555. /**
  556. * Generated bundle index. Do not edit.
  557. */
  558. export { platformBrowserDynamicTesting, BrowserDynamicTestingModule, DOMTestComponentRenderer as ɵDOMTestComponentRenderer, platformCoreDynamicTesting as ɵplatformCoreDynamicTesting, COMPILER_PROVIDERS as ɵa, TestingCompilerFactoryImpl as ɵb };
  559. //# sourceMappingURL=testing.js.map