Skip to content

Commit 8553240

Browse files
committed
test: Added logging tests
1 parent 40c5215 commit 8553240

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

test/logging.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const {describe, it, expect, beforeEach, afterEach} = require('@jest/globals');
4+
const {infoOut, logOut, debugOut, infoTable} = require('../utils/logging');
5+
6+
describe('logging utils', () => {
7+
let warnSpy;
8+
9+
beforeEach(() => {
10+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
11+
});
12+
13+
afterEach(() => {
14+
warnSpy.mockRestore();
15+
});
16+
17+
it('infoOut should write warnings', () => {
18+
infoOut('hello');
19+
expect(warnSpy).toHaveBeenCalledWith('hello');
20+
});
21+
22+
it('logOut should respect verbose level', () => {
23+
logOut('quiet', 0);
24+
expect(warnSpy).not.toHaveBeenCalled();
25+
26+
logOut('loud', 1);
27+
expect(warnSpy).toHaveBeenCalledWith('loud');
28+
});
29+
30+
it('debugOut should write only for verbose level >= 2', () => {
31+
debugOut('nope', 1);
32+
expect(warnSpy).not.toHaveBeenCalled();
33+
34+
debugOut('yep', 2);
35+
expect(warnSpy).toHaveBeenCalledWith('yep');
36+
});
37+
38+
it('infoTable should render table in verbose mode', () => {
39+
const table = infoTable({a: '1', b: ['x', 'y']}, 1);
40+
expect(table).toContain('| a | 1 |');
41+
expect(table).toContain('| b | x, y |');
42+
});
43+
});

0 commit comments

Comments
 (0)