5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
+ import { Logger , schema } from '@angular-devkit/core' ;
8
9
import {
9
10
Collection ,
10
11
SchematicEngine ,
@@ -15,7 +16,6 @@ import {
15
16
FileSystemSchematicDesc ,
16
17
NodeModulesTestEngineHost ,
17
18
} from '@angular-devkit/schematics/tools' ;
18
- import { SchemaClassFactory } from '@ngtools/json-schema' ;
19
19
import { Observable } from 'rxjs/Observable' ;
20
20
21
21
@@ -25,9 +25,13 @@ export class SchematicTestRunner {
25
25
private _engineHost = new NodeModulesTestEngineHost ( ) ;
26
26
private _engine : SchematicEngine < { } , { } > = new SchematicEngine ( this . _engineHost ) ;
27
27
private _collection : Collection < { } , { } > ;
28
+ private _logger : Logger ;
29
+ private _registry : schema . JsonSchemaRegistry ;
28
30
29
31
constructor ( private _collectionName : string , collectionPath : string ) {
30
32
this . _engineHost . registerCollection ( _collectionName , collectionPath ) ;
33
+ this . _logger = new Logger ( 'test' ) ;
34
+ this . _registry = new schema . JsonSchemaRegistry ( ) ;
31
35
32
36
this . _engineHost . registerOptionsTransform ( (
33
37
schematicDescription : { } ,
@@ -36,10 +40,13 @@ export class SchematicTestRunner {
36
40
const schematic : FileSystemSchematicDesc = schematicDescription as FileSystemSchematicDesc ;
37
41
38
42
if ( schematic . schema && schematic . schemaJson ) {
39
- const SchemaMetaClass = SchemaClassFactory < SchematicSchemaT > ( schematic . schemaJson ) ;
40
- const schemaClass = new SchemaMetaClass ( opts ) ;
43
+ const schemaJson = schematic . schemaJson as schema . JsonSchemaObject ;
44
+ const name = schemaJson . id || schematic . name ;
45
+ this . _registry . addSchema ( name , schemaJson ) ;
46
+ const serializer = new schema . serializers . JavascriptSerializer ( ) ;
47
+ const fn = serializer . serialize ( name , this . _registry ) ;
41
48
42
- return schemaClass . $$root ( ) ;
49
+ return fn ( opts ) ;
43
50
}
44
51
45
52
return opts ;
@@ -48,11 +55,13 @@ export class SchematicTestRunner {
48
55
this . _collection = this . _engine . createCollection ( this . _collectionName ) ;
49
56
}
50
57
58
+ get logger ( ) { return this . _logger ; }
59
+
51
60
runSchematicAsync ( schematicName : string , opts ?: SchematicSchemaT , tree ?: Tree ) : Observable < Tree > {
52
61
const schematic = this . _collection . createSchematic ( schematicName ) ;
53
62
const host = Observable . of ( tree || new VirtualTree ) ;
54
63
55
- return schematic . call ( opts || { } , host ) ;
64
+ return schematic . call ( opts || { } , host , { logger : this . _logger } ) ;
56
65
}
57
66
58
67
runSchematic ( schematicName : string , opts ?: SchematicSchemaT , tree ?: Tree ) : Tree {
@@ -61,7 +70,7 @@ export class SchematicTestRunner {
61
70
let result : Tree | null = null ;
62
71
const host = Observable . of ( tree || new VirtualTree ) ;
63
72
64
- schematic . call ( opts || { } , host )
73
+ schematic . call ( opts || { } , host , { logger : this . _logger } )
65
74
. subscribe ( t => result = t ) ;
66
75
67
76
if ( result === null ) {
0 commit comments