Skip to content

Commit

Permalink
fix(@angular-devkit/architect): error out when invalid configurations…
Browse files Browse the repository at this point in the history
… are provided

Fixes #14654
  • Loading branch information
alan-agius4 authored and kyliau committed Jun 10, 2019
1 parent 032409d commit eaae1a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Expand Up @@ -104,8 +104,11 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
if (targetSpec === undefined) {
return null;
}
if (target.configuration && !targetSpec['configurations']) {
throw new Error('Configuration not set in the workspace.');
if (
target.configuration
&& !(targetSpec['configurations'] && targetSpec['configurations'][target.configuration])
) {
throw new Error(`Configuration '${target.configuration}' is not set in the workspace.`);
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/angular_devkit/architect/src/architect.ts
Expand Up @@ -361,7 +361,8 @@ export class Architect {
options: json.JsonObject,
scheduleOptions: ScheduleOptions = {},
): Promise<BuilderRun> {
if (!/^[^:]+:[^:]+$/.test(name)) {
// The below will match 'project:target:configuration'
if (!/^[^:]+:[^:]+(:[^:]+)?$/.test(name)) {
throw new Error('Invalid builder name: ' + JSON.stringify(name));
}

Expand Down
9 changes: 9 additions & 0 deletions packages/angular_devkit/architect/src/index_spec.ts
Expand Up @@ -106,6 +106,15 @@ describe('architect', () => {
await run.stop();
});

it(`errors when target configuration doesn't exists`, async () => {
try {
await architect.scheduleBuilder('test:test:invalid', {});
throw new Error('should have thrown');
} catch (err) {
expect(err.message).toContain('Job name "test:test:invalid" does not exist.');
}
});

it('errors when builder cannot be resolved', async () => {
try {
await architect.scheduleBuilder('non:existent', {});
Expand Down
12 changes: 12 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/unknown-configuration.ts
@@ -0,0 +1,12 @@
import { ng } from "../../utils/process";

export default async function () {
try {
await ng('build', '--configuration', 'invalid');
throw new Error('should have failed.');
} catch (error) {
if (!error.message.includes(`Configuration 'invalid' is not set in the workspace`)) {
throw error;
}
}
};

0 comments on commit eaae1a9

Please sign in to comment.