Skip to content

Commit 8625006

Browse files
committed
feat(@angular-devkit/schematics): use the core json schema for SchematicTestRunner
1 parent 177b535 commit 8625006

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/angular_devkit/schematics/test/schematic-test-runner.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { Logger, schema } from '@angular-devkit/core';
89
import {
910
Collection,
1011
SchematicEngine,
@@ -15,7 +16,6 @@ import {
1516
FileSystemSchematicDesc,
1617
NodeModulesTestEngineHost,
1718
} from '@angular-devkit/schematics/tools';
18-
import { SchemaClassFactory } from '@ngtools/json-schema';
1919
import { Observable } from 'rxjs/Observable';
2020

2121

@@ -25,9 +25,13 @@ export class SchematicTestRunner {
2525
private _engineHost = new NodeModulesTestEngineHost();
2626
private _engine: SchematicEngine<{}, {}> = new SchematicEngine(this._engineHost);
2727
private _collection: Collection<{}, {}>;
28+
private _logger: Logger;
29+
private _registry: schema.JsonSchemaRegistry;
2830

2931
constructor(private _collectionName: string, collectionPath: string) {
3032
this._engineHost.registerCollection(_collectionName, collectionPath);
33+
this._logger = new Logger('test');
34+
this._registry = new schema.JsonSchemaRegistry();
3135

3236
this._engineHost.registerOptionsTransform((
3337
schematicDescription: {},
@@ -36,10 +40,13 @@ export class SchematicTestRunner {
3640
const schematic: FileSystemSchematicDesc = schematicDescription as FileSystemSchematicDesc;
3741

3842
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);
4148

42-
return schemaClass.$$root();
49+
return fn(opts);
4350
}
4451

4552
return opts;
@@ -48,11 +55,13 @@ export class SchematicTestRunner {
4855
this._collection = this._engine.createCollection(this._collectionName);
4956
}
5057

58+
get logger() { return this._logger; }
59+
5160
runSchematicAsync(schematicName: string, opts?: SchematicSchemaT, tree?: Tree): Observable<Tree> {
5261
const schematic = this._collection.createSchematic(schematicName);
5362
const host = Observable.of(tree || new VirtualTree);
5463

55-
return schematic.call(opts || {}, host);
64+
return schematic.call(opts || {}, host, { logger: this._logger });
5665
}
5766

5867
runSchematic(schematicName: string, opts?: SchematicSchemaT, tree?: Tree): Tree {
@@ -61,7 +70,7 @@ export class SchematicTestRunner {
6170
let result: Tree | null = null;
6271
const host = Observable.of(tree || new VirtualTree);
6372

64-
schematic.call(opts || {}, host)
73+
schematic.call(opts || {}, host, { logger: this._logger })
6574
.subscribe(t => result = t);
6675

6776
if (result === null) {

0 commit comments

Comments
 (0)