Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nestjs/nest-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 11, 2019
2 parents 9de7d80 + e20e9da commit 9d1fdec
Show file tree
Hide file tree
Showing 8 changed files with 6,914 additions and 42 deletions.
41 changes: 41 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## PR Checklist
Please check if your PR fulfills the following requirements:

- [ ] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)


## PR Type
What kind of change does this PR introduce?

<!-- Please check the one that applies to this PR using "x". -->
```
[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:
```

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->

Issue Number: N/A


## What is the new behavior?


## Does this PR introduce a breaking change?
```
[ ] Yes
[ ] No
```

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. -->


## Other information
3 changes: 3 additions & 0 deletions actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export * from './build.action';
export * from './generate.action';
export * from './info.action';
export * from './new.action';
export * from './update.action';
export * from './start.action';
export * from './add.action';
13 changes: 9 additions & 4 deletions commands/command.loader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import chalk from 'chalk';
import { CommanderStatic } from 'commander';
import { BuildAction, GenerateAction, InfoAction, NewAction } from '../actions';
import { AddAction } from '../actions/add.action';
import { StartAction } from '../actions/start.action';
import { UpdateAction } from '../actions/update.action';
import {
BuildAction,
GenerateAction,
InfoAction,
NewAction,
AddAction,
StartAction,
UpdateAction,
} from '../actions';
import { ERROR_PREFIX } from '../lib/ui';
import { AddCommand } from './add.command';
import { BuildCommand } from './build.command';
Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
},
"homepage": "https://github.com/nestjs/nest-cli#readme",
"dependencies": {
"@angular-devkit/core": "8.3.6",
"@angular-devkit/schematics": "8.3.6",
"@angular-devkit/schematics-cli": "0.803.6",
"@angular-devkit/core": "8.3.8",
"@angular-devkit/schematics": "8.3.8",
"@angular-devkit/schematics-cli": "0.803.8",
"@nestjs/schematics": "^6.6.3",
"@types/webpack": "4.39.2",
"chalk": "2.4.2",
Expand All @@ -61,7 +61,7 @@
"@types/copyfiles": "2.1.1",
"@types/inquirer": "6.5.0",
"@types/jest": "24.0.18",
"@types/node": "12.7.9",
"@types/node": "12.7.12",
"@types/node-emoji": "1.8.1",
"@types/ora": "3.1.0",
"@types/os-name": "2.0.0",
Expand Down
25 changes: 19 additions & 6 deletions test/lib/readers/file-system.reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,33 @@ jest.mock('fs', () => {
};
});

const dir: string = process.cwd();
const reader: Reader = new FileSystemReader(dir);

describe('File System Reader', () => {
afterAll(() => {
jest.clearAllMocks();
});
it('should use fs.readdir when list', async () => {
const dir: string = process.cwd();
const reader: Reader = new FileSystemReader(dir);
const filenames: string[] = await reader.list();
await reader.list();
expect(fs.readdir).toHaveBeenCalled();
});
it('should use fs.readFile when read', async () => {
const dir: string = process.cwd();
const reader: Reader = new FileSystemReader(dir);
const content: string = await reader.read('filename');
await reader.read('filename');
expect(fs.readFile).toHaveBeenCalled();
});

describe('readAnyOf tests', () => {
it('should call readFile when running readAnyOf fn', async () => {
const filenames: string[] = ['file1', 'file2', 'file3'];
await reader.readAnyOf(filenames);

expect(fs.readFile).toHaveBeenCalled();
});

it('should return null when no file is passed', async () => {
const content = await reader.readAnyOf([]);
expect(content).toEqual(undefined);
});
});
});
23 changes: 17 additions & 6 deletions test/lib/runners/schematic.runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as fs from 'fs';
import * as path from 'path';
import { SchematicRunner } from '../../../lib/runners/schematic.runner';

const withSep = (route: string) => path.resolve(route.split('/').join(path.sep));
const withSep = (route: string) =>
path.resolve(route.split('/').join(path.sep));

const existsSyncTrueForPathMock = (pathToExist: string) => {
pathToExist = withSep(pathToExist);
Expand Down Expand Up @@ -51,29 +52,37 @@ describe('SchematicRunner', () => {

describe('findClosestSchematicsBinary', () => {
it('it should return the correct path when called from globally installed package', () => {
const existingPath = withSep('/home/test/.nvm/versions/node/v8.12.0/lib/node_modules/@nestjs/cli/node_modules/.bin/schematics');
const existingPath = withSep(
'/home/test/.nvm/versions/node/v8.12.0/lib/node_modules/@nestjs/cli/node_modules/.bin/schematics',
);

const globalRunnersDirname = withSep(
'/home/test/.nvm/versions/node/v8.12.0/lib/node_modules/@nestjs/cli/lib/runners',
);

(fs as any).existsSync = jest.fn(existsSyncTrueForPathMock(existingPath));
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(globalRunnersDirname);
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(
globalRunnersDirname,
);

const resolvedPath = SchematicRunner.findClosestSchematicsBinary();

expect(resolvedPath).toEqual(existingPath);
});

it('should return the correct path when called from locally installed package', () => {
const existingPath = withSep('/home/test/project/node_modules/.bin/schematics');
const existingPath = withSep(
'/home/test/project/node_modules/.bin/schematics',
);

const localRunnersDirname = withSep(
'/home/test/project/node_modules/@nestjs/cli/lib/runners',
);

(fs as any).existsSync = jest.fn(existsSyncTrueForPathMock(existingPath));
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(localRunnersDirname);
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(
localRunnersDirname,
);

const resolvedPath = SchematicRunner.findClosestSchematicsBinary();

Expand All @@ -86,7 +95,9 @@ describe('SchematicRunner', () => {
);

(fs as any).existsSync = jest.fn().mockReturnValue(false);
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(globalRunnersDirname);
(SchematicRunner as any).prototype.constructor.getModulePaths = getModulePathsMock(
globalRunnersDirname,
);

expect(SchematicRunner.findClosestSchematicsBinary).toThrow();
});
Expand Down
Loading

0 comments on commit 9d1fdec

Please sign in to comment.