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
```
### 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
### <a name="submit-issue"></a> Submitting an Issue

View File

@ -4,11 +4,28 @@
<div align="center">
[![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)]()
[![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)]()
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
</div>
<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>
@ -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.
```
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.
@ -60,19 +79,27 @@ npm install -g @angular/cli
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:
```
create-nx-workspace myworkspacename
```
ng
```
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!
@ -91,8 +118,10 @@ You are good to go!
### Talks
- [Angular at Large Organizations](https://www.youtube.com/watch?v=piQ0EZhtus0)
- [Nx: The New Way to Build Enterprise Angular Apps](https://www.youtube.com/watch?v=xo-1SDmvM8Y)
- # Podcasts and Shows
- [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)
- [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
- [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.
- [xplat - Cross-platform tools for Nx workspaces](https://nstudio.io/xplat/)
- 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.
- ## Core Team
| Victor Savkin
## 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
| 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) |
| [vsavkin](https://github.com/vsavkin) | [FrozenPandaz](https://github.com/FrozenPandaz) | [bcabanes](https://github.com/bcabanes) |
| | | |

View File

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

View File

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

View File

@ -1,15 +1,13 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
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 * as path from 'path';
describe('schematic:cypress-project', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/schematics',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree;
beforeEach(() => {
@ -19,13 +17,11 @@ describe('schematic:cypress-project', () => {
describe('generate app --e2e-test-runner=cypress', () => {
it('should not contain any protractor files', async () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
expect(
tree.exists('apps/my-app-e2e/protractor.e2e.json')
@ -41,13 +37,11 @@ describe('schematic:cypress-project', () => {
});
it('should generate files', async () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
expect(tree.exists('apps/my-app-e2e/cypress.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 () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.devDependencies.cypress).toBeDefined();
@ -81,13 +73,11 @@ describe('schematic:cypress-project', () => {
});
it('should add update `angular.json` file', async () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
const angularJson = readJsonInTree(tree, 'angular.json');
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 () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
const cypressJson = readJsonInTree(tree, 'apps/my-app-e2e/cypress.json');
expect(cypressJson).toEqual({
@ -123,13 +111,11 @@ describe('schematic:cypress-project', () => {
});
it('should set right path names in `tsconfig.e2e.json`', async () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress' },
appTree
)
.toPromise();
);
const tsconfigJson = readJsonInTree(
tree,
'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', () => {
it('should set right path names in `cypress.json`', async () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' },
appTree
)
.toPromise();
);
const cypressJson = readJsonInTree(
tree,
'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 () => {
const tree = await schematicRunner
.runSchematicAsync(
const tree = await runSchematic(
'application',
{ name: 'myApp', e2eTestRunner: 'cypress', directory: 'my-dir' },
appTree
)
.toPromise();
);
const tsconfigJson = readJsonInTree(
tree,
'apps/my-dir/my-app-e2e/tsconfig.e2e.json'

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,11 @@
import { Tree } from '@angular-devkit/schematics';
import { names } from './name-utils';
import { NxJson } from '../command-line/shared';
import {
SchematicTestRunner,
UnitTestTree
} from '@angular-devkit/schematics/testing';
import * as path from 'path';
export interface AppConfig {
appName: string; // name of app
@ -22,6 +27,21 @@ export function getLibConfig(): 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 {
tree.create(
'/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
jest --maxWorkers=1 ./build/e2e/schematics
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
./scripts/build_for_test.sh
fi
if [ "$1" != "fast" ]; then
./scripts/build.sh
fi
rm -rf node_modules/@nrwl
cp -r build/packages node_modules/@nrwl

View File

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