forked from skygragon/leetcode-cli
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathtest_log.js
108 lines (90 loc) · 2.8 KB
/
test_log.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
var assert = require('chai').assert;
var chalk = require('../lib/chalk');
var log = require('../lib/log');
describe('log', function() {
var _output = null;
var result = '';
before(function() {
chalk.init();
_output = log.output;
log.output = function(s) {
result = s;
};
});
after(function() {
log.output = _output;
});
beforeEach(function() {
log.init();
result = '';
});
describe('#setLevel', function() {
it('should ok with known level', function() {
log.setLevel('TRACE');
assert.deepEqual(log.level, log.levels.TRACE);
log.setLevel('DEBUG');
assert.deepEqual(log.level, log.levels.DEBUG);
log.setLevel('INFO');
assert.deepEqual(log.level, log.levels.INFO);
log.setLevel('WARN');
assert.deepEqual(log.level, log.levels.WARN);
log.setLevel('ERROR');
assert.deepEqual(log.level, log.levels.ERROR);
});
it('should ok with unknown level', function() {
log.setLevel('');
assert.deepEqual(log.level, log.levels.INFO);
});
});
describe('#isEnabled', function() {
it('should ok', function() {
log.setLevel('DEBUG');
assert.equal(log.isEnabled('TRACE'), false);
assert.equal(log.isEnabled('DEBUG'), true);
assert.equal(log.isEnabled('INFO'), true);
assert.equal(log.isEnabled('WARN'), true);
assert.equal(log.isEnabled('ERROR'), true);
});
});
describe('#levels', function() {
it('should ok with log.trace', function() {
log.trace('some error');
assert.equal(result, '');
log.setLevel('TRACE');
log.trace('some error');
assert.equal(result, chalk.gray('[TRACE] some error'));
});
it('should ok with log.debug', function() {
log.debug('some error');
assert.equal(result, '');
log.setLevel('DEBUG');
log.debug('some error');
assert.equal(result, chalk.gray('[DEBUG] some error'));
});
it('should ok with log.info', function() {
log.info('some error');
assert.equal(result, 'some error');
});
it('should ok with log.warn', function() {
log.warn('some error');
assert.equal(result, chalk.yellow('[WARN] some error'));
});
it('should ok with log.error', function() {
log.error('some error');
assert.equal(result, chalk.red('[ERROR] some error'));
});
it('should ok with log.fail', function() {
log.fail({msg: 'some error', statusCode: 500});
assert.equal(result, chalk.red('[ERROR] some error [500]'));
log.fail('some error');
assert.equal(result, chalk.red('[ERROR] some error [0]'));
});
});
describe('#printf', function() {
it('should ok', function() {
log.printf('%s and %d and %%', 'string', 100);
assert.equal(result, 'string and 100 and %');
});
});
});