From 072290a130e4b1dff5637515c8d2e29e38e4307a Mon Sep 17 00:00:00 2001 From: masaxsuzu Date: Sun, 1 Dec 2019 03:01:34 +0900 Subject: [PATCH] fix: throws an error if app building fails cherry-pick from e7f6a51392dd97973c98b5420c4903d2bc1e2721 of angular-cli-ghpages/master by @masaxsuzu see https://github.com/angular-schule/angular-cli-ghpages/pull/85 --- src/deploy/actions.spec.ts | 38 ++++++++++++++++++++++++++++++++++++-- src/deploy/actions.ts | 6 +++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/deploy/actions.spec.ts b/src/deploy/actions.spec.ts index 5251b151..28a28007 100644 --- a/src/deploy/actions.spec.ts +++ b/src/deploy/actions.spec.ts @@ -3,7 +3,8 @@ import { BuilderContext, BuilderRun, ScheduleOptions, - Target + Target, + BuilderOutput } from '@angular-devkit/architect/src/index'; import deploy from './actions'; @@ -145,6 +146,25 @@ describe('Deploy Angular apps', () => { ); } }); + + 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, getBuildTarget(), {}); + fail(); + } catch (e) { + expect(e.message).toMatch(/build error test/); + } + }); }); }); @@ -163,7 +183,9 @@ const initMocks = () => { workspaceRoot: 'my/workspace/root', logger: new logging.NullLogger() as any, scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => - Promise.resolve({} as BuilderRun), + Promise.resolve({ + result: Promise.resolve(createBuilderOutputMock(true, '')) + } as BuilderRun), getTargetOptions: (t: Target) => Promise.resolve({ project: `projects/${t.project}/some-file.json`, @@ -173,6 +195,18 @@ const initMocks = () => { } as unknown) as BuilderContext; }; +const createBuilderOutputMock = ( + success: boolean, + error: string +): BuilderOutput => { + return { + info: { info: null }, + error: error, + success: success, + target: {} as Target + }; +}; + const getBuildTarget = (): BuildTarget => ({ name: `${PROJECT}:build:production` }); diff --git a/src/deploy/actions.ts b/src/deploy/actions.ts index 1cc5cd83..a2e68ff4 100644 --- a/src/deploy/actions.ts +++ b/src/deploy/actions.ts @@ -49,7 +49,11 @@ export default async function deploy( } const build = await context.scheduleTarget(target); - await build.result; + const buildResult = await build.result; + + if (!buildResult.success) { + throw new Error(buildResult.error); + } } const targetFromStr = targetFromTargetString(buildTarget.name);