|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import { logging, schema } from '@angular-devkit/core';
|
10 |
| -import { Observable, of as observableOf } from 'rxjs'; |
| 10 | +import { Observable, from, lastValueFrom, of as observableOf } from 'rxjs'; |
11 | 11 | import { map } from 'rxjs/operators';
|
12 | 12 | import {
|
13 | 13 | Collection,
|
@@ -78,34 +78,57 @@ export class SchematicTestRunner {
|
78 | 78 | this._engineHost.registerCollection(collectionName, collectionPath);
|
79 | 79 | }
|
80 | 80 |
|
81 |
| - runSchematicAsync<SchematicSchemaT extends object>( |
| 81 | + async runSchematic<SchematicSchemaT extends object>( |
82 | 82 | schematicName: string,
|
83 | 83 | opts?: SchematicSchemaT,
|
84 | 84 | tree?: Tree,
|
85 |
| - ): Observable<UnitTestTree> { |
| 85 | + ): Promise<UnitTestTree> { |
86 | 86 | const schematic = this._collection.createSchematic(schematicName, true);
|
87 | 87 | const host = observableOf(tree || new HostTree());
|
88 | 88 | this._engineHost.clearTasks();
|
89 | 89 |
|
90 |
| - return schematic |
91 |
| - .call(opts || {}, host, { logger: this._logger }) |
92 |
| - .pipe(map((tree) => new UnitTestTree(tree))); |
| 90 | + const newTree = await lastValueFrom(schematic.call(opts || {}, host, { logger: this._logger })); |
| 91 | + |
| 92 | + return new UnitTestTree(newTree); |
93 | 93 | }
|
94 | 94 |
|
95 |
| - runExternalSchematicAsync<SchematicSchemaT extends object>( |
96 |
| - collectionName: string, |
| 95 | + /** |
| 96 | + * @deprecated since version 15.1. Use `runSchematic` instead. |
| 97 | + */ |
| 98 | + runSchematicAsync<SchematicSchemaT extends object>( |
97 | 99 | schematicName: string,
|
98 | 100 | opts?: SchematicSchemaT,
|
99 | 101 | tree?: Tree,
|
100 | 102 | ): Observable<UnitTestTree> {
|
| 103 | + return from(this.runSchematic(schematicName, opts, tree)); |
| 104 | + } |
| 105 | + |
| 106 | + async runExternalSchematic<SchematicSchemaT extends object>( |
| 107 | + collectionName: string, |
| 108 | + schematicName: string, |
| 109 | + opts?: SchematicSchemaT, |
| 110 | + tree?: Tree, |
| 111 | + ): Promise<UnitTestTree> { |
101 | 112 | const externalCollection = this._engine.createCollection(collectionName);
|
102 | 113 | const schematic = externalCollection.createSchematic(schematicName, true);
|
103 | 114 | const host = observableOf(tree || new HostTree());
|
104 | 115 | this._engineHost.clearTasks();
|
105 | 116 |
|
106 |
| - return schematic |
107 |
| - .call(opts || {}, host, { logger: this._logger }) |
108 |
| - .pipe(map((tree) => new UnitTestTree(tree))); |
| 117 | + const newTree = await lastValueFrom(schematic.call(opts || {}, host, { logger: this._logger })); |
| 118 | + |
| 119 | + return new UnitTestTree(newTree); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @deprecated since version 15.1. Use `runExternalSchematic` instead. |
| 124 | + */ |
| 125 | + runExternalSchematicAsync<SchematicSchemaT extends object>( |
| 126 | + collectionName: string, |
| 127 | + schematicName: string, |
| 128 | + opts?: SchematicSchemaT, |
| 129 | + tree?: Tree, |
| 130 | + ): Observable<UnitTestTree> { |
| 131 | + return from(this.runExternalSchematic(collectionName, schematicName, opts, tree)); |
109 | 132 | }
|
110 | 133 |
|
111 | 134 | callRule(rule: Rule, tree: Tree, parentContext?: Partial<SchematicContext>): Observable<Tree> {
|
|
0 commit comments