diff --git a/packages/workspace/src/schematics/library/files/lib/README.md b/packages/workspace/src/schematics/library/files/lib/README.md index bf02443b31309..f2336f89d3285 100644 --- a/packages/workspace/src/schematics/library/files/lib/README.md +++ b/packages/workspace/src/schematics/library/files/lib/README.md @@ -5,6 +5,6 @@ This library was generated with [Nx](https://nx.dev). ## Running unit tests -Run `ng test <%= name %>` to execute the unit tests via [Jest](https://jestjs.io). +Run `<%= cliCommand %> test <%= name %>` to execute the unit tests via [Jest](https://jestjs.io). <% } %> diff --git a/packages/workspace/src/schematics/library/library.spec.ts b/packages/workspace/src/schematics/library/library.spec.ts index 017d0aa9a209b..86bb95e742b3f 100644 --- a/packages/workspace/src/schematics/library/library.spec.ts +++ b/packages/workspace/src/schematics/library/library.spec.ts @@ -2,6 +2,7 @@ import { Tree } from '@angular-devkit/schematics'; import { createEmptyWorkspace } from '@nrwl/workspace/testing'; import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; import { NxJson } from '@nrwl/workspace'; + import { runSchematic } from '../../utils/testing'; describe('lib', () => { @@ -98,9 +99,14 @@ describe('lib', () => { it('should generate files', async () => { const tree = await runSchematic('lib', { name: 'myLib' }, appTree); + expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.ts')).toBeTruthy(); + expect(tree.exists('libs/my-lib/README.md')).toBeTruthy(); + + const ReadmeContent = tree.readContent('libs/my-lib/README.md'); + expect(ReadmeContent).toContain('nx test my-lib'); }); }); diff --git a/packages/workspace/src/schematics/library/library.ts b/packages/workspace/src/schematics/library/library.ts index 4f13784ea54c7..1f6e57a778aff 100644 --- a/packages/workspace/src/schematics/library/library.ts +++ b/packages/workspace/src/schematics/library/library.ts @@ -21,6 +21,7 @@ import { formatFiles } from '@nrwl/workspace'; import { offsetFromRoot } from '@nrwl/workspace'; import { generateProjectLint, addLintFiles } from '../../utils/lint'; import { addProjectToNxJsonInTree, libsDir } from '../../utils/ast-utils'; +import { cliCommand } from '../../core/file-utils'; export interface NormalizedSchema extends Schema { name: string; @@ -74,6 +75,7 @@ function createFiles(options: NormalizedSchema): Rule { template({ ...options, ...names(options.name), + cliCommand: cliCommand(), tmpl: '', offsetFromRoot: offsetFromRoot(options.projectRoot), hasUnitTestRunner: options.unitTestRunner !== 'none',