Skip to content

Commit e7f6a51

Browse files
masaxsuzuJohannesHoppe
authored andcommitted
fix: throws an error if app building fails
1 parent f75c740 commit e7f6a51

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/deploy/actions.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JsonObject, logging } from '@angular-devkit/core';
2-
import { BuilderContext, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
2+
import { BuilderContext, BuilderOutput, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
33
import deploy from './actions';
44

55
let context: BuilderContext;
@@ -53,6 +53,18 @@ describe('Deploy Angular apps', () => {
5353
expect(e.message).toMatch(/Cannot execute the build target/);
5454
}
5555
});
56+
57+
it('throws if app building fails', async () => {
58+
context.scheduleTarget = (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({
59+
result: Promise.resolve(createBuilderOutputMock(false, 'build error test')),
60+
} as BuilderRun);
61+
try {
62+
await deploy(mockEngine, context, 'host', {});
63+
fail();
64+
} catch (e) {
65+
expect(e.message).toMatch(/build error test/);
66+
}
67+
});
5668
});
5769
});
5870

@@ -81,6 +93,17 @@ const initMocks = () => {
8193
reportStatus: (_: string) => { },
8294
reportRunning: () => { },
8395
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun),
84-
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun)
96+
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({
97+
result: Promise.resolve(createBuilderOutputMock(true, '')),
98+
} as BuilderRun)
99+
};
100+
};
101+
102+
const createBuilderOutputMock = (success: boolean, error: string): BuilderOutput => {
103+
return {
104+
info: { 'info': null },
105+
error: error,
106+
success: success,
107+
target: {} as Target,
85108
};
86109
};

src/deploy/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export default async function deploy(
3030
project: context.target.project,
3131
configuration
3232
}, overrides as json.JsonObject);
33-
await build.result;
33+
const buildResult = await build.result;
34+
35+
if (!buildResult.success) {
36+
throw new Error(buildResult.error);
37+
}
3438
}
3539

3640
await engine.run(

0 commit comments

Comments
 (0)