Skip to content

Commit

Permalink
Make printExitInfoTimingTable method private and test indirectly
Browse files Browse the repository at this point in the history
With this change we can be sure that the 'logger' is defined.
Increases coverage on Node.js 12.
  • Loading branch information
paescuj committed Jun 27, 2022
1 parent 150d5db commit d7fcb11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/flow-control/log-timings.spec.ts
Expand Up @@ -109,20 +109,14 @@ it('does not log timings summary if there was an error', () => {
});

it('logs the sorted timings summary when all processes close successfully', () => {
jest.spyOn(controller, 'printExitInfoTimingTable');
controller.handle(commands);

commands[0].close.next(command0ExitInfo);
commands[1].close.next(command1ExitInfo);

expect(logger.logGlobalEvent).toHaveBeenCalledTimes(1);
expect(logger.logGlobalEvent).toHaveBeenCalledWith('Timings:');
expect(logger.logTable).toHaveBeenCalledTimes(1);

// un-sorted ie by finish order
expect(controller.printExitInfoTimingTable).toHaveBeenCalledWith([
command0ExitInfo,
command1ExitInfo,
]);

// sorted by duration
expect(logger.logTable).toHaveBeenCalledWith([
LogTimings.mapCloseEventToTimingInfo(command1ExitInfo),
Expand Down
10 changes: 5 additions & 5 deletions src/flow-control/log-timings.ts
Expand Up @@ -51,15 +51,15 @@ export class LogTimings implements FlowController {
this.timestampFormat = timestampFormat;
}

printExitInfoTimingTable(exitInfos: CloseEvent[]) {
private printExitInfoTimingTable(exitInfos: CloseEvent[]) {
const exitInfoTable = _(exitInfos)
.sortBy(({ timings }) => timings.durationSeconds)
.reverse()
.map(LogTimings.mapCloseEventToTimingInfo)
.value();

this.logger?.logGlobalEvent('Timings:');
this.logger?.logTable(exitInfoTable);
this.logger.logGlobalEvent('Timings:');
this.logger.logTable(exitInfoTable);
return exitInfos;
}

Expand All @@ -73,14 +73,14 @@ export class LogTimings implements FlowController {
command.timer.subscribe(({ startDate, endDate }) => {
if (!endDate) {
const formattedStartDate = formatDate(startDate, this.timestampFormat);
this.logger?.logCommandEvent(
this.logger.logCommandEvent(
`${command.command} started at ${formattedStartDate}`,
command
);
} else {
const durationMs = endDate.getTime() - startDate.getTime();
const formattedEndDate = formatDate(endDate, this.timestampFormat);
this.logger?.logCommandEvent(
this.logger.logCommandEvent(
`${
command.command
} stopped at ${formattedEndDate} after ${durationMs.toLocaleString()}ms`,
Expand Down

0 comments on commit d7fcb11

Please sign in to comment.