-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
58 lines (48 loc) · 1.53 KB
/
test.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
require('should');
var log = require('./');
var chalk = require('chalk');
var sinon = require('sinon');
describe('log', function() {
afterEach(function() {
log.level = 'info';
});
it('config level', function() {
log.level.should.eql('info');
log.config({ verbose: true });
log.level.should.eql('debug');
log.config({ quiet: true });
log.level.should.eql('warn');
});
it('config color', function() {
chalk.enabled.should.eql(true);
log.config({ color: false });
chalk.enabled.should.eql(false);
log.config({ color: { debug: 'white' } });
chalk.enabled.should.eql(true);
});
it('default level', function() {
var old_console_warn = console.warn;
var old_console_error = console.error;
console.warn = function() {
console.warn = old_console_warn;
};
console.error = function() {
console.error = old_console_error;
};
var console_log = sinon.spy(console, 'log');
var console_info = sinon.spy(console, 'info');
var console_warn = sinon.spy(console, 'warn');
var console_error = sinon.spy(console, 'error');
log.config({ color: false });
log.debug('debug', 'debug');
console_log.callCount.should.eql(0);
log.info('info', 'info');
console_info.callCount.should.eql(1);
console_info.calledWith(' info: info').should.eql(true);
log.warn('warn', 'warn');
console_warn.callCount.should.eql(1);
log.error('error', 'error');
console_error.callCount.should.eql(1);
log.config({ color: true });
});
});