Skip to content

Commit

Permalink
refactor(core): drop r3_ prefix from TestBed filenames and merge files
Browse files Browse the repository at this point in the history
This commit performs a couple updates:
- the `r3_` prefix is dropped from the names of TestBed-related files
- the `test_bed_common.ts` content is moved into `test_bed.ts`
  • Loading branch information
AndrewKushnir committed Jun 30, 2022
1 parent 5f2047f commit e84d180
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 130 deletions.
7 changes: 3 additions & 4 deletions goldens/circular-deps/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,12 @@
"packages/core/src/render3/interfaces/view.ts"
],
[
"packages/core/testing/src/r3_test_bed_compiler.ts",
"packages/core/testing/src/test_bed_common.ts",
"packages/core/testing/src/test_bed_compiler.ts",
"packages/core/testing/src/test_bed.ts",
"packages/core/testing/src/r3_test_bed.ts"
"packages/core/testing/src/test_bed_impl.ts"
],
[
"packages/core/testing/src/r3_test_bed.ts",
"packages/core/testing/src/test_bed_impl.ts",
"packages/core/testing/src/test_bed.ts"
],
[
Expand Down
6 changes: 2 additions & 4 deletions packages/core/test/test_bed_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
*/

import {APP_INITIALIZER, ChangeDetectorRef, Compiler, Component, Directive, ElementRef, ErrorHandler, getNgModuleById, Inject, Injectable, InjectionToken, Injector, Input, LOCALE_ID, ModuleWithProviders, NgModule, Optional, Pipe, Type, ViewChild, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineInjector as defineInjector, ɵɵdefineNgModule as defineNgModule, ɵɵelementEnd as elementEnd, ɵɵelementStart as elementStart, ɵɵsetNgModuleScope as setNgModuleScope, ɵɵtext as text} from '@angular/core';
import {TestBedImpl} from '@angular/core/testing/src/r3_test_bed';
import {TestBed} from '@angular/core/testing/src/test_bed';
import {TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, TestBed, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from '@angular/core/testing/src/test_bed';
import {TestBedImpl} from '@angular/core/testing/src/test_bed_impl';
import {By} from '@angular/platform-browser';
import {expect} from '@angular/platform-browser/testing/src/matchers';

import {TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from '../testing/src/test_bed_common';

const NAME = new InjectionToken<string>('name');

@Injectable({providedIn: 'root'})
Expand Down
105 changes: 102 additions & 3 deletions packages/core/testing/src/test_bed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component, Directive, InjectFlags, NgModule, Pipe, PlatformRef, ProviderToken, Type} from '@angular/core';
import {Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, ProviderToken, SchemaMetadata, Type} from '@angular/core';

import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
import {TestBedImpl} from './r3_test_bed';
import {TestBedStatic, TestEnvironmentOptions, TestModuleMetadata} from './test_bed_common';
import {TestBedImpl} from './test_bed_impl';

/** Whether test modules should be torn down by default. */
export const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;

/** Whether unknown elements in templates should throw by default. */
export const THROW_ON_UNKNOWN_ELEMENTS_DEFAULT = false;

/** Whether unknown properties in templates should throw by default. */
export const THROW_ON_UNKNOWN_PROPERTIES_DEFAULT = false;

/**
* @publicApi
Expand Down Expand Up @@ -85,6 +93,15 @@ export interface TestBed {
createComponent<T>(component: Type<T>): ComponentFixture<T>;
}

/**
* Static methods implemented by the `TestBed`.
*
* @publicApi
*/
export interface TestBedStatic extends TestBed {
new(...args: any[]): TestBed;
}

/**
* @description
* Configures and initializes environment for unit testing and provides methods for
Expand Down Expand Up @@ -169,3 +186,85 @@ export function withModule(moduleDef: TestModuleMetadata, fn?: Function|null): (
}
return new InjectSetupWrapper(() => moduleDef);
}

/**
* Configures the test module teardown behavior in `TestBed`.
* @publicApi
*/
export interface ModuleTeardownOptions {
/** Whether the test module should be destroyed after every test. */
destroyAfterEach: boolean;

/** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
rethrowErrors?: boolean;
}

/**
* An abstract class for inserting the root test component element in a platform independent way.
*
* @publicApi
*/
export class TestComponentRenderer {
insertRootElement(rootElementId: string) {}
removeAllRootElements?() {}
}

/**
* @publicApi
*/
export const ComponentFixtureAutoDetect =
new InjectionToken<boolean[]>('ComponentFixtureAutoDetect');

/**
* @publicApi
*/
export const ComponentFixtureNoNgZone = new InjectionToken<boolean[]>('ComponentFixtureNoNgZone');

/**
* @publicApi
*/
export interface TestModuleMetadata {
providers?: any[];
declarations?: any[];
imports?: any[];
schemas?: Array<SchemaMetadata|any[]>;
teardown?: ModuleTeardownOptions;
/**
* Whether NG0304 runtime errors should be thrown when unknown elements are present in component's
* template. Defaults to `false`, where the error is simply logged. If set to `true`, the error is
* thrown.
* @see https://angular.io/errors/NG8001 for the description of the problem and how to fix it
*/
errorOnUnknownElements?: boolean;
/**
* Whether errors should be thrown when unknown properties are present in component's template.
* Defaults to `false`, where the error is simply logged.
* If set to `true`, the error is thrown.
* @see https://angular.io/errors/NG8002 for the description of the error and how to fix it
*/
errorOnUnknownProperties?: boolean;
}

/**
* @publicApi
*/
export interface TestEnvironmentOptions {
/**
* Configures the test module teardown behavior in `TestBed`.
*/
teardown?: ModuleTeardownOptions;
/**
* Whether errors should be thrown when unknown elements are present in component's template.
* Defaults to `false`, where the error is simply logged.
* If set to `true`, the error is thrown.
* @see https://angular.io/errors/NG8001 for the description of the error and how to fix it
*/
errorOnUnknownElements?: boolean;
/**
* Whether errors should be thrown when unknown properties are present in component's template.
* Defaults to `false`, where the error is simply logged.
* If set to `true`, the error is thrown.
* @see https://angular.io/errors/NG8002 for the description of the error and how to fix it
*/
errorOnUnknownProperties?: boolean;
}
111 changes: 0 additions & 111 deletions packages/core/testing/src/test_bed_common.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {generateStandaloneInDeclarationsError} from '../../src/render3/jit/modul

import {MetadataOverride} from './metadata_override';
import {ComponentResolver, DirectiveResolver, NgModuleResolver, PipeResolver, Resolver} from './resolvers';
import {TestModuleMetadata} from './test_bed_common';
import {TestModuleMetadata} from './test_bed';

enum TestingModuleOverride {
DECLARATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ import {

import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
import {TestBedCompiler} from './r3_test_bed_compiler';
import {TestBed} from './test_bed';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, ModuleTeardownOptions, TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, TestComponentRenderer, TestEnvironmentOptions, TestModuleMetadata, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from './test_bed_common';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, ModuleTeardownOptions, TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, TestBed, TestComponentRenderer, TestEnvironmentOptions, TestModuleMetadata, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from './test_bed';
import {TestBedCompiler} from './test_bed_compiler';

let _nextRootElementId = 0;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/testing/src/test_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

import {resetFakeAsyncZone} from './fake_async';
import {TestBedImpl} from './r3_test_bed';
import {TestBedImpl} from './test_bed_impl';

declare var global: any;

Expand Down
5 changes: 2 additions & 3 deletions packages/core/testing/src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
export * from './async';
export * from './component_fixture';
export * from './fake_async';
export {TestBed, inject, InjectSetupWrapper, withModule} from './test_bed';
export {TestComponentRenderer, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestModuleMetadata, TestEnvironmentOptions, ModuleTeardownOptions, TestBedStatic} from './test_bed_common';
export {TestBed, inject, ComponentFixtureNoNgZone, TestModuleMetadata, TestEnvironmentOptions, ComponentFixtureAutoDetect, InjectSetupWrapper, withModule, TestComponentRenderer, TestBedStatic, ModuleTeardownOptions} from './test_bed';
export * from './test_hooks';
export {getTestBed} from './r3_test_bed';
export {getTestBed} from './test_bed_impl';
export * from './metadata_override';
export {MetadataOverrider as ɵMetadataOverrider} from './metadata_overrider';

0 comments on commit e84d180

Please sign in to comment.