From a3fc7e18c0650e3e3f9909611b0e5a6f514265d2 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Sun, 2 Aug 2020 16:00:37 +0200 Subject: [PATCH] fix(core): generate proper cli command in lib readme --- .../workspace/src/schematics/library/files/lib/README.md | 2 +- packages/workspace/src/schematics/library/library.spec.ts | 6 ++++++ packages/workspace/src/schematics/library/library.ts | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/workspace/src/schematics/library/files/lib/README.md b/packages/workspace/src/schematics/library/files/lib/README.md index bf02443b31..f2336f89d3 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 40411fa519..c8f8b9a25d 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', () => { @@ -103,9 +104,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 0034b85dd6..403a678382 100644 --- a/packages/workspace/src/schematics/library/library.ts +++ b/packages/workspace/src/schematics/library/library.ts @@ -22,6 +22,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; @@ -80,6 +81,7 @@ function createFiles(options: NormalizedSchema): Rule { template({ ...options, ...names(options.name), + cliCommand: cliCommand(), tmpl: '', offsetFromRoot: offsetFromRoot(options.projectRoot), hasUnitTestRunner: options.unitTestRunner !== 'none',