Skip to content

Commit aa6f0d0

Browse files
devversionalan-agius4
authored andcommitted
fix(@angular-devkit/schematics): ensure collections can be resolved via test runner in pnpm workspaces
Currently when operating within a pnpm workspace and leveraging the schematic test runner, there are situations where e.g. `@schematics/angular` cannot be resolved. Consider this pnpm node modules structure: ``` packages/ pwa/ node_modules/@schematics/angular --> .pnpm-store/@schematics/angular/... node_modules/@angular-devkit/schematics --> .pnpm-store/@angular-devkit/schematics/... index_spec.js // trying to call external schematic `@schematics/angular` ``` This above setup will fail because `@schematics/angular` is attempted to be resolved from within the devkit schematics code, which doesn't have access, or a dependency on `@schematics/angular`. We can use the specified collection of the test runner to determine a good "resolution lookup site", similiar to how it happens with the real `ng update` command.
1 parent ff8192a commit aa6f0d0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@ export class UnitTestTree extends DelegateTree {
4343
}
4444

4545
export class SchematicTestRunner {
46-
private _engineHost = new NodeModulesTestEngineHost();
47-
private _engine: SchematicEngine<{}, {}> = new SchematicEngine(this._engineHost);
46+
private _engineHost: NodeModulesTestEngineHost;
47+
private _engine: SchematicEngine<{}, {}>;
4848
private _collection: Collection<{}, {}>;
4949
private _logger: logging.Logger;
5050

5151
constructor(
5252
private _collectionName: string,
5353
collectionPath: string,
5454
) {
55+
this._engineHost = new NodeModulesTestEngineHost([
56+
// Leverage the specified collection path as an additional base for resolving other
57+
// collections by name. This is useful in e.g. pnpm workspaces where `@angular-devkit/schematics`
58+
// doesn't necessarily have access to e.g. `@schematics/angular`.
59+
collectionPath,
60+
]);
61+
this._engine = new SchematicEngine(this._engineHost);
62+
5563
this._engineHost.registerCollection(_collectionName, collectionPath);
5664
this._logger = new logging.Logger('test');
5765

0 commit comments

Comments
 (0)