tests(schematic): add back unit tests for ng-add
This commit is contained in:
parent
efe38c47a7
commit
ac7cc3b113
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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,7 +57,6 @@ xdescribe('workspace', () => {
|
||||
});
|
||||
|
||||
it('should error if the angular.json specifies more than one app', () => {
|
||||
expect(() => {
|
||||
appTree.create('/package.json', JSON.stringify({}));
|
||||
appTree.create('/e2e/protractor.conf.js', '');
|
||||
appTree.create(
|
||||
@ -50,6 +70,7 @@ xdescribe('workspace', () => {
|
||||
}
|
||||
})
|
||||
);
|
||||
expect(() => {
|
||||
schematicRunner.runSchematic('ng-add', { name: 'myApp' }, appTree);
|
||||
}).toThrow('Can only convert projects with one app');
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user