@@ -19,7 +19,7 @@ import { SchemaClassFactory } from '@ngtools/json-schema';
1919import { Observable } from 'rxjs/Observable' ;
2020
2121
22- export interface SchemaT { }
22+ export interface SchematicSchemaT { }
2323
2424export class SchematicTestRunner {
2525 private engineHost : NodeModulesEngineHost ;
@@ -34,9 +34,9 @@ export class SchematicTestRunner {
3434 this . engineHost = new NodeModulesEngineHost ( ) ;
3535 this . engine = new SchematicEngine ( this . engineHost ) ;
3636 this . engineHost . registerOptionsTransform ( (
37- schematic : FileSystemSchematicDesc , opts : SchemaT ) => {
37+ schematic : FileSystemSchematicDesc , opts : SchematicSchemaT ) => {
3838 if ( schematic . schema && schematic . schemaJson ) {
39- const SchemaMetaClass = SchemaClassFactory < SchemaT > ( schematic . schemaJson ) ;
39+ const SchemaMetaClass = SchemaClassFactory < SchematicSchemaT > ( schematic . schemaJson ) ;
4040 const schemaClass = new SchemaMetaClass ( opts ) ;
4141
4242 return schemaClass . $$root ( ) ;
@@ -47,44 +47,26 @@ export class SchematicTestRunner {
4747 this . collection = this . engine . createCollection ( this . collectionName ) ;
4848 }
4949
50- runSchematicAsync ( schematicName : string , opts : SchemaT , tree ?: Tree ) : Observable < Tree > {
50+ runSchematicAsync ( schematicName : string , opts ?: SchematicSchemaT , tree ?: Tree ) : Observable < Tree > {
5151 const schematic = this . collection . createSchematic ( schematicName ) ;
5252 const host = Observable . of ( tree || new VirtualTree ) ;
5353
54- return schematic . call ( opts , host ) ;
54+ return schematic . call ( opts || { } , host ) ;
5555 }
5656
57- runSchematic ( schematicName : string , opts : SchemaT , tree ?: Tree ) : Tree {
57+ runSchematic ( schematicName : string , opts ?: SchematicSchemaT , tree ?: Tree ) : Tree {
5858 const schematic = this . collection . createSchematic ( schematicName ) ;
5959
60- let result : Tree = tree || new VirtualTree ;
61- const host = Observable . of ( result ) ;
60+ let result : Tree | null = null ;
61+ const host = Observable . of ( tree || new VirtualTree ) ;
6262
63- schematic . call ( opts , host )
63+ schematic . call ( opts || { } , host )
6464 . subscribe ( t => result = t ) ;
6565
66- return result ;
67- }
68-
69- public static createAppNgModule ( tree : Tree , path ?: string ) : Tree {
70- tree . create ( path || '/src/app/app.module.ts' , `
71- import { BrowserModule } from '@angular/platform-browser';
72- import { NgModule } from '@angular/core';
73- import { AppComponent } from './app.component';
74-
75- @NgModule({
76- declarations: [
77- AppComponent
78- ],
79- imports: [
80- BrowserModule
81- ],
82- providers: [],
83- bootstrap: [AppComponent]
84- })
85- export class AppModule { }
86- ` ) ;
66+ if ( result === null ) {
67+ throw new Error ( 'Schematic is async, please use runSchematicAsync' ) ;
68+ }
8769
88- return tree ;
70+ return result ;
8971 }
9072}
0 commit comments