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');
|
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
|
// TODO: This restriction should be lited
|
||||||
const angularJson = readJsonInTree(host, 'angular.json');
|
const angularJson = readJsonInTree(host, 'angular.json');
|
||||||
if (Object.keys(angularJson.projects).length > 2) {
|
if (Object.keys(angularJson.projects).length > 2) {
|
||||||
@ -682,7 +686,7 @@ function checkCanConvertToWorkspace(options: Schema) {
|
|||||||
context.logger.error(
|
context.logger.error(
|
||||||
'Your workspace could not be converted into an Nx Workspace because of the above 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 * as path from 'path';
|
||||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||||
|
|
||||||
xdescribe('workspace', () => {
|
describe('workspace', () => {
|
||||||
const schematicRunner = new SchematicTestRunner(
|
const schematicRunner = new SchematicTestRunner(
|
||||||
'@nrwl/schematics',
|
'@nrwl/schematics',
|
||||||
path.join(__dirname, '../../collection.json')
|
path.join(__dirname, '../../collection.json')
|
||||||
@ -23,8 +23,29 @@ xdescribe('workspace', () => {
|
|||||||
it('should error if no e2e/protractor.conf.js is present', () => {
|
it('should error if no e2e/protractor.conf.js is present', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
appTree.create('/package.json', JSON.stringify({}));
|
appTree.create('/package.json', JSON.stringify({}));
|
||||||
schematicRunner.runSchematic('ng-add', { name: 'myApp' }, appTree);
|
appTree.create(
|
||||||
}).toThrow('Cannot find e2e/protractor.conf.js');
|
'/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', () => {
|
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', () => {
|
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(() => {
|
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);
|
schematicRunner.runSchematic('ng-add', { name: 'myApp' }, appTree);
|
||||||
}).toThrow('Can only convert projects with one app');
|
}).toThrow('Can only convert projects with one app');
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user