| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- /**
- * @license Angular v5.2.11
- * (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
|