fix(build): make Nx dev process WSL-friendly

- Reformat code to have LF line endings.
- Enforce LF line endings.
This commit is contained in:
Victor Savkin 2019-01-13 16:15:41 -05:00
parent c2c01f977b
commit ffd9d93019
33 changed files with 14119 additions and 14234 deletions

View File

@ -48,6 +48,13 @@ Running e2e tests can take some time, so if it often useful to run a single test
yarn e2e affected yarn e2e affected
``` ```
### Developing on Windows
To build Nx on Windows, you need to use WSL.
- Run `yarn install` in WSL. Yarn will compile several dependencies. If you don't run `install` in WSL, they will be compiled for Windows.
- Run `yarn test:scheamtics` and other commands in WSL.
## Submission Guidelines ## Submission Guidelines
### <a name="submit-issue"></a> Submitting an Issue ### <a name="submit-issue"></a> Submitting an Issue

View File

@ -4,11 +4,28 @@
<div align="center"> <div align="center">
[![Build Status](https://travis-ci.org/nrwl/nx.svg?branch=master)](https://travis-ci.org/nrwl/nx) [![Build Status](https://travis-ci.org/nrwl/nx.svg?branch=master)](https://travis-ci.org/nrwl/nx)
[![License](https://img.shields.io/npm/l/@nrwl/schematics.svg?style=flat-square)]() [![License](https://img.shields.io/npm/l/@nrwl/schematics.svg?style=flat-square)]()
[![NPM Version](https://badge.fury.io/js/%40nrwl%2Fnx.svg)](https://www.npmjs.com/@nrwl/nx) [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fnx.svg)](https://www.npmjs.com/@nrwl/nx)
[![NPM Downloads](https://img.shields.io/npm/dt/@nrwl/schematics.svg?style=flat-square)](https://www.npmjs.com/@nrwl/nx)
[![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]() </div>
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
<hr>
# What is Nx?
🔎 **Nx is an open source toolkit for enterprise Angular applications**, which is b
<hr>
# What is Nx?
🔎 **Nx is an open source toolkit for enterprise Angular applications**, which is based on our experienc
# What is Nx?
🔎 **Nx is an open source toolkit for enterprise Angular applications**, which is based on our experience wo
</div> </div>
@ -52,7 +69,9 @@ In other words, small organizations can often get by with informal ad-hoc proces
An Nx workspace is an Angular CLI project that has been enhanced to be enterprise ready. Being an Angular CLI project means it will be handy to have the Angular CLI installed globally, which can be done via npm or yarn as well. An Nx workspace is an Angular CLI project that has been enhanced to be enterprise ready. Being an Angular CLI project means it will be handy to have the Angular CLI installed globally, which can be done via npm or yarn as well.
``` ```
npm install -g @angular/cli After you have installed the Angular CLI, install `@nrwl/schematics`.
`
``` ```
> Note: If you do not have the Angular CLI installed globally you may not be able to use ng from the terminal to run CLI commands within the project. But the package.json file comes with npm scripts to run ng commands, so you can run npm start to ng serve and you can run npm run ng <command> to run any of the ng commands. > Note: If you do not have the Angular CLI installed globally you may not be able to use ng from the terminal to run CLI commands within the project. But the package.json file comes with npm scripts to run ng commands, so you can run npm start to ng serve and you can run npm run ng <command> to run any of the ng commands.
@ -60,19 +79,27 @@ npm install -g @angular/cli
After you have installed the Angular CLI, install `@nrwl/schematics`. After you have installed the Angular CLI, install `@nrwl/schematics`.
``` ```
npm install -g @nrwl/schematics
```
cre
``` ```
After installing it you can create a new Nx workspace by running: After installing it you can create a new Nx workspace by running:
``` ```
create-nx-workspace myworkspacename
```
ng
``` ```
You can also add Nx capabilities to an existing CLI project by running: You can also add Nx capabilities to an existing CLI project by running:
``` ```
ng add @nrwl/schematics ## Quick Start & Documentation
#
``` ```
You are good to go! You are good to go!
@ -91,8 +118,10 @@ You are good to go!
### Talks ### Talks
- [Angular at Large Organizations](https://www.youtube.com/watch?v=piQ0EZhtus0) - # Podcasts and Shows
- [Nx: The New Way to Build Enterprise Angular Apps](https://www.youtube.com/watch?v=xo-1SDmvM8Y)
- [ngAir 140: Nx for Enterprise Angular Development](
- - [ngAir 140: Nx for Enterprise Angular Development](https://www.youtube.com/watch?v=qYNiOKDno_
- [Supercharging the Angular CLI](https://www.youtube.com/watch?v=bMkKz8AedHc) - [Supercharging the Angular CLI](https://www.youtube.com/watch?v=bMkKz8AedHc)
- [Hands on Full Stack development with Nx and Bazel](https://www.youtube.com/watch?v=1KDDIhcQORM) - [Hands on Full Stack development with Nx and Bazel](https://www.youtube.com/watch?v=1KDDIhcQORM)
@ -103,16 +132,18 @@ You are good to go!
## Misc ## Misc
- [nx-examples](https://github.com/nrwl/nx-examples) repo has branches for different nx comments to display expected behavior and example app and libraries. Check out the branch (workspace, ngrx...) to see what gets created for you. More info on readme. - you want to file a bug or submit a PR, read up on repo has branches for different nx comments to display expected behavior and example app and libraries. Check out the branch (workspace, ngrx...) to see what gets created for you. More info on readme.
- [xplat - Cross-platform tools for Nx workspaces](https://nstudio.io/xplat/) - ## Core Team
| Victor Savkin
## Want to help? ## Want to help?
If you want to file a bug or submit a PR, read up on our [guidelines for contributing](https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md). If you want to file a bug or submit a PR, read up on our ----------------------- | -----------------------------------------------------------.
## Core Team ## Core Team
| Victor Savkin | Jason Jean | Benjamin Cabanes | | Victor Savkin | Jason Jean | Benjamin Cabanes |
| ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| ![Victor Savkin](https://github.com/nrwl/nx/blob/master/static/victor_pic.jpg) | ![Jason Jean](https://github.com/nrwl/nx/blob/master/static/jason_pic.jpg) | ![Benjamin Cabanes](https://github.com/nrwl/nx/blob/master/static/ben_pic.jpg) | | ![Victor Savkin](https://github.com/nrwl/nx/blob/master/static/victor_pic.jpg) | ![Jason Jean](https://github.com/nrwl/nx/blob/master/static/jason_pic.jpg) | ![Benjamin Cabanes](https://github.com/nrwl/nx/blob/master/static/ben_pic.jpg) |
| [vsavkin](https://github.com/vsavkin) | [FrozenPandaz](https://github.com/FrozenPandaz) | [bcabanes](https://github.com/bcabanes) | | | | |

View File

@ -9,14 +9,14 @@
"commit": "git-cz", "commit": "git-cz",
"checkcommit": "node ./scripts/commit-lint.js", "checkcommit": "node ./scripts/commit-lint.js",
"e2e": "./scripts/e2e.sh", "e2e": "./scripts/e2e.sh",
"format": "prettier \"**/*.{ts,js,json,css,scss,md}\" \"!**/{__name__,__directory__}/**\" --write", "format": "./scripts/format.sh",
"linknpm": "./scripts/link.sh", "linknpm": "./scripts/link.sh",
"nx-release": "./scripts/nx-release.js", "nx-release": "./scripts/nx-release.js",
"copy": "./scripts/copy.sh", "copy": "./scripts/copy.sh",
"test:schematics": "yarn linknpm fast && ./scripts/test_schematics.sh", "test:schematics": "yarn linknpm fast && ./scripts/test_schematics.sh",
"test:nx": "yarn linknpm fast && ./scripts/test_nx.sh", "test:nx": "yarn linknpm fast && ./scripts/test_nx.sh",
"test": "yarn linknpm fast && ./scripts/test_nx.sh && ./scripts/test_schematics.sh", "test": "yarn linknpm fast && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
"checkformat": "prettier \"**/*.{ts,js,json,css,scss}\" \"!**/{__name__,__directory__}/**\" --list-different" "checkformat": "./scripts/check_format.sh"
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/architect": "~0.11.0", "@angular-devkit/architect": "~0.11.0",
@ -69,7 +69,6 @@
"karma-jasmine": "~1.1.1", "karma-jasmine": "~1.1.1",
"karma-webpack": "2.0.4", "karma-webpack": "2.0.4",
"license-webpack-plugin": "^1.4.0", "license-webpack-plugin": "^1.4.0",
"lint-staged": "^7.2.2",
"ng-packagr": "4.3.1", "ng-packagr": "4.3.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"opn": "^5.3.0", "opn": "^5.3.0",
@ -101,17 +100,6 @@
"collection/.*/files" "collection/.*/files"
] ]
}, },
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.{ts,js,json,css,md}": [
"prettier --write",
"git add"
]
},
"config": { "config": {
"commitizen": { "commitizen": {
"path": "./node_modules/cz-conventional-changelog" "path": "./node_modules/cz-conventional-changelog"

View File

@ -1,18 +1,17 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '../../utils/testing-utils'; import {
createEmptyWorkspace,
runSchematic,
schematicRunner
} from '../../utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test'; import { getFileContent } from '@schematics/angular/utility/test';
import * as stripJsonComments from 'strip-json-comments'; import * as stripJsonComments from 'strip-json-comments';
import { readJsonInTree, updateJsonInTree } from '../../utils/ast-utils'; import { readJsonInTree, updateJsonInTree } from '../../utils/ast-utils';
import { NxJson } from '../../command-line/shared'; import { NxJson } from '../../command-line/shared';
describe('app', () => { describe('app', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -22,9 +21,7 @@ describe('app', () => {
describe('not nested', () => { describe('not nested', () => {
it('should update angular.json', async () => { it('should update angular.json', async () => {
const tree = await schematicRunner const tree = await runSchematic('app', { name: 'myApp' }, appTree);
.runSchematicAsync('app', { name: 'myApp' }, appTree)
.toPromise();
const angularJson = readJsonInTree(tree, '/angular.json'); const angularJson = readJsonInTree(tree, '/angular.json');
expect(angularJson.projects['my-app'].root).toEqual('apps/my-app/'); expect(angularJson.projects['my-app'].root).toEqual('apps/my-app/');
@ -34,9 +31,11 @@ describe('app', () => {
}); });
it('should update nx.json', async () => { it('should update nx.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('app', { name: 'myApp', tags: 'one,two' }, appTree) 'app',
.toPromise(); { name: 'myApp', tags: 'one,two' },
appTree
);
const nxJson = readJsonInTree<NxJson>(tree, '/nx.json'); const nxJson = readJsonInTree<NxJson>(tree, '/nx.json');
expect(nxJson).toEqual({ expect(nxJson).toEqual({
npmScope: 'proj', npmScope: 'proj',
@ -52,9 +51,7 @@ describe('app', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const tree = await schematicRunner const tree = await runSchematic('app', { name: 'myApp' }, appTree);
.runSchematicAsync('app', { name: 'myApp' }, appTree)
.toPromise();
expect(tree.exists(`apps/my-app/karma.conf.js`)).toBeTruthy(); expect(tree.exists(`apps/my-app/karma.conf.js`)).toBeTruthy();
expect(tree.exists('apps/my-app/src/main.ts')).toBeTruthy(); expect(tree.exists('apps/my-app/src/main.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/src/app/app.module.ts')).toBeTruthy(); expect(tree.exists('apps/my-app/src/app/app.module.ts')).toBeTruthy();
@ -93,12 +90,12 @@ describe('app', () => {
}); });
it('should default the prefix to npmScope', async () => { it('should default the prefix to npmScope', async () => {
const noPrefix = await schematicRunner const noPrefix = await runSchematic('app', { name: 'myApp' }, appTree);
.runSchematicAsync('app', { name: 'myApp' }, appTree) const withPrefix = await runSchematic(
.toPromise(); 'app',
const withPrefix = await schematicRunner { name: 'myApp', prefix: 'custom' },
.runSchematicAsync('app', { name: 'myApp', prefix: 'custom' }, appTree) appTree
.toPromise(); );
// Testing without prefix // Testing without prefix
@ -134,10 +131,7 @@ describe('app', () => {
) )
.toPromise(); .toPromise();
const result = await schematicRunner const result = await runSchematic('app', { name: 'myApp' }, appTree);
.runSchematicAsync('app', { name: 'myApp' }, appTree)
.toPromise();
expect(result.exists('apps/my-app/src/main.ts')).toEqual(true); expect(result.exists('apps/my-app/src/main.ts')).toEqual(true);
expect(result.exists('apps/my-app-e2e/protractor.conf.js')).toEqual(true); expect(result.exists('apps/my-app-e2e/protractor.conf.js')).toEqual(true);
}); });
@ -145,13 +139,11 @@ describe('app', () => {
describe('nested', () => { describe('nested', () => {
it('should update angular.json', async () => { it('should update angular.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir' }, { name: 'myApp', directory: 'myDir' },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(tree, '/angular.json'); const angularJson = readJsonInTree(tree, '/angular.json');
expect(angularJson.projects['my-dir-my-app'].root).toEqual( expect(angularJson.projects['my-dir-my-app'].root).toEqual(
@ -163,13 +155,11 @@ describe('app', () => {
}); });
it('should update nx.json', async () => { it('should update nx.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir', tags: 'one,two' }, { name: 'myApp', directory: 'myDir', tags: 'one,two' },
appTree appTree
) );
.toPromise();
const nxJson = readJsonInTree<NxJson>(tree, '/nx.json'); const nxJson = readJsonInTree<NxJson>(tree, '/nx.json');
expect(nxJson).toEqual({ expect(nxJson).toEqual({
npmScope: 'proj', npmScope: 'proj',
@ -191,13 +181,11 @@ describe('app', () => {
expect(lookupFn(config)).toEqual(expectedValue); expect(lookupFn(config)).toEqual(expectedValue);
}; };
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir' }, { name: 'myApp', directory: 'myDir' },
appTree appTree
) );
.toPromise();
const appModulePath = 'apps/my-dir/my-app/src/app/app.module.ts'; const appModulePath = 'apps/my-dir/my-app/src/app/app.module.ts';
expect(getFileContent(tree, appModulePath)).toContain('class AppModule'); expect(getFileContent(tree, appModulePath)).toContain('class AppModule');
@ -245,9 +233,11 @@ describe('app', () => {
}); });
it('should import NgModule', async () => { it('should import NgModule', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('app', { name: 'myApp', directory: 'myDir' }, appTree) 'app',
.toPromise(); { name: 'myApp', directory: 'myDir' },
appTree
);
expect( expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts') getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')
).toContain('NxModule.forRoot()'); ).toContain('NxModule.forRoot()');
@ -255,13 +245,11 @@ describe('app', () => {
describe('routing', () => { describe('routing', () => {
it('should include RouterTestingModule', async () => { it('should include RouterTestingModule', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir', routing: true }, { name: 'myApp', directory: 'myDir', routing: true },
appTree appTree
) );
.toPromise();
expect( expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts') getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')
).toContain('RouterModule.forRoot'); ).toContain('RouterModule.forRoot');
@ -271,13 +259,11 @@ describe('app', () => {
}); });
it('should not modify tests when --skip-tests is set', async () => { it('should not modify tests when --skip-tests is set', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir', routing: true, skipTests: true }, { name: 'myApp', directory: 'myDir', routing: true, skipTests: true },
appTree appTree
) );
.toPromise();
expect( expect(
tree.exists('apps/my-dir/my-app/src/app/app.component.spec.ts') tree.exists('apps/my-dir/my-app/src/app/app.component.spec.ts')
).toBeFalsy(); ).toBeFalsy();
@ -286,13 +272,11 @@ describe('app', () => {
describe('template generation mode', () => { describe('template generation mode', () => {
it('should create Nx specific `app.component.html` template', async () => { it('should create Nx specific `app.component.html` template', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir' }, { name: 'myApp', directory: 'myDir' },
appTree appTree
) );
.toPromise();
expect( expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.html') getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.html')
).toBeTruthy(); ).toBeTruthy();
@ -302,13 +286,11 @@ describe('app', () => {
}); });
it("should update `template`'s property of AppComponent with Nx content", async () => { it("should update `template`'s property of AppComponent with Nx content", async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', directory: 'myDir', inlineTemplate: true }, { name: 'myApp', directory: 'myDir', inlineTemplate: true },
appTree appTree
) );
.toPromise();
expect( expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts') getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts')
).toContain('This is an Angular CLI app built with Nrwl Nx!'); ).toContain('This is an Angular CLI app built with Nrwl Nx!');
@ -317,19 +299,22 @@ describe('app', () => {
describe('--style scss', () => { describe('--style scss', () => {
it('should generate scss styles', async () => { it('should generate scss styles', async () => {
const result = await schematicRunner const result = await runSchematic(
.runSchematicAsync('app', { name: 'myApp', style: 'scss' }, appTree) 'app',
.toPromise(); { name: 'myApp', style: 'scss' },
appTree
);
expect(result.exists('apps/my-app/src/app/app.component.scss')).toEqual( expect(result.exists('apps/my-app/src/app/app.component.scss')).toEqual(
true true
); );
}); });
it('should set it as default', async () => { it('should set it as default', async () => {
const result = await schematicRunner const result = await runSchematic(
.runSchematicAsync('app', { name: 'myApp', style: 'scss' }, appTree) 'app',
.toPromise(); { name: 'myApp', style: 'scss' },
appTree
);
const angularJson = readJsonInTree(result, 'angular.json'); const angularJson = readJsonInTree(result, 'angular.json');
expect(angularJson.projects['my-app'].schematics).toEqual({ expect(angularJson.projects['my-app'].schematics).toEqual({
@ -342,13 +327,11 @@ describe('app', () => {
describe('--unit-test-runner jest', () => { describe('--unit-test-runner jest', () => {
it('should generate a jest config', async () => { it('should generate a jest config', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', unitTestRunner: 'jest' }, { name: 'myApp', unitTestRunner: 'jest' },
appTree appTree
) );
.toPromise();
expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy(); expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy();
expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeTruthy(); expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeTruthy(); expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeTruthy();
@ -379,13 +362,11 @@ describe('app', () => {
describe('--unit-test-runner none', () => { describe('--unit-test-runner none', () => {
it('should not generate test configuration', async () => { it('should not generate test configuration', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', unitTestRunner: 'none' }, { name: 'myApp', unitTestRunner: 'none' },
appTree appTree
) );
.toPromise();
expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeFalsy(); expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeFalsy();
expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy(); expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy();
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy(); expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy();
@ -401,13 +382,11 @@ describe('app', () => {
describe('--e2e-test-runner none', () => { describe('--e2e-test-runner none', () => {
it('should not generate test configuration', async () => { it('should not generate test configuration', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'app', 'app',
{ name: 'myApp', e2eTestRunner: 'none' }, { name: 'myApp', e2eTestRunner: 'none' },
appTree appTree
) );
.toPromise();
expect(tree.exists('apps/my-app-e2e')).toBeFalsy(); expect(tree.exists('apps/my-app-e2e')).toBeFalsy();
const angularJson = readJsonInTree(tree, 'angular.json'); const angularJson = readJsonInTree(tree, 'angular.json');
expect(angularJson.projects['my-app-e2e']).toBeUndefined(); expect(angularJson.projects['my-app-e2e']).toBeUndefined();
@ -416,10 +395,7 @@ describe('app', () => {
describe('replaceAppNameWithPath', () => { describe('replaceAppNameWithPath', () => {
it('should protect `angular.json` commands and properties', async () => { it('should protect `angular.json` commands and properties', async () => {
const tree = await schematicRunner const tree = await runSchematic('app', { name: 'ui' }, appTree);
.runSchematicAsync('app', { name: 'ui' }, appTree)
.toPromise();
const angularJson = readJsonInTree(tree, 'angular.json'); const angularJson = readJsonInTree(tree, 'angular.json');
expect(angularJson.projects['ui']).toBeDefined(); expect(angularJson.projects['ui']).toBeDefined();
expect( expect(
@ -428,10 +404,11 @@ describe('app', () => {
}); });
it('should protect `angular.json` sensible properties value to be renamed', async () => { it('should protect `angular.json` sensible properties value to be renamed', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('app', { name: 'ui', prefix: 'ui' }, appTree) 'app',
.toPromise(); { name: 'ui', prefix: 'ui' },
appTree
);
const angularJson = readJsonInTree(tree, 'angular.json'); const angularJson = readJsonInTree(tree, 'angular.json');
expect(angularJson.projects['ui'].prefix).toEqual('ui'); expect(angularJson.projects['ui'].prefix).toEqual('ui');
}); });

View File

@ -1,15 +1,13 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '@nrwl/schematics/src/utils/testing-utils'; import {
createEmptyWorkspace,
runSchematic
} from '@nrwl/schematics/src/utils/testing-utils';
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils'; import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
import * as path from 'path'; import * as path from 'path';
describe('schematic:cypress-project', () => { describe('schematic:cypress-project', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -19,13 +17,11 @@ describe('schematic:cypress-project', () => {
describe('generate app --e2e-test-runner=cypress', () => { describe('generate app --e2e-test-runner=cypress', () => {
it('should not contain any protractor files', async () => { it('should not contain any protractor files', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
expect( expect(
tree.exists('apps/my-app-e2e/protractor.e2e.json') tree.exists('apps/my-app-e2e/protractor.e2e.json')
@ -41,13 +37,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/tsconfig.e2e.json')).toBeTruthy(); expect(tree.exists('apps/my-app-e2e/tsconfig.e2e.json')).toBeTruthy();
@ -67,13 +61,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should add dependencies into `package.json` file', async () => { it('should add dependencies into `package.json` file', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, 'package.json'); const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.devDependencies.cypress).toBeDefined(); expect(packageJson.devDependencies.cypress).toBeDefined();
@ -81,13 +73,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should add update `angular.json` file', async () => { it('should add update `angular.json` file', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(tree, 'angular.json'); const angularJson = readJsonInTree(tree, 'angular.json');
const project = angularJson.projects['my-app-e2e']; const project = angularJson.projects['my-app-e2e'];
@ -100,13 +90,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should set right path names in `cypress.json`', async () => { it('should set right path names in `cypress.json`', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
const cypressJson = readJsonInTree(tree, 'apps/my-app-e2e/cypress.json'); const cypressJson = readJsonInTree(tree, 'apps/my-app-e2e/cypress.json');
expect(cypressJson).toEqual({ expect(cypressJson).toEqual({
@ -123,13 +111,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should set right path names in `tsconfig.e2e.json`', async () => { it('should set right path names in `tsconfig.e2e.json`', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress' }, { name: 'myApp', e2eTestRunner: 'cypress' },
appTree appTree
) );
.toPromise();
const tsconfigJson = readJsonInTree( const tsconfigJson = readJsonInTree(
tree, tree,
'apps/my-app-e2e/tsconfig.e2e.json' 'apps/my-app-e2e/tsconfig.e2e.json'
@ -144,13 +130,11 @@ describe('schematic:cypress-project', () => {
describe('generate app --e2e-test-runner=cypress --directory=my-dir', () => { describe('generate app --e2e-test-runner=cypress --directory=my-dir', () => {
it('should set right path names in `cypress.json`', async () => { it('should set right path names in `cypress.json`', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' }, { name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' },
appTree appTree
) );
.toPromise();
const cypressJson = readJsonInTree( const cypressJson = readJsonInTree(
tree, tree,
'apps/my-dir/my-app-e2e/cypress.json' 'apps/my-dir/my-app-e2e/cypress.json'
@ -174,13 +158,11 @@ describe('schematic:cypress-project', () => {
}); });
it('should set right path names in `tsconfig.e2e.json`', async () => { it('should set right path names in `tsconfig.e2e.json`', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'application', 'application',
{ name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' }, { name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' },
appTree appTree
) );
.toPromise();
const tsconfigJson = readJsonInTree( const tsconfigJson = readJsonInTree(
tree, tree,
'apps/my-dir/my-app-e2e/tsconfig.e2e.json' 'apps/my-dir/my-app-e2e/tsconfig.e2e.json'

View File

@ -1,16 +1,15 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createApp, createEmptyWorkspace } from '../../utils/testing-utils'; import {
createApp,
createEmptyWorkspace,
runSchematic
} from '../../utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test'; import { getFileContent } from '@schematics/angular/utility/test';
import { readJsonInTree } from '../../utils/ast-utils'; import { readJsonInTree } from '../../utils/ast-utils';
describe('downgrade-module', () => { describe('downgrade-module', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -20,16 +19,14 @@ describe('downgrade-module', () => {
}); });
it('should update main.ts', async () => { it('should update main.ts', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'downgrade-module', 'downgrade-module',
{ {
name: 'legacy', name: 'legacy',
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const main = getFileContent(tree, '/apps/myapp/src/main.ts'); const main = getFileContent(tree, '/apps/myapp/src/main.ts');
expect(main).toContain('downgradeModule(bootstrapAngular)'); expect(main).toContain('downgradeModule(bootstrapAngular)');
@ -40,16 +37,14 @@ describe('downgrade-module', () => {
}); });
it('should update module', async () => { it('should update module', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'downgrade-module', 'downgrade-module',
{ {
name: 'legacy', name: 'legacy',
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, 'apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, 'apps/myapp/src/app/app.module.ts');
expect(appModule).not.toContain('bootstrap:'); expect(appModule).not.toContain('bootstrap:');
@ -67,16 +62,14 @@ describe('downgrade-module', () => {
}) })
); );
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'downgrade-module', 'downgrade-module',
{ {
name: 'legacy', name: 'legacy',
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, '/package.json'); const packageJson = readJsonInTree(tree, '/package.json');
expect(packageJson.dependencies['@angular/upgrade']).toEqual('4.4.4'); expect(packageJson.dependencies['@angular/upgrade']).toEqual('4.4.4');
@ -93,8 +86,7 @@ describe('downgrade-module', () => {
}) })
); );
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'downgrade-module', 'downgrade-module',
{ {
name: 'legacy', name: 'legacy',
@ -102,16 +94,14 @@ describe('downgrade-module', () => {
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, 'package.json'); const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.dependencies['@angular/upgrade']).not.toBeDefined(); expect(packageJson.dependencies['@angular/upgrade']).not.toBeDefined();
}); });
it('should support custom angularJsImport', async () => { it('should support custom angularJsImport', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'downgrade-module', 'downgrade-module',
{ {
name: 'legacy', name: 'legacy',
@ -119,8 +109,7 @@ describe('downgrade-module', () => {
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const main = getFileContent(tree, '/apps/myapp/src/main.ts'); const main = getFileContent(tree, '/apps/myapp/src/main.ts');
expect(main).toContain(`import 'legacy-app';`); expect(main).toContain(`import 'legacy-app';`);

View File

@ -1,57 +1,46 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '../../utils/testing-utils'; import { createEmptyWorkspace, runSchematic } from '../../utils/testing-utils';
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils'; import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
describe('lib', () => { describe('lib', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(async () => { beforeEach(async () => {
appTree = new VirtualTree(); appTree = new VirtualTree();
appTree = createEmptyWorkspace(appTree); appTree = createEmptyWorkspace(appTree);
appTree = await schematicRunner appTree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'lib1', name: 'lib1',
unitTestRunner: 'none' unitTestRunner: 'none'
}, },
appTree appTree
) );
.toPromise();
}); });
it('should generate files', async () => { it('should generate files', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1'
}, },
appTree appTree
) );
.toPromise();
expect(resultTree.exists('/libs/lib1/src/test-setup.ts')).toBeTruthy(); expect(resultTree.exists('/libs/lib1/src/test-setup.ts')).toBeTruthy();
expect(resultTree.exists('/libs/lib1/jest.config.js')).toBeTruthy(); expect(resultTree.exists('/libs/lib1/jest.config.js')).toBeTruthy();
expect(resultTree.exists('/libs/lib1/tsconfig.spec.json')).toBeTruthy(); expect(resultTree.exists('/libs/lib1/tsconfig.spec.json')).toBeTruthy();
}); });
it('should alter angular.json', async () => { it('should alter angular.json', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1'
}, },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(resultTree, 'angular.json'); const angularJson = readJsonInTree(resultTree, 'angular.json');
expect(angularJson.projects.lib1.architect.test).toEqual({ expect(angularJson.projects.lib1.architect.test).toEqual({
builder: '@nrwl/builders:jest', builder: '@nrwl/builders:jest',
@ -67,15 +56,13 @@ describe('lib', () => {
}); });
it('should create a jest.config.js', async () => { it('should create a jest.config.js', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1'
}, },
appTree appTree
) );
.toPromise();
expect(resultTree.readContent('libs/lib1/jest.config.js')) expect(resultTree.readContent('libs/lib1/jest.config.js'))
.toBe(`module.exports = { .toBe(`module.exports = {
name: 'lib1', name: 'lib1',
@ -86,30 +73,26 @@ describe('lib', () => {
}); });
it('should update the local tsconfig.json', async () => { it('should update the local tsconfig.json', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1'
}, },
appTree appTree
) );
.toPromise();
const tsConfig = readJsonInTree(resultTree, 'libs/lib1/tsconfig.json'); const tsConfig = readJsonInTree(resultTree, 'libs/lib1/tsconfig.json');
expect(tsConfig.compilerOptions.types).toContain('jest'); expect(tsConfig.compilerOptions.types).toContain('jest');
expect(tsConfig.compilerOptions.types).toContain('node'); expect(tsConfig.compilerOptions.types).toContain('node');
}); });
it('should create a tsconfig.spec.json', async () => { it('should create a tsconfig.spec.json', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1'
}, },
appTree appTree
) );
.toPromise();
const tsConfig = readJsonInTree(resultTree, 'libs/lib1/tsconfig.spec.json'); const tsConfig = readJsonInTree(resultTree, 'libs/lib1/tsconfig.spec.json');
expect(tsConfig).toEqual({ expect(tsConfig).toEqual({
extends: './tsconfig.json', extends: './tsconfig.json',
@ -125,30 +108,26 @@ describe('lib', () => {
describe('--skip-setup-file', () => { describe('--skip-setup-file', () => {
it('should generate src/test-setup.ts', async () => { it('should generate src/test-setup.ts', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1', project: 'lib1',
skipSetupFile: true skipSetupFile: true
}, },
appTree appTree
) );
.toPromise();
expect(resultTree.exists('src/test-setup.ts')).toBeFalsy(); expect(resultTree.exists('src/test-setup.ts')).toBeFalsy();
}); });
it('should not list the setup file in angular.json', async () => { it('should not list the setup file in angular.json', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1', project: 'lib1',
skipSetupFile: true skipSetupFile: true
}, },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(resultTree, 'angular.json'); const angularJson = readJsonInTree(resultTree, 'angular.json');
expect( expect(
angularJson.projects.lib1.architect.test.options.setupFile angularJson.projects.lib1.architect.test.options.setupFile
@ -156,16 +135,14 @@ describe('lib', () => {
}); });
it('should not list the setup file in tsconfig.spec.json', async () => { it('should not list the setup file in tsconfig.spec.json', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'jest-project', 'jest-project',
{ {
project: 'lib1', project: 'lib1',
skipSetupFile: true skipSetupFile: true
}, },
appTree appTree
) );
.toPromise();
const tsConfig = readJsonInTree( const tsConfig = readJsonInTree(
resultTree, resultTree,
'libs/lib1/tsconfig.spec.json' 'libs/lib1/tsconfig.spec.json'

View File

@ -1,15 +1,14 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace, createLib } from '../../utils/testing-utils'; import {
createEmptyWorkspace,
createLib,
runSchematic
} from '../../utils/testing-utils';
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils'; import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
describe('lib', () => { describe('lib', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -17,13 +16,13 @@ describe('lib', () => {
appTree = createEmptyWorkspace(appTree); appTree = createEmptyWorkspace(appTree);
}); });
it('should generate files', () => { it('should generate files', async () => {
const resultTree = schematicRunner.runSchematic('jest', {}, appTree); const resultTree = await runSchematic('jest', {}, appTree);
expect(resultTree.exists('jest.config.js')).toBeTruthy(); expect(resultTree.exists('jest.config.js')).toBeTruthy();
}); });
it('should add dependencies', () => { it('should add dependencies', async () => {
const resultTree = schematicRunner.runSchematic('jest', {}, appTree); const resultTree = await runSchematic('jest', {}, appTree);
const packageJson = readJsonInTree(resultTree, 'package.json'); const packageJson = readJsonInTree(resultTree, 'package.json');
expect(packageJson.devDependencies.jest).toBeDefined(); expect(packageJson.devDependencies.jest).toBeDefined();
expect(packageJson.devDependencies['@nrwl/builders']).toBeDefined(); expect(packageJson.devDependencies['@nrwl/builders']).toBeDefined();

View File

@ -1,18 +1,17 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createApp, createEmptyWorkspace } from '../../utils/testing-utils'; import {
createApp,
createEmptyWorkspace,
runSchematic
} from '../../utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test'; import { getFileContent } from '@schematics/angular/utility/test';
import * as stripJsonComments from 'strip-json-comments'; import * as stripJsonComments from 'strip-json-comments';
import { readJsonInTree } from '../../utils/ast-utils'; import { readJsonInTree } from '../../utils/ast-utils';
import { NxJson } from '../../command-line/shared'; import { NxJson } from '../../command-line/shared';
describe('lib', () => { describe('lib', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -22,9 +21,11 @@ describe('lib', () => {
describe('not nested', () => { describe('not nested', () => {
it('should update ng-package.json', async () => { it('should update ng-package.json', async () => {
const publishableTree = await schematicRunner const publishableTree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', publishable: true }, appTree) 'lib',
.toPromise(); { name: 'myLib', publishable: true },
appTree
);
let ngPackage = readJsonInTree( let ngPackage = readJsonInTree(
publishableTree, publishableTree,
'libs/my-lib/ng-package.json' 'libs/my-lib/ng-package.json'
@ -34,45 +35,47 @@ describe('lib', () => {
}); });
it('should not update package.json by default', async () => { it('should not update package.json by default', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
const packageJson = readJsonInTree(tree, '/package.json'); const packageJson = readJsonInTree(tree, '/package.json');
expect(packageJson.devDependencies['ng-packagr']).toBeUndefined(); expect(packageJson.devDependencies['ng-packagr']).toBeUndefined();
}); });
it('should update package.json when publishable', async () => { it('should update package.json when publishable', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', publishable: true }, appTree) 'lib',
.toPromise(); { name: 'myLib', publishable: true },
appTree
);
const packageJson = readJsonInTree(tree, '/package.json'); const packageJson = readJsonInTree(tree, '/package.json');
expect(packageJson.devDependencies['ng-packagr']).toBeDefined(); expect(packageJson.devDependencies['ng-packagr']).toBeDefined();
}); });
it("should update npmScope of lib's package.json when publishable", async () => { it("should update npmScope of lib's package.json when publishable", async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', publishable: true }, appTree) 'lib',
.toPromise(); { name: 'myLib', publishable: true },
appTree
);
const packageJson = readJsonInTree(tree, '/libs/my-lib/package.json'); const packageJson = readJsonInTree(tree, '/libs/my-lib/package.json');
expect(packageJson.name).toEqual('@proj/my-lib'); expect(packageJson.name).toEqual('@proj/my-lib');
}); });
it("should update npmScope of lib's package.json when publishable", async () => { it("should update npmScope of lib's package.json when publishable", async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', publishable: true, prefix: 'lib' }, { name: 'myLib', publishable: true, prefix: 'lib' },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, '/libs/my-lib/package.json'); const packageJson = readJsonInTree(tree, '/libs/my-lib/package.json');
expect(packageJson.name).toEqual('@proj/my-lib'); expect(packageJson.name).toEqual('@proj/my-lib');
}); });
it('should update angular.json', async () => { it('should update angular.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', publishable: true }, appTree) 'lib',
.toPromise(); { name: 'myLib', publishable: true },
appTree
);
const angularJson = readJsonInTree(tree, '/angular.json'); const angularJson = readJsonInTree(tree, '/angular.json');
expect(angularJson.projects['my-lib'].root).toEqual('libs/my-lib'); expect(angularJson.projects['my-lib'].root).toEqual('libs/my-lib');
@ -80,13 +83,11 @@ describe('lib', () => {
}); });
it('should remove "build" target from angular.json when a library is not publishable', async () => { it('should remove "build" target from angular.json when a library is not publishable', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', publishable: false }, { name: 'myLib', publishable: false },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(tree, '/angular.json'); const angularJson = readJsonInTree(tree, '/angular.json');
expect(angularJson.projects['my-lib'].root).toEqual('libs/my-lib'); expect(angularJson.projects['my-lib'].root).toEqual('libs/my-lib');
@ -94,9 +95,11 @@ describe('lib', () => {
}); });
it('should update nx.json', async () => { it('should update nx.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', tags: 'one,two' }, appTree) 'lib',
.toPromise(); { name: 'myLib', tags: 'one,two' },
appTree
);
const nxJson = readJsonInTree<NxJson>(tree, '/nx.json'); const nxJson = readJsonInTree<NxJson>(tree, '/nx.json');
expect(nxJson).toEqual({ expect(nxJson).toEqual({
npmScope: 'proj', npmScope: 'proj',
@ -109,9 +112,7 @@ describe('lib', () => {
}); });
it('should update root tsconfig.json', async () => { it('should update root tsconfig.json', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
const tsconfigJson = readJsonInTree(tree, '/tsconfig.json'); const tsconfigJson = readJsonInTree(tree, '/tsconfig.json');
expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([
'libs/my-lib/src/index.ts' 'libs/my-lib/src/index.ts'
@ -119,10 +120,7 @@ describe('lib', () => {
}); });
it('should create a local tsconfig.json', async () => { it('should create a local tsconfig.json', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
const tsconfigJson = readJsonInTree(tree, 'libs/my-lib/tsconfig.json'); const tsconfigJson = readJsonInTree(tree, 'libs/my-lib/tsconfig.json');
expect(tsconfigJson).toEqual({ expect(tsconfigJson).toEqual({
extends: '../../tsconfig.json', extends: '../../tsconfig.json',
@ -134,10 +132,7 @@ describe('lib', () => {
}); });
it('should extend the local tsconfig.json with tsconfig.spec.json', async () => { it('should extend the local tsconfig.json with tsconfig.spec.json', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
const tsconfigJson = readJsonInTree( const tsconfigJson = readJsonInTree(
tree, tree,
'libs/my-lib/tsconfig.spec.json' 'libs/my-lib/tsconfig.spec.json'
@ -146,10 +141,7 @@ describe('lib', () => {
}); });
it('should extend the local tsconfig.json with tsconfig.lib.json', async () => { it('should extend the local tsconfig.json with tsconfig.lib.json', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
const tsconfigJson = readJsonInTree( const tsconfigJson = readJsonInTree(
tree, tree,
'libs/my-lib/tsconfig.lib.json' 'libs/my-lib/tsconfig.lib.json'
@ -158,9 +150,7 @@ describe('lib', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const tree = await schematicRunner const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
expect(tree.exists(`libs/my-lib/karma.conf.js`)).toBeTruthy(); expect(tree.exists(`libs/my-lib/karma.conf.js`)).toBeTruthy();
expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy();
expect(tree.exists('libs/my-lib/src/lib/my-lib.module.ts')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.module.ts')).toBeTruthy();
@ -176,13 +166,11 @@ describe('lib', () => {
tree.exists('libs/my-lib/src/lib/my-lib.service.spec.ts') tree.exists('libs/my-lib/src/lib/my-lib.service.spec.ts')
).toBeFalsy(); ).toBeFalsy();
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib2', simpleModuleName: true }, { name: 'myLib2', simpleModuleName: true },
tree tree
) );
.toPromise();
expect(tree2.exists(`libs/my-lib2/karma.conf.js`)).toBeTruthy(); expect(tree2.exists(`libs/my-lib2/karma.conf.js`)).toBeTruthy();
expect(tree2.exists('libs/my-lib2/src/index.ts')).toBeTruthy(); expect(tree2.exists('libs/my-lib2/src/index.ts')).toBeTruthy();
expect( expect(
@ -204,9 +192,11 @@ describe('lib', () => {
}); });
it('should not generate a module for --module false', async () => { it('should not generate a module for --module false', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', module: false }, appTree) 'lib',
.toPromise(); { name: 'myLib', module: false },
appTree
);
expect(tree.exists('libs/my-lib/src/lib/my-lib.module.ts')).toEqual( expect(tree.exists('libs/my-lib/src/lib/my-lib.module.ts')).toEqual(
false false
); );
@ -217,17 +207,17 @@ describe('lib', () => {
}); });
it('should default the prefix to npmScope', async () => { it('should default the prefix to npmScope', async () => {
const noPrefix = await schematicRunner const noPrefix = await runSchematic('lib', { name: 'myLib' }, appTree);
.runSchematicAsync('lib', { name: 'myLib' }, appTree)
.toPromise();
expect( expect(
JSON.parse(noPrefix.read('angular.json').toString()).projects['my-lib'] JSON.parse(noPrefix.read('angular.json').toString()).projects['my-lib']
.prefix .prefix
).toEqual('proj'); ).toEqual('proj');
const withPrefix = await schematicRunner const withPrefix = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', prefix: 'custom' }, appTree) 'lib',
.toPromise(); { name: 'myLib', prefix: 'custom' },
appTree
);
expect( expect(
JSON.parse(withPrefix.read('angular.json').toString()).projects[ JSON.parse(withPrefix.read('angular.json').toString()).projects[
'my-lib' 'my-lib'
@ -238,13 +228,11 @@ describe('lib', () => {
describe('nested', () => { describe('nested', () => {
it('should update nx.json', async () => { it('should update nx.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir', tags: 'one' }, { name: 'myLib', directory: 'myDir', tags: 'one' },
appTree appTree
) );
.toPromise();
const nxJson = readJsonInTree<NxJson>(tree, '/nx.json'); const nxJson = readJsonInTree<NxJson>(tree, '/nx.json');
expect(nxJson).toEqual({ expect(nxJson).toEqual({
npmScope: 'proj', npmScope: 'proj',
@ -255,8 +243,7 @@ describe('lib', () => {
} }
}); });
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib2', name: 'myLib2',
@ -265,8 +252,7 @@ describe('lib', () => {
simpleModuleName: true simpleModuleName: true
}, },
tree tree
) );
.toPromise();
const nxJson2 = readJsonInTree<NxJson>(tree2, '/nx.json'); const nxJson2 = readJsonInTree<NxJson>(tree2, '/nx.json');
expect(nxJson2).toEqual({ expect(nxJson2).toEqual({
npmScope: 'proj', npmScope: 'proj',
@ -282,13 +268,11 @@ describe('lib', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir' }, { name: 'myLib', directory: 'myDir' },
appTree appTree
) );
.toPromise();
expect(tree.exists(`libs/my-dir/my-lib/karma.conf.js`)).toBeTruthy(); expect(tree.exists(`libs/my-dir/my-lib/karma.conf.js`)).toBeTruthy();
expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy();
expect( expect(
@ -308,13 +292,11 @@ describe('lib', () => {
tree.exists('libs/my-dir/my-lib/src/lib/my-lib.service.spec.ts') tree.exists('libs/my-dir/my-lib/src/lib/my-lib.service.spec.ts')
).toBeFalsy(); ).toBeFalsy();
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib2', directory: 'myDir', simpleModuleName: true }, { name: 'myLib2', directory: 'myDir', simpleModuleName: true },
tree tree
) );
.toPromise();
expect(tree2.exists(`libs/my-dir/my-lib2/karma.conf.js`)).toBeTruthy(); expect(tree2.exists(`libs/my-dir/my-lib2/karma.conf.js`)).toBeTruthy();
expect(tree2.exists('libs/my-dir/my-lib2/src/index.ts')).toBeTruthy(); expect(tree2.exists('libs/my-dir/my-lib2/src/index.ts')).toBeTruthy();
expect( expect(
@ -336,13 +318,11 @@ describe('lib', () => {
}); });
it('should update ng-package.json', async () => { it('should update ng-package.json', async () => {
const publishableTree = await schematicRunner const publishableTree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir', publishable: true }, { name: 'myLib', directory: 'myDir', publishable: true },
appTree appTree
) );
.toPromise();
let ngPackage = readJsonInTree( let ngPackage = readJsonInTree(
publishableTree, publishableTree,
@ -352,13 +332,11 @@ describe('lib', () => {
}); });
it('should update angular.json', async () => { it('should update angular.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir' }, { name: 'myLib', directory: 'myDir' },
appTree appTree
) );
.toPromise();
const angularJson = readJsonInTree(tree, '/angular.json'); const angularJson = readJsonInTree(tree, '/angular.json');
expect(angularJson.projects['my-dir-my-lib'].root).toEqual( expect(angularJson.projects['my-dir-my-lib'].root).toEqual(
@ -367,13 +345,11 @@ describe('lib', () => {
}); });
it('should update tsconfig.json', async () => { it('should update tsconfig.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir' }, { name: 'myLib', directory: 'myDir' },
appTree appTree
) );
.toPromise();
const tsconfigJson = readJsonInTree(tree, '/tsconfig.json'); const tsconfigJson = readJsonInTree(tree, '/tsconfig.json');
expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual( expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual(
['libs/my-dir/my-lib/src/index.ts'] ['libs/my-dir/my-lib/src/index.ts']
@ -384,13 +360,11 @@ describe('lib', () => {
}); });
it('should create a local tsconfig.json', async () => { it('should create a local tsconfig.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir' }, { name: 'myLib', directory: 'myDir' },
appTree appTree
) );
.toPromise();
const tsconfigJson = readJsonInTree( const tsconfigJson = readJsonInTree(
tree, tree,
@ -406,13 +380,11 @@ describe('lib', () => {
}); });
it('should not generate a module for --module false', async () => { it('should not generate a module for --module false', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir', module: false }, { name: 'myLib', directory: 'myDir', module: false },
appTree appTree
) );
.toPromise();
expect( expect(
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts') tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts')
).toEqual(false); ).toEqual(false);
@ -426,9 +398,7 @@ describe('lib', () => {
describe('router', () => { describe('router', () => {
it('should error when lazy is set without routing', async () => { it('should error when lazy is set without routing', async () => {
try { try {
await schematicRunner await runSchematic('lib', { name: 'myLib', lazy: true }, appTree);
.runSchematicAsync('lib', { name: 'myLib', lazy: true }, appTree)
.toPromise();
fail(); fail();
} catch (e) { } catch (e) {
expect(e.message).toEqual('routing must be set'); expect(e.message).toEqual('routing must be set');
@ -437,13 +407,11 @@ describe('lib', () => {
describe('lazy', () => { describe('lazy', () => {
it('should add RouterModule.forChild', async () => { it('should add RouterModule.forChild', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir', routing: true, lazy: true }, { name: 'myLib', directory: 'myDir', routing: true, lazy: true },
appTree appTree
) );
.toPromise();
expect( expect(
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts') tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts')
@ -455,8 +423,7 @@ describe('lib', () => {
) )
).toContain('RouterModule.forChild'); ).toContain('RouterModule.forChild');
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib2', name: 'myLib2',
@ -466,8 +433,7 @@ describe('lib', () => {
simpleModuleName: true simpleModuleName: true
}, },
tree tree
) );
.toPromise();
expect( expect(
tree2.exists('libs/my-dir/my-lib2/src/lib/my-lib2.module.ts') tree2.exists('libs/my-dir/my-lib2/src/lib/my-lib2.module.ts')
@ -479,8 +445,7 @@ describe('lib', () => {
it('should update the parent module', async () => { it('should update the parent module', async () => {
appTree = createApp(appTree, 'myapp'); appTree = createApp(appTree, 'myapp');
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib', name: 'myLib',
@ -490,17 +455,15 @@ describe('lib', () => {
parentModule: 'apps/myapp/src/app/app.module.ts' parentModule: 'apps/myapp/src/app/app.module.ts'
}, },
appTree appTree
) );
.toPromise();
const moduleContents = getFileContent( const moduleContents = getFileContent(
tree, tree,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents).toContain('RouterModule.forRoot(['); expect(moduleContents).toContain('RouterModule.forRoot([');
expect(moduleContents).toContain(`{ expect(moduleContents).toContain(
path: 'my-dir-my-lib', `{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule' );
}`);
const tsConfigAppJson = JSON.parse( const tsConfigAppJson = JSON.parse(
stripJsonComments( stripJsonComments(
@ -512,8 +475,7 @@ describe('lib', () => {
'../../libs/my-dir/my-lib/src/index.ts' '../../libs/my-dir/my-lib/src/index.ts'
]); ]);
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib2', name: 'myLib2',
@ -523,21 +485,21 @@ describe('lib', () => {
parentModule: 'apps/myapp/src/app/app.module.ts' parentModule: 'apps/myapp/src/app/app.module.ts'
}, },
tree tree
) );
.toPromise();
const moduleContents2 = getFileContent( const moduleContents2 = getFileContent(
tree2, tree2,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents2).toContain('RouterModule.forRoot(['); expect(moduleContents2).toContain('RouterModule.forRoot([');
expect(moduleContents2).toContain(`{ expect(moduleContents2).toContain(
path: 'my-dir-my-lib', `{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule' );
}`); expect(moduleContents2).toContain(
expect(moduleContents2).toContain(`{ `{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
path: 'my-dir-my-lib2', );
loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module' expect(moduleContents2).toContain(
}`); `{path: 'my-dir-my-lib2', loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module'}`
);
const tsConfigAppJson2 = JSON.parse( const tsConfigAppJson2 = JSON.parse(
stripJsonComments( stripJsonComments(
@ -550,8 +512,7 @@ describe('lib', () => {
'../../libs/my-dir/my-lib2/src/index.ts' '../../libs/my-dir/my-lib2/src/index.ts'
]); ]);
const tree3 = await schematicRunner const tree3 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib3', name: 'myLib3',
@ -562,23 +523,20 @@ describe('lib', () => {
simpleModuleName: true simpleModuleName: true
}, },
tree2 tree2
) );
.toPromise();
const moduleContents3 = getFileContent( const moduleContents3 = getFileContent(
tree3, tree3,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents3).toContain('RouterModule.forRoot(['); expect(moduleContents3).toContain('RouterModule.forRoot([');
expect(moduleContents3).toContain(`{
path: 'my-dir-my-lib',
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'
}`);
expect(moduleContents3).toContain(`{
path: 'my-dir-my-lib2',
loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module'
}`);
expect(moduleContents3).toContain( expect(moduleContents3).toContain(
`{ path: 'my-lib3', loadChildren: '@proj/my-dir/my-lib3#MyLib3Module' }` `{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
);
expect(moduleContents3).toContain(
`{path: 'my-dir-my-lib2', loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module'}`
);
expect(moduleContents3).toContain(
`{path: 'my-lib3', loadChildren: '@proj/my-dir/my-lib3#MyLib3Module'}`
); );
const tsConfigAppJson3 = JSON.parse( const tsConfigAppJson3 = JSON.parse(
@ -597,13 +555,11 @@ describe('lib', () => {
describe('eager', () => { describe('eager', () => {
it('should add RouterModule and define an array of routes', async () => { it('should add RouterModule and define an array of routes', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', directory: 'myDir', routing: true }, { name: 'myLib', directory: 'myDir', routing: true },
appTree appTree
) );
.toPromise();
expect( expect(
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts') tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts')
).toBeTruthy(); ).toBeTruthy();
@ -620,8 +576,7 @@ describe('lib', () => {
) )
).toContain('const myDirMyLibRoutes: Route[] = '); ).toContain('const myDirMyLibRoutes: Route[] = ');
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib2', name: 'myLib2',
@ -630,8 +585,7 @@ describe('lib', () => {
simpleModuleName: true simpleModuleName: true
}, },
tree tree
) );
.toPromise();
expect( expect(
tree2.exists('libs/my-dir/my-lib2/src/lib/my-lib2.module.ts') tree2.exists('libs/my-dir/my-lib2/src/lib/my-lib2.module.ts')
).toBeTruthy(); ).toBeTruthy();
@ -645,8 +599,7 @@ describe('lib', () => {
it('should update the parent module', async () => { it('should update the parent module', async () => {
appTree = createApp(appTree, 'myapp'); appTree = createApp(appTree, 'myapp');
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib', name: 'myLib',
@ -655,19 +608,17 @@ describe('lib', () => {
parentModule: 'apps/myapp/src/app/app.module.ts' parentModule: 'apps/myapp/src/app/app.module.ts'
}, },
appTree appTree
) );
.toPromise();
const moduleContents = getFileContent( const moduleContents = getFileContent(
tree, tree,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents).toContain('RouterModule.forRoot(['); expect(moduleContents).toContain('RouterModule.forRoot([');
expect(moduleContents).toContain( expect(moduleContents).toContain(
"{ path: 'my-dir-my-lib', children: myDirMyLibRoutes }" "{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
); );
const tree2 = await schematicRunner const tree2 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib2', name: 'myLib2',
@ -676,22 +627,20 @@ describe('lib', () => {
parentModule: 'apps/myapp/src/app/app.module.ts' parentModule: 'apps/myapp/src/app/app.module.ts'
}, },
tree tree
) );
.toPromise();
const moduleContents2 = getFileContent( const moduleContents2 = getFileContent(
tree2, tree2,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents2).toContain('RouterModule.forRoot(['); expect(moduleContents2).toContain('RouterModule.forRoot([');
expect(moduleContents2).toContain( expect(moduleContents2).toContain(
"{ path: 'my-dir-my-lib', children: myDirMyLibRoutes }" "{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
); );
expect(moduleContents2).toContain( expect(moduleContents2).toContain(
"{ path: 'my-dir-my-lib2', children: myDirMyLib2Routes }" "{path: 'my-dir-my-lib2', children: myDirMyLib2Routes}"
); );
const tree3 = await schematicRunner const tree3 = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ {
name: 'myLib3', name: 'myLib3',
@ -701,21 +650,20 @@ describe('lib', () => {
simpleModuleName: true simpleModuleName: true
}, },
tree2 tree2
) );
.toPromise();
const moduleContents3 = getFileContent( const moduleContents3 = getFileContent(
tree3, tree3,
'apps/myapp/src/app/app.module.ts' 'apps/myapp/src/app/app.module.ts'
); );
expect(moduleContents3).toContain('RouterModule.forRoot(['); expect(moduleContents3).toContain('RouterModule.forRoot([');
expect(moduleContents3).toContain( expect(moduleContents3).toContain(
"{ path: 'my-dir-my-lib', children: myDirMyLibRoutes }" "{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
); );
expect(moduleContents3).toContain( expect(moduleContents3).toContain(
"{ path: 'my-dir-my-lib2', children: myDirMyLib2Routes }" "{path: 'my-dir-my-lib2', children: myDirMyLib2Routes}"
); );
expect(moduleContents3).toContain( expect(moduleContents3).toContain(
"{ path: 'my-lib3', children: myLib3Routes }" "{path: 'my-lib3', children: myLib3Routes}"
); );
}); });
}); });
@ -723,9 +671,11 @@ describe('lib', () => {
describe('--style scss', () => { describe('--style scss', () => {
it('should set it as default', async () => { it('should set it as default', async () => {
const result = await schematicRunner const result = await runSchematic(
.runSchematicAsync('lib', { name: 'myLib', style: 'scss' }, appTree) 'lib',
.toPromise(); { name: 'myLib', style: 'scss' },
appTree
);
const angularJson = readJsonInTree(result, 'angular.json'); const angularJson = readJsonInTree(result, 'angular.json');
@ -739,13 +689,11 @@ describe('lib', () => {
describe('--unit-test-runner jest', () => { describe('--unit-test-runner jest', () => {
it('should generate jest configuration', async () => { it('should generate jest configuration', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', unitTestRunner: 'jest' }, { name: 'myLib', unitTestRunner: 'jest' },
appTree appTree
) );
.toPromise();
expect(resultTree.exists('libs/my-lib/src/test.ts')).toBeFalsy(); expect(resultTree.exists('libs/my-lib/src/test.ts')).toBeFalsy();
expect(resultTree.exists('libs/my-lib/src/test-setup.ts')).toBeTruthy(); expect(resultTree.exists('libs/my-lib/src/test-setup.ts')).toBeTruthy();
expect(resultTree.exists('libs/my-lib/tsconfig.spec.json')).toBeTruthy(); expect(resultTree.exists('libs/my-lib/tsconfig.spec.json')).toBeTruthy();
@ -763,26 +711,22 @@ describe('lib', () => {
}); });
it('should skip the setup file if no module is generated', async () => { it('should skip the setup file if no module is generated', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', unitTestRunner: 'jest', module: false }, { name: 'myLib', unitTestRunner: 'jest', module: false },
appTree appTree
) );
.toPromise();
expect(resultTree.exists('libs/my-lib/src/test-setup.ts')).toBeFalsy(); expect(resultTree.exists('libs/my-lib/src/test-setup.ts')).toBeFalsy();
}); });
}); });
describe('--unit-test-runner none', () => { describe('--unit-test-runner none', () => {
it('should not generate test configuration', async () => { it('should not generate test configuration', async () => {
const resultTree = await schematicRunner const resultTree = await runSchematic(
.runSchematicAsync(
'lib', 'lib',
{ name: 'myLib', unitTestRunner: 'none' }, { name: 'myLib', unitTestRunner: 'none' },
appTree appTree
) );
.toPromise();
expect( expect(
resultTree.exists('libs/my-lib/src/lib/my-lib.module.spec.ts') resultTree.exists('libs/my-lib/src/lib/my-lib.module.spec.ts')
).toBeFalsy(); ).toBeFalsy();

View File

@ -1,13 +1,9 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { schematicRunner } from '@nrwl/schematics/src/utils/testing-utils';
describe('workspace', () => { describe('workspace', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {

View File

@ -14,15 +14,11 @@ import {
createEmptyWorkspace, createEmptyWorkspace,
AppConfig, AppConfig,
getLibConfig, getLibConfig,
getAppConfig getAppConfig,
runSchematic
} from '../../utils/testing-utils'; } from '../../utils/testing-utils';
describe('ngrx', () => { describe('ngrx', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -32,8 +28,7 @@ describe('ngrx', () => {
}); });
it('should add empty root', async () => { it('should add empty root', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
@ -41,8 +36,7 @@ describe('ngrx', () => {
onlyEmptyRoot: true onlyEmptyRoot: true
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect( expect(
@ -51,14 +45,13 @@ describe('ngrx', () => {
expect(appModule).toContain('StoreModule.forRoot('); expect(appModule).toContain('StoreModule.forRoot(');
expect(appModule).toContain( expect(appModule).toContain(
'{ metaReducers: !environment.production ? [storeFreeze] : [] }' '{ metaReducers : !environment.production ? [storeFreeze] : [] }'
); );
expect(appModule).toContain('EffectsModule.forRoot'); expect(appModule).toContain('EffectsModule.forRoot');
}); });
it('should add root', async () => { it('should add root', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'app', name: 'app',
@ -66,8 +59,7 @@ describe('ngrx', () => {
root: true root: true
}, },
appTree appTree
) );
.toPromise();
[ [
'/apps/myapp/src/app/+state/app.actions.ts', '/apps/myapp/src/app/+state/app.actions.ts',
@ -96,12 +88,11 @@ describe('ngrx', () => {
expect(appModule).toContain('!environment.production ? [storeFreeze] : []'); expect(appModule).toContain('!environment.production ? [storeFreeze] : []');
expect(appModule).toContain('app: appReducer'); expect(appModule).toContain('app: appReducer');
expect(appModule).toContain('initialState: { app: appInitialState }'); expect(appModule).toContain('initialState : { app : appInitialState }');
}); });
it('should add facade to root', async () => { it('should add facade to root', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'app', name: 'app',
@ -110,8 +101,7 @@ describe('ngrx', () => {
facade: true facade: true
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
@ -125,7 +115,7 @@ describe('ngrx', () => {
expect(appModule).toContain('providers: [AppFacade]'); expect(appModule).toContain('providers: [AppFacade]');
expect(appModule).toContain('app: appReducer'); expect(appModule).toContain('app: appReducer');
expect(appModule).toContain('initialState: { app: appInitialState }'); expect(appModule).toContain('initialState : { app : appInitialState }');
[ [
'/apps/myapp/src/app/+state/app.actions.ts', '/apps/myapp/src/app/+state/app.actions.ts',
@ -144,8 +134,7 @@ describe('ngrx', () => {
it('should not add RouterStoreModule only if the module does not reference the router', async () => { it('should not add RouterStoreModule only if the module does not reference the router', async () => {
const newTree = createApp(appTree, 'myapp-norouter', false); const newTree = createApp(appTree, 'myapp-norouter', false);
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'app', name: 'app',
@ -153,8 +142,7 @@ describe('ngrx', () => {
root: true root: true
}, },
newTree newTree
) );
.toPromise();
const appModule = getFileContent( const appModule = getFileContent(
tree, tree,
'/apps/myapp-norouter/src/app/app.module.ts' '/apps/myapp-norouter/src/app/app.module.ts'
@ -163,16 +151,14 @@ describe('ngrx', () => {
}); });
it('should add feature', async () => { it('should add feature', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
module: 'apps/myapp/src/app/app.module.ts' module: 'apps/myapp/src/app/app.module.ts'
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect(appModule).toContain('StoreModule.forFeature'); expect(appModule).toContain('StoreModule.forFeature');
@ -189,8 +175,7 @@ describe('ngrx', () => {
}); });
it('should add with custom directoryName', async () => { it('should add with custom directoryName', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
@ -198,8 +183,7 @@ describe('ngrx', () => {
directory: 'myCustomState' directory: 'myCustomState'
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect(appModule).toContain('StoreModule.forFeature'); expect(appModule).toContain('StoreModule.forFeature');
@ -214,8 +198,7 @@ describe('ngrx', () => {
}); });
it('should only add files', async () => { it('should only add files', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
@ -224,8 +207,7 @@ describe('ngrx', () => {
facade: true facade: true
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect(appModule).not.toContain('StoreModule'); expect(appModule).not.toContain('StoreModule');
@ -247,16 +229,14 @@ describe('ngrx', () => {
}); });
it('should update package.json', async () => { it('should update package.json', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
module: 'apps/myapp/src/app/app.module.ts' module: 'apps/myapp/src/app/app.module.ts'
}, },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, 'package.json'); const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.dependencies['@ngrx/store']).toBeDefined(); expect(packageJson.dependencies['@ngrx/store']).toBeDefined();
@ -268,16 +248,14 @@ describe('ngrx', () => {
it('should error when no module is provided', async () => { it('should error when no module is provided', async () => {
try { try {
await schematicRunner await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
module: '' module: ''
}, },
appTree appTree
) );
.toPromise();
fail(); fail();
} catch (e) { } catch (e) {
expect(e.message).toEqual('The required --module option must be passed'); expect(e.message).toEqual('The required --module option must be passed');
@ -286,16 +264,14 @@ describe('ngrx', () => {
it('should error the module could not be found', async () => { it('should error the module could not be found', async () => {
try { try {
await schematicRunner await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'state', name: 'state',
module: 'does-not-exist.ts' module: 'does-not-exist.ts'
}, },
appTree appTree
) );
.toPromise();
} catch (e) { } catch (e) {
expect(e.message).toEqual('Path does not exist: does-not-exist.ts'); expect(e.message).toEqual('Path does not exist: does-not-exist.ts');
} }
@ -347,9 +323,9 @@ describe('ngrx', () => {
expect(content).toContain('UsersActionTypes'); expect(content).toContain('UsersActionTypes');
expect(content).toContain("LoadUsers = '[Users] Load Users'"); expect(content).toContain(`LoadUsers = "[Users] Load Users"`);
expect(content).toContain("UsersLoaded = '[Users] Users Loaded'"); expect(content).toContain(`UsersLoaded = "[Users] Users Loaded"`);
expect(content).toContain("UsersLoadError = '[Users] Users Load Error'"); expect(content).toContain(`UsersLoadError = "[Users] Users Load Error"`);
expect(content).toContain('class LoadUsers implements Action'); expect(content).toContain('class LoadUsers implements Action');
expect(content).toContain('class UsersLoaded implements Action'); expect(content).toContain('class UsersLoaded implements Action');
@ -422,12 +398,7 @@ describe('ngrx', () => {
[ [
`import { DataPersistence } from \'@nrwl/nx\'`, `import { DataPersistence } from \'@nrwl/nx\'`,
`import { `import { LoadUsers, UsersLoaded, UsersLoadError, UsersActionTypes } from './users.actions';`,
LoadUsers,
UsersLoaded,
UsersLoadError,
UsersActionTypes
} from \'./users.actions\';`,
`loadUsers$`, `loadUsers$`,
`run: (action: LoadUsers, state: UsersPartialState)`, `run: (action: LoadUsers, state: UsersPartialState)`,
`return new UsersLoaded([])`, `return new UsersLoaded([])`,
@ -457,8 +428,7 @@ describe('ngrx', () => {
it('should update the barrel API with exports for ngrx facade, selector, and reducer', async () => { it('should update the barrel API with exports for ngrx facade, selector, and reducer', async () => {
appTree = createLib(appTree, 'flights'); appTree = createLib(appTree, 'flights');
let libConfig = getLibConfig(); let libConfig = getLibConfig();
let tree = await schematicRunner let tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'super-users', name: 'super-users',
@ -466,8 +436,7 @@ describe('ngrx', () => {
facade: true facade: true
}, },
appTree appTree
) );
.toPromise();
const barrel = tree.readContent(libConfig.barrel); const barrel = tree.readContent(libConfig.barrel);
expect(barrel).toContain( expect(barrel).toContain(
@ -478,8 +447,7 @@ describe('ngrx', () => {
it('should not update the barrel API with a facade', async () => { it('should not update the barrel API with a facade', async () => {
appTree = createLib(appTree, 'flights'); appTree = createLib(appTree, 'flights');
let libConfig = getLibConfig(); let libConfig = getLibConfig();
let tree = await schematicRunner let tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'super-users', name: 'super-users',
@ -487,8 +455,7 @@ describe('ngrx', () => {
facade: false facade: false
}, },
appTree appTree
) );
.toPromise();
const barrel = tree.readContent(libConfig.barrel); const barrel = tree.readContent(libConfig.barrel);
expect(barrel).not.toContain( expect(barrel).not.toContain(
@ -498,16 +465,14 @@ describe('ngrx', () => {
it('should produce proper tests for the ngrx reducer for a name with a dash', async () => { it('should produce proper tests for the ngrx reducer for a name with a dash', async () => {
const appConfig = getAppConfig(); const appConfig = getAppConfig();
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: 'super-users', name: 'super-users',
module: appConfig.appModule module: appConfig.appModule
}, },
appTree appTree
) );
.toPromise();
const statePath = `${findModuleParent(appConfig.appModule)}/+state`; const statePath = `${findModuleParent(appConfig.appModule)}/+state`;
const contents = tree.readContent( const contents = tree.readContent(
@ -526,8 +491,7 @@ describe('ngrx', () => {
featureName: string = 'user', featureName: string = 'user',
withFacade = false withFacade = false
): Promise<UnitTestTree> { ): Promise<UnitTestTree> {
return await schematicRunner return await runSchematic(
.runSchematicAsync(
'ngrx', 'ngrx',
{ {
name: featureName, name: featureName,
@ -535,7 +499,6 @@ describe('ngrx', () => {
facade: withFacade facade: withFacade
}, },
appTree appTree
) );
.toPromise();
} }
}); });

View File

@ -1,18 +1,16 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '../../utils/testing-utils'; import {
createEmptyWorkspace,
schematicRunner
} from '../../utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test'; import { getFileContent } from '@schematics/angular/utility/test';
import * as stripJsonComments from 'strip-json-comments'; import * as stripJsonComments from 'strip-json-comments';
import { readJsonInTree } from '../../utils/ast-utils'; import { readJsonInTree } from '../../utils/ast-utils';
import { NxJson } from '../../command-line/shared'; import { NxJson } from '../../command-line/shared';
describe('node-app', () => { describe('node-app', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,15 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createApp, createEmptyWorkspace } from '../../utils/testing-utils'; import {
createApp,
createEmptyWorkspace,
runSchematic
} from '../../utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test'; import { getFileContent } from '@schematics/angular/utility/test';
import { readJsonInTree } from '../../utils/ast-utils'; import { readJsonInTree } from '../../utils/ast-utils';
describe('upgrade-module', () => { describe('upgrade-module', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -20,16 +19,14 @@ describe('upgrade-module', () => {
}); });
it('should update the bootstrap logic', async () => { it('should update the bootstrap logic', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'upgrade-module', 'upgrade-module',
{ {
name: 'legacy', name: 'legacy',
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts'); const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect(appModule).toContain( expect(appModule).toContain(
@ -53,16 +50,14 @@ describe('upgrade-module', () => {
}) })
); );
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'upgrade-module', 'upgrade-module',
{ {
name: 'legacy', name: 'legacy',
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, '/package.json'); const packageJson = readJsonInTree(tree, '/package.json');
expect(packageJson.dependencies['@angular/upgrade']).toEqual('4.4.4'); expect(packageJson.dependencies['@angular/upgrade']).toEqual('4.4.4');
@ -79,8 +74,7 @@ describe('upgrade-module', () => {
}) })
); );
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'upgrade-module', 'upgrade-module',
{ {
name: 'legacy', name: 'legacy',
@ -88,16 +82,14 @@ describe('upgrade-module', () => {
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const packageJson = readJsonInTree(tree, '/package.json'); const packageJson = readJsonInTree(tree, '/package.json');
expect(packageJson.dependencies['@angular/upgrade']).not.toBeDefined(); expect(packageJson.dependencies['@angular/upgrade']).not.toBeDefined();
}); });
it('should add router configuration when --router=true', async () => { it('should add router configuration when --router=true', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'upgrade-module', 'upgrade-module',
{ {
name: 'legacy', name: 'legacy',
@ -105,16 +97,14 @@ describe('upgrade-module', () => {
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const legacySetup = getFileContent(tree, '/apps/myapp/src/legacy-setup.ts'); const legacySetup = getFileContent(tree, '/apps/myapp/src/legacy-setup.ts');
expect(legacySetup).toContain(`setUpLocationSync`); expect(legacySetup).toContain(`setUpLocationSync`);
}); });
it('should support custom angularJsImport', async () => { it('should support custom angularJsImport', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync(
'upgrade-module', 'upgrade-module',
{ {
name: 'legacy', name: 'legacy',
@ -122,8 +112,7 @@ describe('upgrade-module', () => {
project: 'myapp' project: 'myapp'
}, },
appTree appTree
) );
.toPromise();
const legacySetup = getFileContent(tree, '/apps/myapp/src/legacy-setup.ts'); const legacySetup = getFileContent(tree, '/apps/myapp/src/legacy-setup.ts');
expect(legacySetup).toContain(`import 'legacy-app';`); expect(legacySetup).toContain(`import 'legacy-app';`);

View File

@ -1,14 +1,9 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '../../utils/testing-utils'; import { createEmptyWorkspace, runSchematic } from '../../utils/testing-utils';
describe('workspace-schematic', () => { describe('workspace-schematic', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree; let appTree: Tree;
beforeEach(() => { beforeEach(() => {
@ -17,9 +12,11 @@ describe('workspace-schematic', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const tree = await schematicRunner const tree = await runSchematic(
.runSchematicAsync('workspace-schematic', { name: 'custom' }, appTree) 'workspace-schematic',
.toPromise(); { name: 'custom' },
appTree
);
expect(tree.exists('tools/schematics/custom/index.ts')).toBeTruthy(); expect(tree.exists('tools/schematics/custom/index.ts')).toBeTruthy();
expect(tree.exists('tools/schematics/custom/schema.json')).toBeTruthy(); expect(tree.exists('tools/schematics/custom/schema.json')).toBeTruthy();
}); });

View File

@ -8,8 +8,8 @@ import {
} from '@angular-devkit/schematics'; } from '@angular-devkit/schematics';
import { format, resolveConfig, getFileInfo } from 'prettier'; import { format, resolveConfig, getFileInfo } from 'prettier';
import * as appRoot from 'app-root-path'; import * as appRoot from 'app-root-path';
import { from } from 'rxjs'; import { from, Observable } from 'rxjs';
import { filter, map, mergeMap } from 'rxjs/operators'; import { concatMap, delay, filter, map, mergeMap } from 'rxjs/operators';
export function formatFiles( export function formatFiles(
options: { skipFormat: boolean } = { skipFormat: false } options: { skipFormat: boolean } = { skipFormat: false }

View File

@ -1,6 +1,11 @@
import { Tree } from '@angular-devkit/schematics'; import { Tree } from '@angular-devkit/schematics';
import { names } from './name-utils'; import { names } from './name-utils';
import { NxJson } from '../command-line/shared'; import { NxJson } from '../command-line/shared';
import {
SchematicTestRunner,
UnitTestTree
} from '@angular-devkit/schematics/testing';
import * as path from 'path';
export interface AppConfig { export interface AppConfig {
appName: string; // name of app appName: string; // name of app
@ -22,6 +27,21 @@ export function getLibConfig(): LibConfig {
return libConfig; return libConfig;
} }
export const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../collection.json')
);
export function runSchematic(
name: string,
options: any,
tree: Tree
): Promise<UnitTestTree> {
return schematicRunner
.runSchematicAsync(name, { ...options, skipFormat: true }, tree)
.toPromise();
}
export function createEmptyWorkspace(tree: Tree): Tree { export function createEmptyWorkspace(tree: Tree): Tree {
tree.create( tree.create(
'/angular.json', '/angular.json',

17
scripts/check_format.sh Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
echo "Checking prettier"
prettier "**/*.{ts,js,json,css,scss}" "!**/{__name__,__directory__}/**" --list-different
PRETTIER_STATUS=$?
echo "Checking CRLF"
find scripts -type f -exec file "{}" ";" | grep CRLF
SCRIPTS_STATUS=$?
find packages -type f -exec file "{}" ";" | grep CRLF
PACKAGES_STATUS=$?
if [[ $PRETTIER_STATUS -eq 1 || $SCRIPTS_STATUS -eq 0 || $PACKAGES_STATUS -eq 0 ]]; then
echo "Please run yarn format";
exit 1;
fi

View File

@ -9,3 +9,5 @@ if [ -n "$1" ]; then
else else
jest --maxWorkers=1 ./build/e2e/schematics jest --maxWorkers=1 ./build/e2e/schematics
fi fi

8
scripts/format.sh Normal file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
echo "Prettier"
prettier "**/*.{ts,js,json,css,scss,md}" "!**/{__name__,__directory__}/**" --write
echo "Line endings"
find packages -type f -print0 | xargs -0 dos2unix
find scripts -type f -print0 | xargs -0 dos2unix

View File

@ -3,9 +3,11 @@
if [ "$1" = "fast" ]; then if [ "$1" = "fast" ]; then
./scripts/build_for_test.sh ./scripts/build_for_test.sh
fi fi
if [ "$1" != "fast" ]; then if [ "$1" != "fast" ]; then
./scripts/build.sh ./scripts/build.sh
fi fi
rm -rf node_modules/@nrwl rm -rf node_modules/@nrwl
cp -r build/packages node_modules/@nrwl cp -r build/packages node_modules/@nrwl

View File

@ -19,7 +19,6 @@
"exclude": [ "exclude": [
"tmp", "tmp",
"build", "build",
"node_modules",
"packages/bazel", "packages/bazel",
"packages/schematics/src/*/files/**/*" "packages/schematics/src/*/files/**/*"
], ],