Skip to content

fix: throws an error if app building fails #85

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
Dec 19, 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
27 changes: 25 additions & 2 deletions src/deploy/actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonObject, logging } from '@angular-devkit/core';
import { BuilderContext, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
import { BuilderContext, BuilderOutput, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
import deploy from './actions';

let context: BuilderContext;
Expand Down Expand Up @@ -53,6 +53,18 @@ describe('Deploy Angular apps', () => {
expect(e.message).toMatch(/Cannot execute the build target/);
}
});

it('throws if app building fails', async () => {
context.scheduleTarget = (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({
result: Promise.resolve(createBuilderOutputMock(false, 'build error test')),
} as BuilderRun);
try {
await deploy(mockEngine, context, 'host', {});
fail();
} catch (e) {
expect(e.message).toMatch(/build error test/);
}
});
});
});

Expand Down Expand Up @@ -81,6 +93,17 @@ const initMocks = () => {
reportStatus: (_: string) => { },
reportRunning: () => { },
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun),
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun)
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({
result: Promise.resolve(createBuilderOutputMock(true, '')),
} as BuilderRun)
};
};

const createBuilderOutputMock = (success: boolean, error: string): BuilderOutput => {
return {
info: { 'info': null },
error: error,
success: success,
target: {} as Target,
};
};
6 changes: 5 additions & 1 deletion src/deploy/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default async function deploy(
project: context.target.project,
configuration
}, overrides as json.JsonObject);
await build.result;
const buildResult = await build.result;

if (!buildResult.success) {
throw new Error(buildResult.error);
}
}

await engine.run(
Expand Down