You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

247 lines
9.8 KiB

/**
* @license Angular v12.2.16
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
import { Injectable, Inject, ɵstringify, NgModule, Directive, Component, Pipe, createPlatformFactory, COMPILER_OPTIONS, Injector, CompilerFactory } from '@angular/core';
import { TestComponentRenderer, ɵMetadataOverrider, ɵTestingCompilerFactory } from '@angular/core/testing';
import { ɵplatformCoreDynamic, ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS } from '@angular/platform-browser-dynamic';
import { BrowserTestingModule } from '@angular/platform-browser/testing';
import { ɵgetDOM, DOCUMENT } from '@angular/common';
import { CompileReflector, PipeResolver, DirectiveResolver, NgModuleResolver, ERROR_COMPONENT_TYPE } from '@angular/compiler';
import { MockPipeResolver, MockDirectiveResolver, MockNgModuleResolver } from '@angular/compiler/testing';
/**
* @license
* Copyright Google LLC 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.
*/
import * as ɵngcc0 from '@angular/core';
class DOMTestComponentRenderer extends TestComponentRenderer {
constructor(_doc) {
super();
this._doc = _doc;
}
insertRootElement(rootElId) {
this.removeAllRootElements();
const rootElement = ɵgetDOM().getDefaultDocument().createElement('div');
rootElement.setAttribute('id', rootElId);
this._doc.body.appendChild(rootElement);
}
removeAllRootElements() {
// TODO(juliemr): can/should this be optional?
const oldRoots = this._doc.querySelectorAll('[id^=root]');
for (let i = 0; i < oldRoots.length; i++) {
ɵgetDOM().remove(oldRoots[i]);
}
}
}
DOMTestComponentRenderer.ɵfac = function DOMTestComponentRenderer_Factory(t) { return new (t || DOMTestComponentRenderer)(ɵngcc0.ɵɵinject(DOCUMENT)); };
DOMTestComponentRenderer.ɵprov = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjectable({ token: DOMTestComponentRenderer, factory: DOMTestComponentRenderer.ɵfac });
DOMTestComponentRenderer.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
];
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(DOMTestComponentRenderer, [{
type: Injectable
}], function () { return [{ type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }]; }, null); })();
/**
* @license
* Copyright Google LLC 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
*/
/**
* @license
* Copyright Google LLC 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 {
constructor(_injector, _compilerFactory) {
this._injector = _injector;
this._compilerFactory = _compilerFactory;
}
createTestingCompiler(options) {
const compiler = this._compilerFactory.createCompiler(options);
return new TestingCompilerImpl(compiler, compiler.injector.get(MockDirectiveResolver), compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
}
}
class TestingCompilerImpl {
constructor(_compiler, _directiveResolver, _pipeResolver, _moduleResolver) {
this._compiler = _compiler;
this._directiveResolver = _directiveResolver;
this._pipeResolver = _pipeResolver;
this._moduleResolver = _moduleResolver;
this._overrider = new ɵMetadataOverrider();
}
get injector() {
return this._compiler.injector;
}
compileModuleSync(moduleType) {
return this._compiler.compileModuleSync(moduleType);
}
compileModuleAsync(moduleType) {
return this._compiler.compileModuleAsync(moduleType);
}
compileModuleAndAllComponentsSync(moduleType) {
return this._compiler.compileModuleAndAllComponentsSync(moduleType);
}
compileModuleAndAllComponentsAsync(moduleType) {
return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
}
getComponentFactory(component) {
return this._compiler.getComponentFactory(component);
}
checkOverrideAllowed(type) {
if (this._compiler.hasAotSummary(type)) {
throw new Error(`${ɵstringify(type)} was AOT compiled, so its metadata cannot be changed.`);
}
}
overrideModule(ngModule, override) {
this.checkOverrideAllowed(ngModule);
const oldMetadata = this._moduleResolver.resolve(ngModule, false);
this._moduleResolver.setNgModule(ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
this.clearCacheFor(ngModule);
}
overrideDirective(directive, override) {
this.checkOverrideAllowed(directive);
const oldMetadata = this._directiveResolver.resolve(directive, false);
this._directiveResolver.setDirective(directive, this._overrider.overrideMetadata(Directive, oldMetadata, override));
this.clearCacheFor(directive);
}
overrideComponent(component, override) {
this.checkOverrideAllowed(component);
const oldMetadata = this._directiveResolver.resolve(component, false);
this._directiveResolver.setDirective(component, this._overrider.overrideMetadata(Component, oldMetadata, override));
this.clearCacheFor(component);
}
overridePipe(pipe, override) {
this.checkOverrideAllowed(pipe);
const oldMetadata = this._pipeResolver.resolve(pipe, false);
this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override));
this.clearCacheFor(pipe);
}
loadAotSummaries(summaries) {
this._compiler.loadAotSummaries(summaries);
}
clearCache() {
this._compiler.clearCache();
}
clearCacheFor(type) {
this._compiler.clearCacheFor(type);
}
getComponentFromError(error) {
return error[ERROR_COMPONENT_TYPE] || null;
}
getModuleId(moduleType) {
return this._moduleResolver.resolve(moduleType, true).id;
}
}
/**
* @license
* Copyright Google LLC 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 ɵ0 = { providers: COMPILER_PROVIDERS };
/**
* Platform for dynamic tests
*
* @publicApi
*/
const platformCoreDynamicTesting = createPlatformFactory(ɵplatformCoreDynamic, 'coreDynamicTesting', [
{ provide: COMPILER_OPTIONS, useValue: ɵ0, multi: true }, {
provide: ɵTestingCompilerFactory,
useClass: TestingCompilerFactoryImpl,
deps: [Injector, CompilerFactory]
}
]);
/**
* @license
* Copyright Google LLC 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
*/
/**
* @license
* Copyright Google LLC 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
*/
/**
* @publicApi
*/
const platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
/**
* NgModule for testing.
*
* @publicApi
*/
class BrowserDynamicTestingModule {
}
BrowserDynamicTestingModule.ɵfac = function BrowserDynamicTestingModule_Factory(t) { return new (t || BrowserDynamicTestingModule)(); };
BrowserDynamicTestingModule.ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: BrowserDynamicTestingModule });
BrowserDynamicTestingModule.ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ providers: [
{ provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
], imports: [BrowserTestingModule] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(BrowserDynamicTestingModule, [{
type: NgModule,
args: [{
exports: [BrowserTestingModule],
providers: [
{ provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
]
}]
}], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(BrowserDynamicTestingModule, { exports: function () { return [BrowserTestingModule]; } }); })();
/**
* @license
* Copyright Google LLC 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
*/
/**
* @license
* Copyright Google LLC 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
*/
/**
* Generated bundle index. Do not edit.
*/
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 };
//# sourceMappingURL=testing.js.map