-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.test.js
More file actions
66 lines (61 loc) · 2.17 KB
/
logger.test.js
File metadata and controls
66 lines (61 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { assert } from './test-utils/deps-node.js';
import * as logger from '../ts/logger.ts';
describe('[LOGX] Logger', function () {
describe('[LGFX] Logger functions', function () {
it('[LGFA] info() should call logger.info', () => {
let called = false;
let loggedArgs = null;
const customLogger = {
info: (...args) => { called = true; loggedArgs = args; },
error: () => {},
debug: () => {}
};
logger.setLogger(customLogger);
logger.info('test message', { data: 123 });
assert.equal(called, true);
assert.deepEqual(loggedArgs, ['test message', { data: 123 }]);
});
it('[LGFB] error() should call logger.error', () => {
let called = false;
let loggedArgs = null;
const customLogger = {
info: () => {},
error: (...args) => { called = true; loggedArgs = args; },
debug: () => {}
};
logger.setLogger(customLogger);
logger.error('error message', new Error('test'));
assert.equal(called, true);
assert.equal(loggedArgs[0], 'error message');
});
it('[LGFC] warn() should call logger.info (warn uses info internally)', () => {
let called = false;
let loggedArgs = null;
const customLogger = {
info: (...args) => { called = true; loggedArgs = args; },
error: () => {},
debug: () => {}
};
logger.setLogger(customLogger);
logger.warn('warning message');
assert.equal(called, true);
assert.deepEqual(loggedArgs, ['warning message']);
});
it('[LGFD] setLogger() should replace the logger', () => {
const logs = [];
const customLogger = {
info: (...args) => logs.push(['info', ...args]),
error: (...args) => logs.push(['error', ...args]),
debug: (...args) => logs.push(['debug', ...args])
};
logger.setLogger(customLogger);
logger.info('msg1');
logger.error('msg2');
logger.warn('msg3');
assert.equal(logs.length, 3);
assert.deepEqual(logs[0], ['info', 'msg1']);
assert.deepEqual(logs[1], ['error', 'msg2']);
assert.deepEqual(logs[2], ['info', 'msg3']); // warn uses info
});
});
});