Skip to content

fix(@angular-devkit/architect): error out when invalid configurations are provided #14676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}
}
};