Skip to content

Commit 072290a

Browse files
masaxsuzudianjuar
authored andcommitted
fix: throws an error if app building fails
cherry-pick from e7f6a51 of angular-cli-ghpages/master by @masaxsuzu see angular-schule/angular-cli-ghpages#85
1 parent 9020e9f commit 072290a

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/deploy/actions.spec.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
BuilderContext,
44
BuilderRun,
55
ScheduleOptions,
6-
Target
6+
Target,
7+
BuilderOutput
78
} from '@angular-devkit/architect/src/index';
89

910
import deploy from './actions';
@@ -145,6 +146,25 @@ describe('Deploy Angular apps', () => {
145146
);
146147
}
147148
});
149+
150+
it('throws if app building fails', async () => {
151+
context.scheduleTarget = (
152+
_: Target,
153+
__?: JsonObject,
154+
___?: ScheduleOptions
155+
) =>
156+
Promise.resolve({
157+
result: Promise.resolve(
158+
createBuilderOutputMock(false, 'build error test')
159+
)
160+
} as BuilderRun);
161+
try {
162+
await deploy(mockEngine, context, getBuildTarget(), {});
163+
fail();
164+
} catch (e) {
165+
expect(e.message).toMatch(/build error test/);
166+
}
167+
});
148168
});
149169
});
150170

@@ -163,7 +183,9 @@ const initMocks = () => {
163183
workspaceRoot: 'my/workspace/root',
164184
logger: new logging.NullLogger() as any,
165185
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) =>
166-
Promise.resolve({} as BuilderRun),
186+
Promise.resolve({
187+
result: Promise.resolve(createBuilderOutputMock(true, ''))
188+
} as BuilderRun),
167189
getTargetOptions: (t: Target) =>
168190
Promise.resolve({
169191
project: `projects/${t.project}/some-file.json`,
@@ -173,6 +195,18 @@ const initMocks = () => {
173195
} as unknown) as BuilderContext;
174196
};
175197

198+
const createBuilderOutputMock = (
199+
success: boolean,
200+
error: string
201+
): BuilderOutput => {
202+
return {
203+
info: { info: null },
204+
error: error,
205+
success: success,
206+
target: {} as Target
207+
};
208+
};
209+
176210
const getBuildTarget = (): BuildTarget => ({
177211
name: `${PROJECT}:build:production`
178212
});

src/deploy/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export default async function deploy(
4949
}
5050

5151
const build = await context.scheduleTarget(target);
52-
await build.result;
52+
const buildResult = await build.result;
53+
54+
if (!buildResult.success) {
55+
throw new Error(buildResult.error);
56+
}
5357
}
5458

5559
const targetFromStr = targetFromTargetString(buildTarget.name);

0 commit comments

Comments
 (0)