Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
3 changes: 1 addition & 2 deletions src/commands/hld/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const commandDecorator = (command: commander.Command): void => {
// gitPush will is always true or false. It shall not be
// undefined because default value is set in the commander decorator
await execute(projectPath, opts.gitPush, async (status: number) => {
await exitCmd(logger);
process.exit(status);
await exitCmd(logger, process.exit, status);
});
});
};
Expand Down
3 changes: 1 addition & 2 deletions src/commands/project/create-variable-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ export const commandDecorator = (command: commander.Command): void => {
buildCmd(command, decorator).action(
async (variableGroupName: string, opts: ICommandOptions) => {
await execute(variableGroupName, opts, async (status: number) => {
await exitCmd(logger);
process.exit(status);
await exitCmd(logger, process.exit, status);
});
}
);
Expand Down
3 changes: 1 addition & 2 deletions src/commands/project/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export const execute = async (
export const commandDecorator = (command: commander.Command): void => {
buildCmd(command, decorator).action(async (opts: ICommandOptions) => {
await execute(opts, async (status: number) => {
await exitCmd(logger);
process.exit(status);
await exitCmd(logger, process.exit, status);
});
});
};
Expand Down
10 changes: 5 additions & 5 deletions src/lib/commandBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ describe("Tests Command Builder's validation function", () => {
});

describe("Tests Command Builder's exit function", () => {
it("calling exit function", () => {
jest.spyOn(logger, "info");
exitCmd(logger).then(() => {
expect(logger.info).toBeCalledTimes(1);
});
it("calling exit function", async () => {
const exitFn = jest.fn();
await exitCmd(logger, exitFn, 1);
expect(exitFn).toBeCalledTimes(1);
expect(exitFn.mock.calls).toEqual([[1]]);
});
});
15 changes: 12 additions & 3 deletions src/lib/commandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,20 @@ export const validateForRequiredValues = (
* In future there may be other housekeeper tasks.
*
* @param log Logger instance
* @param exitFn exit function
* @param statusCode Exit status code
*/
export const exit = (log: Logger): Promise<void> => {

export const exit = (
log: Logger,
exitFn: (status: number) => void,
statusCode: number
): Promise<void> => {
return new Promise(resolve => {
log.info("", null, () => {
log.end();
setTimeout(() => {
exitFn(statusCode);
resolve();
});
}, 1000);
});
};