Skip to content

Commit e1dc07a

Browse files
committed
refactor(logger): improve getSuggestLogFilePath method
1 parent 7254a69 commit e1dc07a

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

__tests__/logger.service.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { jest } from '@jest/globals';
2+
import { normalize } from 'path';
23

34
const writeFileSyncMock = jest.fn();
45
const renameFileSyncMock = jest.fn();
@@ -101,22 +102,22 @@ describe('LoggerService', () => {
101102

102103
describe('getSuggestLogfilePath', () => {
103104
it('the path should includes the os tmp dir', () => {
104-
const path = logger.getSuggestLogfilePath();
105-
expect(path.includes('/tmpDir')).toBeTruthy();
105+
const path = logger.getSuggestLogFilePath();
106+
expect(path.includes(normalize('/tmpDir'))).toBeTruthy();
106107
});
107108
});
108109

109110
describe('LogFile rotation', () => {
110111
it('should not rotate file if not exist', () => {
111112
existsSyncMock.mockReturnValue(false);
112-
const path = logger.getSuggestLogfilePath();
113+
const path = logger.getSuggestLogFilePath();
113114
logger.saveToFile(path);
114115
expect(renameFileSyncMock).not.toBeCalled();
115116
});
116117

117118
it('should rotate file if exist', () => {
118119
existsSyncMock.mockReturnValue(true);
119-
const path = logger.getSuggestLogfilePath();
120+
const path = logger.getSuggestLogFilePath();
120121
logger.saveToFile(path);
121122
const expectedOldPath = path.replace('latest', 'old');
122123
expect(renameFileSyncMock).toBeCalledWith(path, expectedOldPath);

src/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ export class Controller {
487487
this.uiService.print('\n');
488488
this.uiService.setRawMode(false);
489489
this.uiService.setCursorVisible(true);
490-
const logPath = this.logger.getSuggestLogfilePath();
490+
const logPath = this.logger.getSuggestLogFilePath();
491491
this.logger.saveToFile(logPath);
492492
process.exit(1);
493493
}
@@ -498,7 +498,7 @@ export class Controller {
498498
this.uiService.setCursorVisible(true);
499499
this.printExitMessage();
500500
this.logger.info('Thank for using npkill. Bye!');
501-
const logPath = this.logger.getSuggestLogfilePath();
501+
const logPath = this.logger.getSuggestLogFilePath();
502502
this.logger.saveToFile(logPath);
503503
process.exit();
504504
}

src/services/logger.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ export class LoggerService {
5252
writeFileSync(path, content);
5353
}
5454

55-
getSuggestLogfilePath(): string {
56-
return `${tmpdir()}/npkill-${LATEST_TAG}.log`;
55+
getSuggestLogFilePath(): string {
56+
const filename = `npkill-${LATEST_TAG}.log`;
57+
return join(tmpdir(), filename);
5758
}
5859

5960
private rotateLogFile(newLogPath: string): void {

0 commit comments

Comments
 (0)