Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 03be017

Browse files
dennisseahmtarng
andauthored
[Fix] 789: Having spk.log to be written and return status code (#214)
* [Fix] Issue 789 - for hld init and project create-variable-group command * having to use setTimeout to allow writing of log * code cleanup * restore helper function * fix hardcoded status * correct the exitCmd function call Co-authored-by: Michael Tarng <20913254+mtarng@users.noreply.github.com>
1 parent 1b02b1a commit 03be017

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

src/commands/hld/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export const commandDecorator = (command: commander.Command): void => {
4242
// gitPush will is always true or false. It shall not be
4343
// undefined because default value is set in the commander decorator
4444
await execute(projectPath, opts.gitPush, async (status: number) => {
45-
await exitCmd(logger);
46-
process.exit(status);
45+
await exitCmd(logger, process.exit, status);
4746
});
4847
});
4948
};

src/commands/project/create-variable-group.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ export const commandDecorator = (command: commander.Command): void => {
154154
buildCmd(command, decorator).action(
155155
async (variableGroupName: string, opts: ICommandOptions) => {
156156
await execute(variableGroupName, opts, async (status: number) => {
157-
await exitCmd(logger);
158-
process.exit(status);
157+
await exitCmd(logger, process.exit, status);
159158
});
160159
}
161160
);

src/commands/project/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export const execute = async (
4545
export const commandDecorator = (command: commander.Command): void => {
4646
buildCmd(command, decorator).action(async (opts: ICommandOptions) => {
4747
await execute(opts, async (status: number) => {
48-
await exitCmd(logger);
49-
process.exit(status);
48+
await exitCmd(logger, process.exit, status);
5049
});
5150
});
5251
};

src/lib/commandBuilder.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ describe("Tests Command Builder's validation function", () => {
105105
});
106106

107107
describe("Tests Command Builder's exit function", () => {
108-
it("calling exit function", () => {
109-
jest.spyOn(logger, "info");
110-
exitCmd(logger).then(() => {
111-
expect(logger.info).toBeCalledTimes(1);
112-
});
108+
it("calling exit function", async () => {
109+
const exitFn = jest.fn();
110+
await exitCmd(logger, exitFn, 1);
111+
expect(exitFn).toBeCalledTimes(1);
112+
expect(exitFn.mock.calls).toEqual([[1]]);
113113
});
114114
});

src/lib/commandBuilder.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,20 @@ export const validateForRequiredValues = (
108108
* In future there may be other housekeeper tasks.
109109
*
110110
* @param log Logger instance
111+
* @param exitFn exit function
112+
* @param statusCode Exit status code
111113
*/
112-
export const exit = (log: Logger): Promise<void> => {
114+
115+
export const exit = (
116+
log: Logger,
117+
exitFn: (status: number) => void,
118+
statusCode: number
119+
): Promise<void> => {
113120
return new Promise(resolve => {
114-
log.info("", null, () => {
121+
log.end();
122+
setTimeout(() => {
123+
exitFn(statusCode);
115124
resolve();
116-
});
125+
}, 1000);
117126
});
118127
};

0 commit comments

Comments
 (0)