Skip to content

Commit

Permalink
fix: throws an error if app building fails
Browse files Browse the repository at this point in the history
  • Loading branch information
masaxsuzu authored and JohannesHoppe committed Dec 19, 2019
1 parent f75c740 commit e7f6a51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/deploy/actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonObject, logging } from '@angular-devkit/core';
import { BuilderContext, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
import { BuilderContext, BuilderOutput, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
import deploy from './actions';

let context: BuilderContext;
Expand Down Expand Up @@ -53,6 +53,18 @@ 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 @@ -81,6 +93,17 @@ const initMocks = () => {
reportStatus: (_: string) => { },
reportRunning: () => { },
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun),
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun)
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => 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 @@ -30,7 +30,11 @@ export default async function deploy(
project: context.target.project,
configuration
}, 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 e7f6a51

Please sign in to comment.