From ac7cc3b113a613e7abb3bd6ffb98654e9eda5ef4 Mon Sep 17 00:00:00 2001 From: --get Date: Thu, 20 Sep 2018 15:21:08 -0400 Subject: [PATCH] tests(schematic): add back unit tests for ng-add --- .../schematics/src/collection/ng-add/index.ts | 6 ++- .../{workspace.spec.ts => ng-add.spec.ts} | 53 +++++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-) rename packages/schematics/src/collection/ng-add/{workspace.spec.ts => ng-add.spec.ts} (63%) diff --git a/packages/schematics/src/collection/ng-add/index.ts b/packages/schematics/src/collection/ng-add/index.ts index 7d06d60948..3538b8498b 100755 --- a/packages/schematics/src/collection/ng-add/index.ts +++ b/packages/schematics/src/collection/ng-add/index.ts @@ -654,6 +654,10 @@ function checkCanConvertToWorkspace(options: Schema) { throw new Error('Cannot find package.json'); } + if (!host.exists('angular.json')) { + throw new Error('Cannot find angular.json'); + } + // TODO: This restriction should be lited const angularJson = readJsonInTree(host, 'angular.json'); if (Object.keys(angularJson.projects).length > 2) { @@ -682,7 +686,7 @@ function checkCanConvertToWorkspace(options: Schema) { context.logger.error( 'Your workspace could not be converted into an Nx Workspace because of the above error.' ); - throw new Error(); + throw e; } }; } diff --git a/packages/schematics/src/collection/ng-add/workspace.spec.ts b/packages/schematics/src/collection/ng-add/ng-add.spec.ts similarity index 63% rename from packages/schematics/src/collection/ng-add/workspace.spec.ts rename to packages/schematics/src/collection/ng-add/ng-add.spec.ts index 58740ce3a3..a258c0b9f4 100644 --- a/packages/schematics/src/collection/ng-add/workspace.spec.ts +++ b/packages/schematics/src/collection/ng-add/ng-add.spec.ts @@ -2,7 +2,7 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Tree, VirtualTree } from '@angular-devkit/schematics'; -xdescribe('workspace', () => { +describe('workspace', () => { const schematicRunner = new SchematicTestRunner( '@nrwl/schematics', path.join(__dirname, '../../collection.json') @@ -23,8 +23,29 @@ xdescribe('workspace', () => { it('should error if no e2e/protractor.conf.js is present', () => { expect(() => { appTree.create('/package.json', JSON.stringify({})); - schematicRunner.runSchematic('ng-add', { name: 'myApp' }, appTree); - }).toThrow('Cannot find e2e/protractor.conf.js'); + appTree.create( + '/angular.json', + JSON.stringify({ + projects: { + proj1: { + architect: {} + }, + 'proj1-e2e': { + architect: { + e2e: { + options: { + protractorConfig: 'e2e/protractor.conf.js' + } + } + } + } + } + }) + ); + schematicRunner.runSchematic('ng-add', { name: 'proj1' }, appTree); + }).toThrow( + 'An e2e project was specified but e2e/protractor.conf.js could not be found.' + ); }); it('should error if no angular.json is present', () => { @@ -36,20 +57,20 @@ xdescribe('workspace', () => { }); it('should error if the angular.json specifies more than one app', () => { + appTree.create('/package.json', JSON.stringify({})); + appTree.create('/e2e/protractor.conf.js', ''); + appTree.create( + '/angular.json', + JSON.stringify({ + projects: { + proj1: {}, + 'proj1-e2e': {}, + proj2: {}, + 'proj2-e2e': {} + } + }) + ); expect(() => { - appTree.create('/package.json', JSON.stringify({})); - appTree.create('/e2e/protractor.conf.js', ''); - appTree.create( - '/angular.json', - JSON.stringify({ - projects: { - proj1: {}, - 'proj1-e2e': {}, - proj2: {}, - 'proj2-e2e': {} - } - }) - ); schematicRunner.runSchematic('ng-add', { name: 'myApp' }, appTree); }).toThrow('Can only convert projects with one app'); });