| /** |
| * @license Angular v5.2.0 |
| * (c) 2010-2018 Google, Inc. https://angular.io/ |
| * License: MIT |
| */ |
| import { COMPILER_OPTIONS, CompilerFactory, Component, Directive, Inject, Injectable, Injector, NgModule, Pipe, createPlatformFactory, ɵstringify } from '@angular/core'; |
| import { TestComponentRenderer, ɵTestingCompilerFactory } from '@angular/core/testing'; |
| import { ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ɵplatformCoreDynamic } from '@angular/platform-browser-dynamic'; |
| import { BrowserTestingModule } from '@angular/platform-browser/testing'; |
| import { DOCUMENT, ɵgetDOM } from '@angular/platform-browser'; |
| import { CompileReflector, DirectiveResolver, ERROR_COMPONENT_TYPE, NgModuleResolver, PipeResolver } from '@angular/compiler'; |
| import { MockDirectiveResolver, MockNgModuleResolver, MockPipeResolver } from '@angular/compiler/testing'; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| /** |
| * A DOM based implementation of the TestComponentRenderer. |
| */ |
| class DOMTestComponentRenderer extends TestComponentRenderer { |
| /** |
| * @param {?} _doc |
| */ |
| constructor(_doc /** TODO #9100 */) { |
| super(); |
| this._doc = _doc; |
| } |
| /** |
| * @param {?} rootElId |
| * @return {?} |
| */ |
| insertRootElement(rootElId) { |
| const /** @type {?} */ rootEl = /** @type {?} */ (ɵgetDOM().firstChild(ɵgetDOM().content(ɵgetDOM().createTemplate(`<div id="${rootElId}"></div>`)))); |
| // TODO(juliemr): can/should this be optional? |
| const /** @type {?} */ oldRoots = ɵgetDOM().querySelectorAll(this._doc, '[id^=root]'); |
| for (let /** @type {?} */ i = 0; i < oldRoots.length; i++) { |
| ɵgetDOM().remove(oldRoots[i]); |
| } |
| ɵgetDOM().appendChild(this._doc.body, rootEl); |
| } |
| } |
| DOMTestComponentRenderer.decorators = [ |
| { type: Injectable }, |
| ]; |
| /** @nocollapse */ |
| DOMTestComponentRenderer.ctorParameters = () => [ |
| { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] },] }, |
| ]; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| let _nextReferenceId = 0; |
| class MetadataOverrider { |
| constructor() { |
| this._references = new Map(); |
| } |
| /** |
| * Creates a new instance for the given metadata class |
| * based on an old instance and overrides. |
| * @template C, T |
| * @param {?} metadataClass |
| * @param {?} oldMetadata |
| * @param {?} override |
| * @return {?} |
| */ |
| overrideMetadata(metadataClass, oldMetadata, override) { |
| const /** @type {?} */ props = {}; |
| if (oldMetadata) { |
| _valueProps(oldMetadata).forEach((prop) => props[prop] = (/** @type {?} */ (oldMetadata))[prop]); |
| } |
| if (override.set) { |
| if (override.remove || override.add) { |
| throw new Error(`Cannot set and add/remove ${ɵstringify(metadataClass)} at the same time!`); |
| } |
| setMetadata(props, override.set); |
| } |
| if (override.remove) { |
| removeMetadata(props, override.remove, this._references); |
| } |
| if (override.add) { |
| addMetadata(props, override.add); |
| } |
| return new metadataClass(/** @type {?} */ (props)); |
| } |
| } |
| /** |
| * @param {?} metadata |
| * @param {?} remove |
| * @param {?} references |
| * @return {?} |
| */ |
| function removeMetadata(metadata, remove, references) { |
| const /** @type {?} */ removeObjects = new Set(); |
| for (const /** @type {?} */ prop in remove) { |
| const /** @type {?} */ removeValue = remove[prop]; |
| if (removeValue instanceof Array) { |
| removeValue.forEach((value) => { removeObjects.add(_propHashKey(prop, value, references)); }); |
| } |
| else { |
| removeObjects.add(_propHashKey(prop, removeValue, references)); |
| } |
| } |
| for (const /** @type {?} */ prop in metadata) { |
| const /** @type {?} */ propValue = metadata[prop]; |
| if (propValue instanceof Array) { |
| metadata[prop] = propValue.filter((value) => !removeObjects.has(_propHashKey(prop, value, references))); |
| } |
| else { |
| if (removeObjects.has(_propHashKey(prop, propValue, references))) { |
| metadata[prop] = undefined; |
| } |
| } |
| } |
| } |
| /** |
| * @param {?} metadata |
| * @param {?} add |
| * @return {?} |
| */ |
| function addMetadata(metadata, add) { |
| for (const /** @type {?} */ prop in add) { |
| const /** @type {?} */ addValue = add[prop]; |
| const /** @type {?} */ propValue = metadata[prop]; |
| if (propValue != null && propValue instanceof Array) { |
| metadata[prop] = propValue.concat(addValue); |
| } |
| else { |
| metadata[prop] = addValue; |
| } |
| } |
| } |
| /** |
| * @param {?} metadata |
| * @param {?} set |
| * @return {?} |
| */ |
| function setMetadata(metadata, set) { |
| for (const /** @type {?} */ prop in set) { |
| metadata[prop] = set[prop]; |
| } |
| } |
| /** |
| * @param {?} propName |
| * @param {?} propValue |
| * @param {?} references |
| * @return {?} |
| */ |
| function _propHashKey(propName, propValue, references) { |
| const /** @type {?} */ replacer = (key, value) => { |
| if (typeof value === 'function') { |
| value = _serializeReference(value, references); |
| } |
| return value; |
| }; |
| return `${propName}:${JSON.stringify(propValue, replacer)}`; |
| } |
| /** |
| * @param {?} ref |
| * @param {?} references |
| * @return {?} |
| */ |
| function _serializeReference(ref, references) { |
| let /** @type {?} */ id = references.get(ref); |
| if (!id) { |
| id = `${ɵstringify(ref)}${_nextReferenceId++}`; |
| references.set(ref, id); |
| } |
| return id; |
| } |
| /** |
| * @param {?} obj |
| * @return {?} |
| */ |
| function _valueProps(obj) { |
| const /** @type {?} */ props = []; |
| // regular public props |
| Object.keys(obj).forEach((prop) => { |
| if (!prop.startsWith('_')) { |
| props.push(prop); |
| } |
| }); |
| // getters |
| let /** @type {?} */ proto = obj; |
| while (proto = Object.getPrototypeOf(proto)) { |
| Object.keys(proto).forEach((protoProp) => { |
| const /** @type {?} */ desc = Object.getOwnPropertyDescriptor(proto, protoProp); |
| if (!protoProp.startsWith('_') && desc && 'get' in desc) { |
| props.push(protoProp); |
| } |
| }); |
| } |
| return props; |
| } |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| const COMPILER_PROVIDERS = [ |
| { provide: MockPipeResolver, deps: [CompileReflector] }, |
| { provide: PipeResolver, useExisting: MockPipeResolver }, |
| { provide: MockDirectiveResolver, deps: [CompileReflector] }, |
| { provide: DirectiveResolver, useExisting: MockDirectiveResolver }, |
| { provide: MockNgModuleResolver, deps: [CompileReflector] }, |
| { provide: NgModuleResolver, useExisting: MockNgModuleResolver }, |
| ]; |
| class TestingCompilerFactoryImpl { |
| /** |
| * @param {?} _injector |
| * @param {?} _compilerFactory |
| */ |
| constructor(_injector, _compilerFactory) { |
| this._injector = _injector; |
| this._compilerFactory = _compilerFactory; |
| } |
| /** |
| * @param {?} options |
| * @return {?} |
| */ |
| createTestingCompiler(options) { |
| const /** @type {?} */ compiler = /** @type {?} */ (this._compilerFactory.createCompiler(options)); |
| return new TestingCompilerImpl(compiler, compiler.injector.get(MockDirectiveResolver), compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver)); |
| } |
| } |
| class TestingCompilerImpl { |
| /** |
| * @param {?} _compiler |
| * @param {?} _directiveResolver |
| * @param {?} _pipeResolver |
| * @param {?} _moduleResolver |
| */ |
| constructor(_compiler, _directiveResolver, _pipeResolver, _moduleResolver) { |
| this._compiler = _compiler; |
| this._directiveResolver = _directiveResolver; |
| this._pipeResolver = _pipeResolver; |
| this._moduleResolver = _moduleResolver; |
| this._overrider = new MetadataOverrider(); |
| } |
| /** |
| * @return {?} |
| */ |
| get injector() { return this._compiler.injector; } |
| /** |
| * @template T |
| * @param {?} moduleType |
| * @return {?} |
| */ |
| compileModuleSync(moduleType) { |
| return this._compiler.compileModuleSync(moduleType); |
| } |
| /** |
| * @template T |
| * @param {?} moduleType |
| * @return {?} |
| */ |
| compileModuleAsync(moduleType) { |
| return this._compiler.compileModuleAsync(moduleType); |
| } |
| /** |
| * @template T |
| * @param {?} moduleType |
| * @return {?} |
| */ |
| compileModuleAndAllComponentsSync(moduleType) { |
| return this._compiler.compileModuleAndAllComponentsSync(moduleType); |
| } |
| /** |
| * @template T |
| * @param {?} moduleType |
| * @return {?} |
| */ |
| compileModuleAndAllComponentsAsync(moduleType) { |
| return this._compiler.compileModuleAndAllComponentsAsync(moduleType); |
| } |
| /** |
| * @template T |
| * @param {?} component |
| * @return {?} |
| */ |
| getComponentFactory(component) { |
| return this._compiler.getComponentFactory(component); |
| } |
| /** |
| * @param {?} type |
| * @return {?} |
| */ |
| checkOverrideAllowed(type) { |
| if (this._compiler.hasAotSummary(type)) { |
| throw new Error(`${ɵstringify(type)} was AOT compiled, so its metadata cannot be changed.`); |
| } |
| } |
| /** |
| * @param {?} ngModule |
| * @param {?} override |
| * @return {?} |
| */ |
| overrideModule(ngModule, override) { |
| this.checkOverrideAllowed(ngModule); |
| const /** @type {?} */ oldMetadata = this._moduleResolver.resolve(ngModule, false); |
| this._moduleResolver.setNgModule(ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override)); |
| this.clearCacheFor(ngModule); |
| } |
| /** |
| * @param {?} directive |
| * @param {?} override |
| * @return {?} |
| */ |
| overrideDirective(directive, override) { |
| this.checkOverrideAllowed(directive); |
| const /** @type {?} */ oldMetadata = this._directiveResolver.resolve(directive, false); |
| this._directiveResolver.setDirective(directive, this._overrider.overrideMetadata(Directive, /** @type {?} */ ((oldMetadata)), override)); |
| this.clearCacheFor(directive); |
| } |
| /** |
| * @param {?} component |
| * @param {?} override |
| * @return {?} |
| */ |
| overrideComponent(component, override) { |
| this.checkOverrideAllowed(component); |
| const /** @type {?} */ oldMetadata = this._directiveResolver.resolve(component, false); |
| this._directiveResolver.setDirective(component, this._overrider.overrideMetadata(Component, /** @type {?} */ ((oldMetadata)), override)); |
| this.clearCacheFor(component); |
| } |
| /** |
| * @param {?} pipe |
| * @param {?} override |
| * @return {?} |
| */ |
| overridePipe(pipe, override) { |
| this.checkOverrideAllowed(pipe); |
| const /** @type {?} */ oldMetadata = this._pipeResolver.resolve(pipe, false); |
| this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override)); |
| this.clearCacheFor(pipe); |
| } |
| /** |
| * @param {?} summaries |
| * @return {?} |
| */ |
| loadAotSummaries(summaries) { this._compiler.loadAotSummaries(summaries); } |
| /** |
| * @return {?} |
| */ |
| clearCache() { this._compiler.clearCache(); } |
| /** |
| * @param {?} type |
| * @return {?} |
| */ |
| clearCacheFor(type) { this._compiler.clearCacheFor(type); } |
| /** |
| * @param {?} error |
| * @return {?} |
| */ |
| getComponentFromError(error) { return (/** @type {?} */ (error))[ERROR_COMPONENT_TYPE] || null; } |
| } |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| /** |
| * Platform for dynamic tests |
| * |
| * \@experimental |
| */ |
| const platformCoreDynamicTesting = createPlatformFactory(ɵplatformCoreDynamic, 'coreDynamicTesting', [ |
| { provide: COMPILER_OPTIONS, useValue: { providers: COMPILER_PROVIDERS }, multi: true }, { |
| provide: ɵTestingCompilerFactory, |
| useClass: TestingCompilerFactoryImpl, |
| deps: [Injector, CompilerFactory] |
| } |
| ]); |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| /** |
| * \@stable |
| */ |
| const platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS); |
| /** |
| * NgModule for testing. |
| * |
| * \@stable |
| */ |
| class BrowserDynamicTestingModule { |
| } |
| BrowserDynamicTestingModule.decorators = [ |
| { type: NgModule, args: [{ |
| exports: [BrowserTestingModule], |
| providers: [ |
| { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer }, |
| ] |
| },] }, |
| ]; |
| /** @nocollapse */ |
| BrowserDynamicTestingModule.ctorParameters = () => []; |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * @license |
| * Copyright Google Inc. All Rights Reserved. |
| * |
| * Use of this source code is governed by an MIT-style license that can be |
| * found in the LICENSE file at https://angular.io/license |
| */ |
| /** |
| * @module |
| * @description |
| * Entry point for all public APIs of this package. |
| */ |
| |
| /** |
| * @fileoverview added by tsickle |
| * @suppress {checkTypes} checked by tsc |
| */ |
| /** |
| * Generated bundle index. Do not edit. |
| */ |
| |
| export { platformBrowserDynamicTesting, BrowserDynamicTestingModule, DOMTestComponentRenderer as ɵDOMTestComponentRenderer, platformCoreDynamicTesting as ɵplatformCoreDynamicTesting, COMPILER_PROVIDERS as ɵa, TestingCompilerFactoryImpl as ɵb }; |
| //# sourceMappingURL=testing.js.map |