Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
fix: throws an error if app building fails
Browse files Browse the repository at this point in the history
cherry-pick from e7f6a51 of angular-cli-ghpages/master by @masaxsuzu
see angular-schule/angular-cli-ghpages#85
  • Loading branch information
masaxsuzu authored and JohannesHoppe committed Dec 20, 2019
1 parent f3cf830 commit 9b44ce3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/deploy/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
BuilderContext,
BuilderRun,
ScheduleOptions,
Target
Target,
BuilderOutput
} from '@angular-devkit/architect/src/index';
import deploy from './actions';

Expand Down Expand Up @@ -60,6 +61,25 @@ 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 @@ -90,6 +110,20 @@ const initMocks = () => {
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) =>
Promise.resolve({} as BuilderRun),
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) =>
Promise.resolve({} as BuilderRun)
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 @@ -46,7 +46,11 @@ export default async function deploy(
},
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

0 comments on commit 9b44ce3

Please sign in to comment.