diff --git a/src/commands/hld/init.ts b/src/commands/hld/init.ts index 47f2e52e4..71dc1cff7 100644 --- a/src/commands/hld/init.ts +++ b/src/commands/hld/init.ts @@ -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); }); }); }; diff --git a/src/commands/project/create-variable-group.ts b/src/commands/project/create-variable-group.ts index 2a6973d9b..bc6beeb9b 100644 --- a/src/commands/project/create-variable-group.ts +++ b/src/commands/project/create-variable-group.ts @@ -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); }); } ); diff --git a/src/commands/project/init.ts b/src/commands/project/init.ts index 0ebb05407..de130bac9 100644 --- a/src/commands/project/init.ts +++ b/src/commands/project/init.ts @@ -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); }); }); }; diff --git a/src/lib/commandBuilder.test.ts b/src/lib/commandBuilder.test.ts index 0218ad94e..f4132edd2 100644 --- a/src/lib/commandBuilder.test.ts +++ b/src/lib/commandBuilder.test.ts @@ -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]]); }); }); diff --git a/src/lib/commandBuilder.ts b/src/lib/commandBuilder.ts index 4196ae81b..40699f5e0 100644 --- a/src/lib/commandBuilder.ts +++ b/src/lib/commandBuilder.ts @@ -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 => { + +export const exit = ( + log: Logger, + exitFn: (status: number) => void, + statusCode: number +): Promise => { return new Promise(resolve => { - log.info("", null, () => { + log.end(); + setTimeout(() => { + exitFn(statusCode); resolve(); - }); + }, 1000); }); };