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

Commit 9b44ce3

Browse files
masaxsuzuJohannesHoppe
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 f3cf830 commit 9b44ce3

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
import deploy from './actions';
910

@@ -60,6 +61,25 @@ describe('Deploy Angular apps', () => {
6061
expect(e.message).toMatch(/Cannot execute the build target/);
6162
}
6263
});
64+
65+
it('throws if app building fails', async () => {
66+
context.scheduleTarget = (
67+
_: Target,
68+
__?: JsonObject,
69+
___?: ScheduleOptions
70+
) =>
71+
Promise.resolve({
72+
result: Promise.resolve(
73+
createBuilderOutputMock(false, 'build error test')
74+
)
75+
} as BuilderRun);
76+
try {
77+
await deploy(mockEngine, context, 'host', {});
78+
fail();
79+
} catch (e) {
80+
expect(e.message).toMatch(/build error test/);
81+
}
82+
});
6383
});
6484
});
6585

@@ -90,6 +110,20 @@ const initMocks = () => {
90110
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) =>
91111
Promise.resolve({} as BuilderRun),
92112
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) =>
93-
Promise.resolve({} as BuilderRun)
113+
Promise.resolve({
114+
result: Promise.resolve(createBuilderOutputMock(true, ''))
115+
} as BuilderRun)
116+
};
117+
};
118+
119+
const createBuilderOutputMock = (
120+
success: boolean,
121+
error: string
122+
): BuilderOutput => {
123+
return {
124+
info: { info: null },
125+
error: error,
126+
success: success,
127+
target: {} as Target
94128
};
95129
};

src/deploy/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export default async function deploy(
4646
},
4747
overrides as json.JsonObject
4848
);
49-
await build.result;
49+
const buildResult = await build.result;
50+
51+
if (!buildResult.success) {
52+
throw new Error(buildResult.error);
53+
}
5054
}
5155

5256
await engine.run(

0 commit comments

Comments
 (0)