Module: ngcli-adapter

Table of contents

Classes

Functions

Classes

NxScopedHost

NxScopedHost: object

Functions

mockSchematicsForTesting

mockSchematicsForTesting(schematics: { [name: string]: (host: Tree, generatorOptions: { [k: string]: any; }) => Promise<void>; }): void

If you have an Nx Devkit generator invoking the wrapped Angular Devkit schematic, and you don't want the Angular Devkit schematic to run, you can mock it up using this function.

Unfortunately, there are some edge cases in the Nx-Angular devkit integration that can be seen in the unit tests context. This function is useful for handling that as well.

In this case, you can mock it up.

Example:

1mockSchematicsForTesting({
2  'mycollection:myschematic': (tree, params) => {
3    tree.write('README.md');
4  },
5});

Parameters

NameType
schematicsobject

Returns: void


overrideCollectionResolutionForTesting

overrideCollectionResolutionForTesting(collections: { [name: string]: string; }): void

By default, Angular Devkit schematic collections will be resolved using the Node resolution. This doesn't work if you are testing schematics that refer to other schematics in the same repo.

This function can can be used to override the resolution behaviour.

Example:

1overrideCollectionResolutionForTesting({
2  '@nrwl/workspace': path.join(
3    __dirname,
4    '../../../../workspace/collection.json'
5  ),
6  '@nrwl/angular': path.join(__dirname, '../../../../angular/collection.json'),
7  '@nrwl/linter': path.join(__dirname, '../../../../linter/collection.json'),
8});

Parameters

NameType
collectionsobject

Returns: void


wrapAngularDevkitSchematic

wrapAngularDevkitSchematic(collectionName: string, generatorName: string): function

Parameters

NameType
collectionNamestring
generatorNamestring

Returns: (host: Tree, generatorOptions: { [k: string]: any; }) => Promise<any>