feat: add .ngsummary.ts files to support AOT unit tests
Design doc: https://docs.google.com/document/d/1VmTkz0EbEVSWfEEWEvQ5sXyQXSCvtMOw4t7pKU-jOwc/edit?usp=sharing
This commit is contained in:

committed by
Matias Niemelä

parent
2714644528
commit
547c363473
@ -0,0 +1 @@
|
||||
Hello world!
|
52
packages/compiler-cli/integrationtest/src/jit_summaries.ts
Normal file
52
packages/compiler-cli/integrationtest/src/jit_summaries.ts
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {Component, Directive, Injectable, NgModule, Pipe} from '@angular/core';
|
||||
|
||||
const instances = new Map<any, Base>();
|
||||
|
||||
export function expectInstanceCreated(type: any) {
|
||||
const instance = instances.get(type) !;
|
||||
expect(instance).toBeDefined();
|
||||
expect(instance.dep instanceof SomeDep).toBe(true);
|
||||
}
|
||||
|
||||
export class SomeDep {}
|
||||
|
||||
export class Base {
|
||||
constructor(public dep: SomeDep) { instances.set(Object.getPrototypeOf(this).constructor, this); }
|
||||
}
|
||||
|
||||
@Component({templateUrl: './jit_summaries.html'})
|
||||
export class SomePrivateComponent extends Base {
|
||||
}
|
||||
|
||||
@Component({templateUrl: './jit_summaries.html'})
|
||||
export class SomePublicComponent extends Base {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]'})
|
||||
export class SomeDirective extends Base {
|
||||
}
|
||||
|
||||
@Pipe({name: 'somePipe'})
|
||||
export class SomePipe extends Base {
|
||||
transform(value: any) { return value; }
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SomeService extends Base {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [SomePublicComponent, SomePrivateComponent, SomeDirective, SomePipe],
|
||||
exports: [SomeDirective, SomePipe, SomePublicComponent],
|
||||
providers: [SomeService]
|
||||
})
|
||||
export class SomeModule extends Base {
|
||||
}
|
@ -28,6 +28,9 @@ import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibM
|
||||
import {CompWithNgContent, ProjectingComp} from './projection';
|
||||
import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, DirectiveForQuery} from './queries';
|
||||
|
||||
// Adding an export here so that TypeScript compiles the file as well
|
||||
export {SomeModule as JitSummariesSomeModule} from './jit_summaries';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AnimateCmp,
|
||||
|
@ -16,4 +16,5 @@ import './i18n_spec';
|
||||
import './ng_module_spec';
|
||||
import './projection_spec';
|
||||
import './query_spec';
|
||||
import './source_map_spec';
|
||||
import './source_map_spec';
|
||||
import './jit_summaries_spec';
|
||||
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {ServerTestingModule, platformServerTesting} from '@angular/platform-server/testing';
|
||||
|
||||
import {SomeDep, SomeDirective, SomeModule, SomePipe, SomePrivateComponent, SomeService, expectInstanceCreated} from '../src/jit_summaries';
|
||||
import {SomeModuleNgSummary} from '../src/jit_summaries.ngsummary';
|
||||
|
||||
describe('Jit Summaries', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.initTestEnvironment(ServerTestingModule, platformServerTesting(), SomeModuleNgSummary);
|
||||
});
|
||||
|
||||
afterEach(() => { TestBed.resetTestEnvironment(); });
|
||||
|
||||
it('should use directive metadata from summaries', () => {
|
||||
@Component({template: '<div someDir></div>'})
|
||||
class TestComp {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomeDirective]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
});
|
||||
|
||||
it('should use pipe metadata from summaries', () => {
|
||||
@Component({template: '{{1 | somePipe}}'})
|
||||
class TestComp {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomePipe);
|
||||
});
|
||||
|
||||
it('should use Service metadata from summaries', () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SomeService, SomeDep],
|
||||
});
|
||||
TestBed.get(SomeService);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
|
||||
it('should use NgModule metadata from summaries', () => {
|
||||
@Component({template: '<div someDir>{{1 | somePipe}}</div>'})
|
||||
class TestComp {
|
||||
constructor(service: SomeService) {}
|
||||
}
|
||||
|
||||
TestBed
|
||||
.configureTestingModule(
|
||||
{providers: [SomeDep], declarations: [TestComp], imports: [SomeModule]})
|
||||
.createComponent(TestComp);
|
||||
|
||||
expectInstanceCreated(SomeModule);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
expectInstanceCreated(SomePipe);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
|
||||
it('should allow to create private components from imported NgModule summaries', () => {
|
||||
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePrivateComponent);
|
||||
expectInstanceCreated(SomePrivateComponent);
|
||||
});
|
||||
});
|
@ -8,14 +8,14 @@
|
||||
|
||||
import {NgModuleRef} from '@angular/core';
|
||||
import {ComponentFixture} from '@angular/core/testing';
|
||||
import {platformServer} from '@angular/platform-server';
|
||||
import {platformServerTesting} from '@angular/platform-server/testing';
|
||||
|
||||
import {MainModule} from '../src/module';
|
||||
import {MainModuleNgFactory} from '../src/module.ngfactory';
|
||||
|
||||
let mainModuleRef: NgModuleRef<MainModule> = null !;
|
||||
beforeEach((done) => {
|
||||
platformServer().bootstrapModuleFactory(MainModuleNgFactory).then((moduleRef: any) => {
|
||||
platformServerTesting().bootstrapModuleFactory(MainModuleNgFactory).then((moduleRef: any) => {
|
||||
mainModuleRef = moduleRef;
|
||||
done();
|
||||
});
|
||||
|
Reference in New Issue
Block a user