fix(core): error when an invalid target/configuration is passed (#5447)

This commit is contained in:
Jason Jean 2021-04-23 14:10:54 -04:00 committed by GitHub
parent ae5722eb50
commit bc7af1d4a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 8 deletions

View File

@ -330,6 +330,44 @@ describe('createTasksForProjectToRun', () => {
]);
});
it('should throw an error for an invalid target', () => {
spyOn(process, 'exit').and.throwError('');
try {
createTasksForProjectToRun(
[projectGraph.nodes.app1],
{
target: 'invalid',
configuration: undefined,
overrides: {},
},
projectGraph,
null
);
fail();
} catch (e) {
expect(process.exit).toHaveBeenCalledWith(1);
}
});
it('should throw an error for an invalid configuration for the initiating project', () => {
spyOn(process, 'exit').and.throwError('');
try {
createTasksForProjectToRun(
[projectGraph.nodes.app1],
{
target: 'serve',
configuration: 'invalid',
overrides: {},
},
projectGraph,
'app1'
);
fail();
} catch (e) {
expect(process.exit).toHaveBeenCalledWith(1);
}
});
it('should throw an error for circular dependencies', () => {
projectGraph.nodes.app1.data.targets.build.dependsOn = [
{

View File

@ -173,6 +173,14 @@ function addTasksForProjectTarget(
tasksMap: Map<string, Task>,
path: string[]
) {
const task = createTask({
project,
target,
configuration,
overrides,
errorIfCannotFindConfiguration,
});
const dependencyConfigs = getDependencyConfigs(
{ project: project.name, target },
defaultDependencyConfigs,
@ -195,13 +203,6 @@ function addTasksForProjectTarget(
);
}
}
const task = createTask({
project,
target,
configuration,
overrides,
errorIfCannotFindConfiguration,
});
tasksMap.set(task.id, task);
}
@ -229,7 +230,7 @@ export function createTask({
if (errorIfCannotFindConfiguration && configuration && !config) {
output.error({
title: `Cannot find configuration '${configuration}' for project '${project.name}'`,
title: `Cannot find configuration '${configuration}' for project '${project.name}:${target}'`,
});
process.exit(1);
}