diff --git a/e2e/schematics/application.test.ts b/e2e/schematics/application.test.ts index b862877343577..18a7689a8dee9 100644 --- a/e2e/schematics/application.test.ts +++ b/e2e/schematics/application.test.ts @@ -37,7 +37,9 @@ describe('Nrwl Workspace', () => { () => { newProject(); newApp('myApp --directory=myDir --routing'); - newLib('myLib --directory=myDir --routing --lazy --parentModule=apps/my-dir/my-app/src/app/app.module.ts'); + newLib( + 'myLib --directory=myDir --routing --lazy --parentModule=apps/my-dir/my-app/src/app/app.module.ts' + ); runCLI('build --aot -a=my-dir/my-app'); expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS'); @@ -50,7 +52,9 @@ describe('Nrwl Workspace', () => { () => { newProject(); newApp('myApp --directory=myDir --routing'); - newLib('myLib --directory=myDir --routing --parentModule=apps/my-dir/my-app/src/app/app.module.ts'); + newLib( + 'myLib --directory=myDir --routing --parentModule=apps/my-dir/my-app/src/app/app.module.ts' + ); runCLI('build --aot -a=my-dir/my-app'); expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS'); diff --git a/e2e/schematics/bazel-application.test.ts b/e2e/schematics/bazel-application.test.ts index 493476aa971bd..1b15b6708ce18 100644 --- a/e2e/schematics/bazel-application.test.ts +++ b/e2e/schematics/bazel-application.test.ts @@ -1,4 +1,11 @@ -import {checkFilesExist, newApp, newBazelProject, newLib, runCLI, updateFile} from '../utils'; +import { + checkFilesExist, + newApp, + newBazelProject, + newLib, + runCLI, + updateFile +} from '../utils'; xdescribe('Nrwl Workspace (Bazel)', () => { it( diff --git a/e2e/schematics/command-line.test.ts b/e2e/schematics/command-line.test.ts index 654ac288b048d..77e88e06b5bbe 100644 --- a/e2e/schematics/command-line.test.ts +++ b/e2e/schematics/command-line.test.ts @@ -1,4 +1,12 @@ -import { newApp, newLib, newProject, readFile, runCLI, runCommand, updateFile } from '../utils'; +import { + newApp, + newLib, + newProject, + readFile, + runCLI, + runCommand, + updateFile +} from '../utils'; describe('Command line', () => { it( @@ -13,9 +21,9 @@ describe('Command line', () => { newLib('validtaglib --tags=validtag'); const tslint = JSON.parse(readFile('tslint.json')); - tslint.rules["nx-enforce-module-boundaries"][1].depConstraints = [ - { "sourceTag": "validtag", "onlyDependOnLibsWithTags": ["validtag"] }, - ...tslint.rules["nx-enforce-module-boundaries"][1].depConstraints + tslint.rules['nx-enforce-module-boundaries'][1].depConstraints = [ + { sourceTag: 'validtag', onlyDependOnLibsWithTags: ['validtag'] }, + ...tslint.rules['nx-enforce-module-boundaries'][1].depConstraints ]; updateFile('tslint.json', JSON.stringify(tslint, null, 2)); @@ -38,7 +46,9 @@ describe('Command line', () => { expect(out).toContain('imports of lazy-loaded libraries are forbidden'); expect(out).toContain('deep imports into libraries are forbidden'); expect(out).toContain('imports of apps are forbidden'); - expect(out).toContain('A project tagged with "validtag" can only depend on libs tagged with "validtag"'); + expect(out).toContain( + 'A project tagged with "validtag" can only depend on libs tagged with "validtag"' + ); }, 1000000 ); @@ -59,7 +69,9 @@ describe('Command line', () => { ` ); const checkOut = runCommand('npm run update:check'); - expect(checkOut).toContain('Run "npm run update" to run the following migrations'); + expect(checkOut).toContain( + 'Run "npm run update" to run the following migrations' + ); expect(checkOut).toContain('20200101-test-migration'); const migrateOut = runCommand('npm run update'); @@ -82,7 +94,9 @@ describe('Command line', () => { ); const checkOut2 = runCommand('npm run update:check'); - expect(checkOut2).toContain('Run "npm run update" to run the following migrations'); + expect(checkOut2).toContain( + 'Run "npm run update" to run the following migrations' + ); expect(checkOut2).toContain('20200102-test-migration'); const skipOut = runCommand('npm run update:skip'); @@ -104,16 +118,25 @@ describe('Command line', () => { newApp('myapp2'); newLib('mylib'); - updateFile('apps/myapp/src/app/app.component.spec.ts', `import '@proj/mylib';`); + updateFile( + 'apps/myapp/src/app/app.component.spec.ts', + `import '@proj/mylib';` + ); - const affectedApps = runCommand('npm run affected:apps -- --files="libs/mylib/index.ts"'); + const affectedApps = runCommand( + 'npm run affected:apps -- --files="libs/mylib/index.ts"' + ); expect(affectedApps).toContain('myapp'); expect(affectedApps).not.toContain('myapp2'); - const build = runCommand('npm run affected:build -- --files="libs/mylib/index.ts"'); + const build = runCommand( + 'npm run affected:build -- --files="libs/mylib/index.ts"' + ); expect(build).toContain('Building myapp'); - const e2e = runCommand('npm run affected:e2e -- --files="libs/mylib/index.ts"'); + const e2e = runCommand( + 'npm run affected:e2e -- --files="libs/mylib/index.ts"' + ); expect(e2e).toContain('should display welcome message'); }, 1000000 @@ -161,7 +184,9 @@ describe('Command line', () => { try { // this will group it by lib, so all three files will be "marked" - runCommand('npm run -s format:check -- --files="libs/mylib/index.ts" --libs-and-apps'); + runCommand( + 'npm run -s format:check -- --files="libs/mylib/index.ts" --libs-and-apps' + ); fail('boom'); } catch (e) { expect(e.stdout.toString()).toContain('libs/mylib/index.ts'); @@ -174,8 +199,12 @@ describe('Command line', () => { fail('boom'); } catch (e) { expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts'); - expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.module.ts'); - expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.component.ts'); + expect(e.stdout.toString()).toContain( + 'apps/myapp/src/app/app.module.ts' + ); + expect(e.stdout.toString()).toContain( + 'apps/myapp/src/app/app.component.ts' + ); } runCommand( 'npm run format:write -- --files="apps/myapp/src/app/app.module.ts,apps/myapp/src/app/app.component.ts"' @@ -186,8 +215,12 @@ describe('Command line', () => { fail('boom'); } catch (e) { expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts'); - expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.module.ts'); - expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.component.ts'); + expect(e.stdout.toString()).not.toContain( + 'apps/myapp/src/app/app.module.ts' + ); + expect(e.stdout.toString()).not.toContain( + 'apps/myapp/src/app/app.component.ts' + ); } runCommand('npm run format:write'); diff --git a/e2e/schematics/create-nx-workspace.test.ts b/e2e/schematics/create-nx-workspace.test.ts index 537812d41fa83..65495fc338180 100644 --- a/e2e/schematics/create-nx-workspace.test.ts +++ b/e2e/schematics/create-nx-workspace.test.ts @@ -37,7 +37,9 @@ xdescribe('CreateNxWorkspace', () => { it( 'should create a new workspace with the --directory option', () => { - const res = createNxWorkspace('myproj --npmScope=myscope --directory=proj'); + const res = createNxWorkspace( + 'myproj --npmScope=myscope --directory=proj' + ); expect(res).toContain("Project 'myproj' successfully created."); checkFilesExist('package-lock.json'); }, diff --git a/e2e/schematics/downgrade-module.test.ts b/e2e/schematics/downgrade-module.test.ts index 4a7392b6f1239..79531147dfa7b 100644 --- a/e2e/schematics/downgrade-module.test.ts +++ b/e2e/schematics/downgrade-module.test.ts @@ -7,7 +7,10 @@ describe('DowngradeModule', () => { newProject(); newApp('myapp'); - updateFile('apps/myapp/src/legacy.js', `window.angular.module('legacy', []);`); + updateFile( + 'apps/myapp/src/legacy.js', + `window.angular.module('legacy', []);` + ); runCLI('generate downgrade-module legacy --angularJsImport=./legacy'); diff --git a/e2e/schematics/ngrx.test.ts b/e2e/schematics/ngrx.test.ts index 3ec3b99ffafe5..b4fba9ca670ec 100644 --- a/e2e/schematics/ngrx.test.ts +++ b/e2e/schematics/ngrx.test.ts @@ -6,7 +6,9 @@ describe('ngrx', () => { () => { newProject(); newApp('myapp'); - runCLI('generate ngrx app --module=apps/myapp/src/app/app.module.ts --root --collection=@nrwl/schematics'); + runCLI( + 'generate ngrx app --module=apps/myapp/src/app/app.module.ts --root --collection=@nrwl/schematics' + ); updateFile( 'apps/myapp/src/app/+state/app.interfaces.ts', ` diff --git a/e2e/schematics/upgrade-module.test.ts b/e2e/schematics/upgrade-module.test.ts index 899f743799441..14b1d2b96f1e3 100644 --- a/e2e/schematics/upgrade-module.test.ts +++ b/e2e/schematics/upgrade-module.test.ts @@ -26,7 +26,10 @@ describe('Upgrade', () => { updateFile('apps/myapp/src/app/app.component.spec.ts', ``); - runCLI('generate upgrade-module legacy --angularJsImport=./legacy ' + '--angularJsCmpSelector=rootLegacyCmp'); + runCLI( + 'generate upgrade-module legacy --angularJsImport=./legacy ' + + '--angularJsCmpSelector=rootLegacyCmp' + ); runCLI('build'); runCLI('test --single-run'); diff --git a/e2e/schematics/workspace.test.ts b/e2e/schematics/workspace.test.ts index 9882e7391dd8a..5cec7947d5b7b 100644 --- a/e2e/schematics/workspace.test.ts +++ b/e2e/schematics/workspace.test.ts @@ -1,5 +1,13 @@ -import {checkFilesExist, cleanup, copyMissingPackages, readFile, runCLI, runNgNew, updateFile} from '../utils'; -import {angularCliSchema} from '../../packages/schematics/src/lib-versions'; +import { + checkFilesExist, + cleanup, + copyMissingPackages, + readFile, + runCLI, + runNgNew, + updateFile +} from '../utils'; +import { angularCliSchema } from '../../packages/schematics/src/lib-versions'; describe('Nrwl Convert to Nx Workspace', () => { beforeEach(cleanup); @@ -31,20 +39,30 @@ describe('Nrwl Convert to Nx Workspace', () => { updateFile('.angular-cli.json', JSON.stringify(angularCLIJson, null, 2)); // run the command - runCLI('generate workspace proj --npmScope=proj --collection=@nrwl/schematics'); + runCLI( + 'generate workspace proj --npmScope=proj --collection=@nrwl/schematics' + ); // check that prettier config exits and that files have been moved! - checkFilesExist('.prettierrc', 'apps/proj/src/main.ts', 'apps/proj/src/app/app.module.ts'); + checkFilesExist( + '.prettierrc', + 'apps/proj/src/main.ts', + 'apps/proj/src/app/app.module.ts' + ); // check that package.json got merged const updatedPackageJson = JSON.parse(readFile('package.json')); expect(updatedPackageJson.description).toEqual('some description'); - expect(updatedPackageJson.devDependencies['@nrwl/schematics']).toBeDefined(); + expect( + updatedPackageJson.devDependencies['@nrwl/schematics'] + ).toBeDefined(); expect(updatedPackageJson.dependencies['@nrwl/nx']).toBeDefined(); expect(updatedPackageJson.dependencies['@ngrx/store']).toBeDefined(); expect(updatedPackageJson.dependencies['@ngrx/effects']).toBeDefined(); expect(updatedPackageJson.dependencies['@ngrx/router-store']).toBeDefined(); - expect(updatedPackageJson.dependencies['@ngrx/store-devtools']).toBeDefined(); + expect( + updatedPackageJson.dependencies['@ngrx/store-devtools'] + ).toBeDefined(); // check if angular-cli.json get merged const updatedAngularCLIJson = JSON.parse(readFile('.angular-cli.json')); @@ -54,9 +72,15 @@ describe('Nrwl Convert to Nx Workspace', () => { expect(updatedAngularCLIJson.apps[0].outDir).toEqual('dist/apps/proj'); expect(updatedAngularCLIJson.apps[0].test).toEqual('../../../test.js'); expect(updatedAngularCLIJson.apps[0].tsconfig).toEqual('tsconfig.app.json'); - expect(updatedAngularCLIJson.apps[0].testTsconfig).toEqual('../../../tsconfig.spec.json'); - expect(updatedAngularCLIJson.apps[0].scripts[0]).toEqual('../../../node_modules/x.js'); - expect(updatedAngularCLIJson.defaults.schematics.collection).toEqual('@nrwl/schematics'); + expect(updatedAngularCLIJson.apps[0].testTsconfig).toEqual( + '../../../tsconfig.spec.json' + ); + expect(updatedAngularCLIJson.apps[0].scripts[0]).toEqual( + '../../../node_modules/x.js' + ); + expect(updatedAngularCLIJson.defaults.schematics.collection).toEqual( + '@nrwl/schematics' + ); // check if tsconfig.json get merged const updatedTsConfig = JSON.parse(readFile('tsconfig.json')); @@ -85,11 +109,15 @@ describe('Nrwl Convert to Nx Workspace', () => { runCLI('generate workspace proj --collection=@nrwl/schematics'); // check that dependencies and devDependencies remained the same const packageJson = JSON.parse(readFile('package.json')); - expect(packageJson.devDependencies['@nrwl/schematics']).toEqual(schematicsVersion); + expect(packageJson.devDependencies['@nrwl/schematics']).toEqual( + schematicsVersion + ); expect(packageJson.dependencies['@nrwl/nx']).toEqual(nxVersion); expect(packageJson.dependencies['@ngrx/store']).toEqual(ngrxVersion); expect(packageJson.dependencies['@ngrx/effects']).toEqual(ngrxVersion); expect(packageJson.dependencies['@ngrx/router-store']).toEqual(ngrxVersion); - expect(packageJson.dependencies['@ngrx/store-devtools']).toEqual(ngrxVersion); + expect(packageJson.dependencies['@ngrx/store-devtools']).toEqual( + ngrxVersion + ); }); }); diff --git a/e2e/utils.ts b/e2e/utils.ts index b50c4cb016df6..95b57c88e22d7 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -7,7 +7,7 @@ const projectName: string = 'proj'; export function runNgNew(command?: string, silent?: boolean): string { return execSync(`../node_modules/.bin/ng new proj ${command}`, { cwd: `./tmp`, - ...(silent ? {stdio: ['ignore', 'ignore', 'ignore']} : {}) + ...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}) }).toString(); } @@ -17,10 +17,9 @@ export function newProject(): void { //TODO delete the try catch after 0.8.0 is released try { runNgNew('--collection=@nrwl/schematics --npmScope=proj', true); - } catch (e) { - } + } catch (e) {} copyMissingPackages(); - execSync('npm run postinstall', {cwd: './tmp/proj'}); + execSync('npm run postinstall', { cwd: './tmp/proj' }); execSync('mv ./tmp/proj ./tmp/proj_backup'); } execSync('cp -a ./tmp/proj_backup ./tmp/proj'); @@ -32,10 +31,9 @@ export function newBazelProject(): void { //TODO delete the try catch after 0.8.0 is released try { runNgNew('--collection=@nrwl/bazel --npmScope=proj', true); - } catch (e) { - } + } catch (e) {} copyMissingPackages(); - execSync('npm run postinstall', {cwd: './tmp/proj'}); + execSync('npm run postinstall', { cwd: './tmp/proj' }); execSync('mv ./tmp/proj ./tmp/proj_backup'); } execSync('cp -a ./tmp/proj_backup ./tmp/proj'); @@ -52,7 +50,13 @@ export function createNxWorkspace(command: string): string { } export function copyMissingPackages(): void { - const modulesToCopy = ['@ngrx', 'jasmine-marbles', '@nrwl', 'angular', '@angular/upgrade']; + const modulesToCopy = [ + '@ngrx', + 'jasmine-marbles', + '@nrwl', + 'angular', + '@angular/upgrade' + ]; modulesToCopy.forEach(m => copyNodeModule(projectName, m)); } @@ -72,7 +76,10 @@ export function runCLI( cwd: `./tmp/${projectName}` }) .toString() - .replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); + .replace( + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, + '' + ); } catch (e) { if (opts.silenceError) { return e.stdout.toString(); @@ -107,7 +114,9 @@ export function updateFile(f: string, content: string): void { export function checkFilesExist(...expectedFiles: string[]) { expectedFiles.forEach(f => { - const ff = f.startsWith('/') ? f : path.join(getCwd(), 'tmp', projectName, f); + const ff = f.startsWith('/') + ? f + : path.join(getCwd(), 'tmp', projectName, f); if (!exists(ff)) { throw new Error(`File '${ff}' does not exist`); } diff --git a/packages/bazel/src/collection/app/app.spec.ts b/packages/bazel/src/collection/app/app.spec.ts index 75cfb3cebe922..c68c4ed9db58a 100644 --- a/packages/bazel/src/collection/app/app.spec.ts +++ b/packages/bazel/src/collection/app/app.spec.ts @@ -6,7 +6,10 @@ import { getFileContent } from '@schematics/angular/utility/test'; import * as stripJsonComments from 'strip-json-comments'; describe('app', () => { - const schematicRunner = new SchematicTestRunner('@nrwl/bazel', path.join(__dirname, '../../collection.json')); + const schematicRunner = new SchematicTestRunner( + '@nrwl/bazel', + path.join(__dirname, '../../collection.json') + ); let appTree: Tree; @@ -17,13 +20,22 @@ describe('app', () => { describe('not nested', () => { it('should update angular-cli.json', () => { - const tree = schematicRunner.runSchematic('app', { name: 'myApp', npmScope: 'nrwl' }, appTree); - const updatedAngularCLIJson = JSON.parse(getFileContent(tree, '/.angular-cli.json')); + const tree = schematicRunner.runSchematic( + 'app', + { name: 'myApp', npmScope: 'nrwl' }, + appTree + ); + const updatedAngularCLIJson = JSON.parse( + getFileContent(tree, '/.angular-cli.json') + ); expect(updatedAngularCLIJson.apps).toEqual([ { assets: ['assets', 'favicon.ico'], environmentSource: 'environments/environment.ts', - environments: { dev: 'environments/environment.ts', prod: 'environments/environment.prod.ts' }, + environments: { + dev: 'environments/environment.ts', + prod: 'environments/environment.prod.ts' + }, index: 'index.html', main: 'main.ts', name: 'my-app', @@ -51,18 +63,36 @@ describe('app', () => { }); it('should generate files', () => { - const tree = schematicRunner.runSchematic('app', { name: 'myApp', npmScope: 'nrwl' }, appTree); + const tree = schematicRunner.runSchematic( + 'app', + { name: 'myApp', npmScope: 'nrwl' }, + appTree + ); 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.component.ts')).toBeTruthy(); expect(tree.exists('apps/my-app/e2e/app.po.ts')).toBeTruthy(); - expect(getFileContent(tree, 'apps/my-app/src/app/app.module.ts')).toContain('class AppModule'); + expect( + getFileContent(tree, 'apps/my-app/src/app/app.module.ts') + ).toContain('class AppModule'); - const tsconfigApp = JSON.parse(stripJsonComments(getFileContent(tree, 'apps/my-app/src/tsconfig.app.json'))); - expect(tsconfigApp.compilerOptions.outDir).toEqual('../../../dist/out-tsc/apps/my-app'); + const tsconfigApp = JSON.parse( + stripJsonComments( + getFileContent(tree, 'apps/my-app/src/tsconfig.app.json') + ) + ); + expect(tsconfigApp.compilerOptions.outDir).toEqual( + '../../../dist/out-tsc/apps/my-app' + ); - const tsconfigE2E = JSON.parse(stripJsonComments(getFileContent(tree, 'apps/my-app/e2e/tsconfig.e2e.json'))); - expect(tsconfigE2E.compilerOptions.outDir).toEqual('../../../dist/out-tsc/e2e/my-app'); + const tsconfigE2E = JSON.parse( + stripJsonComments( + getFileContent(tree, 'apps/my-app/e2e/tsconfig.e2e.json') + ) + ); + expect(tsconfigE2E.compilerOptions.outDir).toEqual( + '../../../dist/out-tsc/e2e/my-app' + ); }); }); @@ -73,12 +103,17 @@ describe('app', () => { { name: 'myApp', npmScope: 'nrwl', directory: 'myDir' }, appTree ); - const updatedAngularCLIJson = JSON.parse(getFileContent(tree, '/.angular-cli.json')); + const updatedAngularCLIJson = JSON.parse( + getFileContent(tree, '/.angular-cli.json') + ); expect(updatedAngularCLIJson.apps).toEqual([ { assets: ['assets', 'favicon.ico'], environmentSource: 'environments/environment.ts', - environments: { dev: 'environments/environment.ts', prod: 'environments/environment.prod.ts' }, + environments: { + dev: 'environments/environment.ts', + prod: 'environments/environment.prod.ts' + }, index: 'index.html', main: 'main.ts', name: 'my-dir/my-app', @@ -113,26 +148,46 @@ describe('app', () => { appTree ); expect(tree.exists('apps/my-dir/my-app/src/main.ts')).toBeTruthy(); - expect(tree.exists('apps/my-dir/my-app/src/app/app.module.ts')).toBeTruthy(); - expect(tree.exists('apps/my-dir/my-app/src/app/app.component.ts')).toBeTruthy(); + expect( + tree.exists('apps/my-dir/my-app/src/app/app.module.ts') + ).toBeTruthy(); + expect( + tree.exists('apps/my-dir/my-app/src/app/app.component.ts') + ).toBeTruthy(); expect(tree.exists('apps/my-dir/my-app/e2e/app.po.ts')).toBeTruthy(); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')).toContain('class AppModule'); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts') + ).toContain('class AppModule'); const tsconfigApp = JSON.parse( - stripJsonComments(getFileContent(tree, 'apps/my-dir/my-app/src/tsconfig.app.json')) + stripJsonComments( + getFileContent(tree, 'apps/my-dir/my-app/src/tsconfig.app.json') + ) + ); + expect(tsconfigApp.compilerOptions.outDir).toEqual( + '../../../../dist/out-tsc/apps/my-dir/my-app' ); - expect(tsconfigApp.compilerOptions.outDir).toEqual('../../../../dist/out-tsc/apps/my-dir/my-app'); const tsconfigE2E = JSON.parse( - stripJsonComments(getFileContent(tree, 'apps/my-dir/my-app/e2e/tsconfig.e2e.json')) + stripJsonComments( + getFileContent(tree, 'apps/my-dir/my-app/e2e/tsconfig.e2e.json') + ) + ); + expect(tsconfigE2E.compilerOptions.outDir).toEqual( + '../../../../dist/out-tsc/e2e/my-dir/my-app' ); - expect(tsconfigE2E.compilerOptions.outDir).toEqual('../../../../dist/out-tsc/e2e/my-dir/my-app'); }); }); it('should import NgModule', () => { - const tree = schematicRunner.runSchematic('app', { name: 'myApp', npmScope: 'nrwl', directory: 'myDir' }, appTree); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')).toContain('NxModule.forRoot()'); + const tree = schematicRunner.runSchematic( + 'app', + { name: 'myApp', npmScope: 'nrwl', directory: 'myDir' }, + appTree + ); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts') + ).toContain('NxModule.forRoot()'); }); describe('routing', () => { @@ -142,10 +197,12 @@ describe('app', () => { { name: 'myApp', npmScope: 'nrwl', directory: 'myDir', routing: true }, appTree ); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')).toContain('RouterModule.forRoot'); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.spec.ts')).toContain( - 'imports: [RouterTestingModule]' - ); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts') + ).toContain('RouterModule.forRoot'); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.spec.ts') + ).toContain('imports: [RouterTestingModule]'); }); }); @@ -156,17 +213,24 @@ describe('app', () => { { name: 'myApp', npmScope: 'nrwl', directory: 'myDir' }, appTree ); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts')).not.toContain('encapsulation: '); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts') + ).not.toContain('encapsulation: '); }); it('should set Component encapsulation metadata if option flag is included', () => { const tree = schematicRunner.runSchematic( 'app', - { name: 'myApp', npmScope: 'nrwl', directory: 'myDir', viewEncapsulation: 'Native' }, + { + name: 'myApp', + npmScope: 'nrwl', + directory: 'myDir', + viewEncapsulation: 'Native' + }, appTree ); - expect(getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts')).toContain( - 'encapsulation: ViewEncapsulation.Native' - ); + expect( + getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts') + ).toContain('encapsulation: ViewEncapsulation.Native'); }); }); }); diff --git a/packages/bazel/src/collection/app/index.ts b/packages/bazel/src/collection/app/index.ts index 5b69dad32db9e..797e1138dbd53 100644 --- a/packages/bazel/src/collection/app/index.ts +++ b/packages/bazel/src/collection/app/index.ts @@ -15,15 +15,24 @@ import { SchematicContext } from '@angular-devkit/schematics'; import { Schema } from './schema'; -import {strings} from '@angular-devkit/core'; -import { addImportToModule, insert, addImportToTestBed } from '@nrwl/schematics/src/utils/ast-utils'; +import { strings } from '@angular-devkit/core'; +import { + addImportToModule, + insert, + addImportToTestBed +} from '@nrwl/schematics/src/utils/ast-utils'; import { toFileName } from '@nrwl/schematics/src/utils/name-utils'; import * as ts from 'typescript'; import { addBootstrapToModule } from '@schematics/angular/utility/ast-utils'; import { insertImport } from '@schematics/angular/utility/route-utils'; -import { addApp, serializeJson, cliConfig, readCliConfigFile } from '@nrwl/schematics/src/utils/fileutils'; +import { + addApp, + serializeJson, + cliConfig, + readCliConfigFile +} from '@nrwl/schematics/src/utils/fileutils'; import { offsetFromRoot } from '@nrwl/schematics/src/utils/common'; -import {FormatFiles, wrapIntoFormat} from '@nrwl/schematics/src/utils/tasks'; +import { FormatFiles, wrapIntoFormat } from '@nrwl/schematics/src/utils/tasks'; interface NormalizedSchema extends Schema { fullName: string; @@ -34,11 +43,26 @@ function addBootstrap(path: string): Rule { return (host: Tree) => { const modulePath = `${path}/app/app.module.ts`; const moduleSource = host.read(modulePath)!.toString('utf-8'); - const sourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true); + const sourceFile = ts.createSourceFile( + modulePath, + moduleSource, + ts.ScriptTarget.Latest, + true + ); insert(host, modulePath, [ - insertImport(sourceFile, modulePath, 'BrowserModule', '@angular/platform-browser'), + insertImport( + sourceFile, + modulePath, + 'BrowserModule', + '@angular/platform-browser' + ), ...addImportToModule(sourceFile, modulePath, 'BrowserModule'), - ...addBootstrapToModule(sourceFile, modulePath, 'AppComponent', './app.component') + ...addBootstrapToModule( + sourceFile, + modulePath, + 'AppComponent', + './app.component' + ) ]); return host; }; @@ -48,7 +72,12 @@ function addNxModule(path: string): Rule { return (host: Tree) => { const modulePath = `${path}/app/app.module.ts`; const moduleSource = host.read(modulePath)!.toString('utf-8'); - const sourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true); + const sourceFile = ts.createSourceFile( + modulePath, + moduleSource, + ts.ScriptTarget.Latest, + true + ); insert(host, modulePath, [ insertImport(sourceFile, modulePath, 'NxModule', '@nrwl/nx'), ...addImportToModule(sourceFile, modulePath, 'NxModule.forRoot()') @@ -106,10 +135,19 @@ function addRouterRootConfiguration(path: string): Rule { return (host: Tree) => { const modulePath = `${path}/app/app.module.ts`; const moduleSource = host.read(modulePath)!.toString('utf-8'); - const sourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true); + const sourceFile = ts.createSourceFile( + modulePath, + moduleSource, + ts.ScriptTarget.Latest, + true + ); insert(host, modulePath, [ insertImport(sourceFile, modulePath, 'RouterModule', '@angular/router'), - ...addImportToModule(sourceFile, modulePath, `RouterModule.forRoot([], {initialNavigation: 'enabled'})`) + ...addImportToModule( + sourceFile, + modulePath, + `RouterModule.forRoot([], {initialNavigation: 'enabled'})` + ) ]); const componentSpecPath = `${path}/app/app.component.spec.ts`; @@ -121,8 +159,17 @@ function addRouterRootConfiguration(path: string): Rule { true ); insert(host, componentSpecPath, [ - insertImport(componentSpecSourceFile, componentSpecPath, 'RouterTestingModule', '@angular/router/testing'), - ...addImportToTestBed(componentSpecSourceFile, componentSpecPath, `RouterTestingModule`) + insertImport( + componentSpecSourceFile, + componentSpecPath, + 'RouterTestingModule', + '@angular/router/testing' + ), + ...addImportToTestBed( + componentSpecSourceFile, + componentSpecPath, + `RouterTestingModule` + ) ]); return host; }; @@ -209,7 +256,9 @@ export default function(schema: Schema): Rule { function normalizeOptions(options: Schema): NormalizedSchema { const name = toFileName(options.name); - const fullName = options.directory ? `${toFileName(options.directory)}/${name}` : name; + const fullName = options.directory + ? `${toFileName(options.directory)}/${name}` + : name; const fullPath = `apps/${fullName}/src`; return { ...options, sourceDir: 'src', name, fullName, fullPath }; } diff --git a/packages/bazel/src/collection/app/schema.json b/packages/bazel/src/collection/app/schema.json index f737ca480782b..af74788f5619a 100644 --- a/packages/bazel/src/collection/app/schema.json +++ b/packages/bazel/src/collection/app/schema.json @@ -61,7 +61,5 @@ "default": "css" } }, - "required": [ - "name" - ] + "required": ["name"] } diff --git a/packages/bazel/src/collection/application/application.spec.ts b/packages/bazel/src/collection/application/application.spec.ts index bbc65e7162318..fca6f2f492b58 100644 --- a/packages/bazel/src/collection/application/application.spec.ts +++ b/packages/bazel/src/collection/application/application.spec.ts @@ -4,7 +4,10 @@ import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { getFileContent } from '@schematics/angular/utility/test'; describe('application', () => { - const schematicRunner = new SchematicTestRunner('@nrwl/bazel', path.join(__dirname, '../../collection.json')); + const schematicRunner = new SchematicTestRunner( + '@nrwl/bazel', + path.join(__dirname, '../../collection.json') + ); let appTree: Tree; @@ -13,7 +16,11 @@ describe('application', () => { }); it('should generate files', () => { - const tree = schematicRunner.runSchematic('application', { name: 'myApp', directory: 'my-app' }, appTree); + const tree = schematicRunner.runSchematic( + 'application', + { name: 'myApp', directory: 'my-app' }, + appTree + ); expect(tree.files).toEqual([ '/my-app/BUILD.bazel', '/my-app/README.md', @@ -29,13 +36,19 @@ describe('application', () => { '/my-app/test.js', '/my-app/tsconfig.json', '/my-app/tsconfig.spec.json', - '/my-app/tslint.json', + '/my-app/tslint.json' ]); }); it('should update package.json', () => { - const tree = schematicRunner.runSchematic('application', { name: 'myApp', directory: 'my-app' }, appTree); - const packageJson = JSON.parse(getFileContent(tree, '/my-app/package.json')); + const tree = schematicRunner.runSchematic( + 'application', + { name: 'myApp', directory: 'my-app' }, + appTree + ); + const packageJson = JSON.parse( + getFileContent(tree, '/my-app/package.json') + ); expect(packageJson.devDependencies['@nrwl/schematics']).toBeDefined(); expect(packageJson.dependencies['@nrwl/nx']).toBeDefined(); @@ -46,12 +59,22 @@ describe('application', () => { }); it('should set right npmScope', () => { - const tree = schematicRunner.runSchematic('application', { name: 'myApp', directory: 'my-app' }, appTree); + const tree = schematicRunner.runSchematic( + 'application', + { name: 'myApp', directory: 'my-app' }, + appTree + ); - const angularCliJson = JSON.parse(getFileContent(tree, '/my-app/.angular-cli.json')); + const angularCliJson = JSON.parse( + getFileContent(tree, '/my-app/.angular-cli.json') + ); expect(angularCliJson.project.npmScope).toEqual('myApp'); - const tsconfigJson = JSON.parse(getFileContent(tree, '/my-app/tsconfig.json')); - expect(tsconfigJson.compilerOptions.paths).toEqual({ '@myApp/*': ['libs/*'] }); + const tsconfigJson = JSON.parse( + getFileContent(tree, '/my-app/tsconfig.json') + ); + expect(tsconfigJson.compilerOptions.paths).toEqual({ + '@myApp/*': ['libs/*'] + }); }); });