Skip to content

Commit 9a3d756

Browse files
committed
improve code cov
1 parent 51b06bd commit 9a3d756

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { _console, logger } from '../logger';
2+
3+
beforeEach(() => {
4+
jest.spyOn(_console, 'debug').mockImplementation(() => {});
5+
jest.spyOn(_console, 'info').mockImplementation(() => {});
6+
jest.spyOn(_console, 'warn').mockImplementation(() => {});
7+
jest.spyOn(_console, 'error').mockImplementation(() => {});
8+
});
9+
10+
test('debug should call console.debug', () => {
11+
logger.debug('test message');
12+
13+
expect(_console.debug).toHaveBeenCalledTimes(1);
14+
expect(_console.debug).toHaveBeenCalledWith(expect.any(String));
15+
});
16+
17+
test('should call console.info', () => {
18+
logger.info('info message');
19+
20+
expect(_console.info).toHaveBeenCalledTimes(1);
21+
expect(_console.info).toHaveBeenCalledWith(expect.any(String));
22+
});
23+
24+
test('should call console.warn', () => {
25+
logger.warn('warning message');
26+
27+
expect(_console.warn).toHaveBeenCalledTimes(1);
28+
expect(_console.warn).toHaveBeenCalledWith(expect.any(String));
29+
});
30+
31+
test('should call console.error', () => {
32+
logger.error('error message');
33+
34+
expect(_console.error).toHaveBeenCalledTimes(1);
35+
expect(_console.error).toHaveBeenCalledWith(expect.any(String));
36+
});

src/helpers/logger.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@ import pc from 'picocolors';
33
import redent from 'redent';
44
import * as nodeUtil from 'util';
55

6+
export const _console = {
7+
debug: nodeConsole.debug,
8+
info: nodeConsole.info,
9+
warn: nodeConsole.warn,
10+
error: nodeConsole.error,
11+
};
12+
613
export const logger = {
714
debug(message: unknown, ...args: unknown[]) {
815
const output = formatMessage('●', message, ...args);
9-
nodeConsole.debug(pc.dim(output));
16+
_console.debug(pc.dim(output));
1017
},
1118

1219
info(message: unknown, ...args: unknown[]) {
1320
const output = formatMessage('●', message, ...args);
14-
nodeConsole.info(output);
21+
_console.info(output);
1522
},
1623

1724
warn(message: unknown, ...args: unknown[]) {
1825
const output = formatMessage('▲', message, ...args);
19-
nodeConsole.warn(pc.yellow(output));
26+
_console.warn(pc.yellow(output));
2027
},
2128

2229
error(message: unknown, ...args: unknown[]) {
2330
const output = formatMessage('■', message, ...args);
24-
nodeConsole.error(pc.red(output));
31+
_console.error(pc.red(output));
2532
},
2633
};
2734

0 commit comments

Comments
 (0)