Module: ngcli-adapter

Table of contents

Ng CLI Adapter Classes

Functions

Ng CLI Adapter Classes

NxScopedHost

NxScopedHost: Object

Functions

mockSchematicsForTesting

mockSchematicsForTesting(schematics): 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:

mockSchematicsForTesting({ 'mycollection:myschematic': (tree, params) => { tree.write('README.md'); }, });

Parameters

NameType
schematicsObject

Returns

void


overrideCollectionResolutionForTesting

overrideCollectionResolutionForTesting(collections): 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:

overrideCollectionResolutionForTesting({ '@nrwl/workspace': path.join( __dirname, '../../../../workspace/generators.json' ), '@nrwl/angular': path.join(__dirname, '../../../../angular/generators.json'), '@nrwl/linter': path.join(__dirname, '../../../../linter/generators.json'), });

Parameters

NameType
collectionsObject

Returns

void


wrapAngularDevkitSchematic

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

Parameters

NameType
collectionNamestring
generatorNamestring

Returns

fn

▸ (host, generatorOptions): Promise<any>

Parameters
NameType
hostTree
generatorOptionsObject
Returns

Promise<any>