-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
96 lines (78 loc) · 2.28 KB
/
index.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
'use strict';
var expect = require('expect');
var logger = require('../');
describe('gulplog', function () {
after(function (done) {
logger.remove();
done();
});
afterEach(function (done) {
logger.removeAllListeners();
done();
});
it('should emit the appropriate event when debug/info/warn/error methods are called', function (done) {
var called = { debug: 0, info: 0, warn: 0, error: 0 };
function allDone() {
if (called.debug && called.info && called.warn && called.error) {
expect(called.debug).toEqual(1);
expect(called.info).toEqual(1);
expect(called.warn).toEqual(1);
expect(called.error).toEqual(1);
done();
}
}
logger.on('debug', function (msg) {
expect(msg).toEqual('The MOST verbose!');
called.debug++;
allDone();
});
logger.on('info', function (msg) {
expect(msg).toEqual('Some important info');
called.info++;
allDone();
});
logger.on('warn', function (msg) {
expect(msg).toEqual('All the warnings to you');
called.warn++;
allDone();
});
logger.on('error', function (msg) {
expect(msg).toEqual('OH NO! SOMETHING HAPPENED!');
called.error++;
allDone();
});
logger.debug('The MOST verbose!');
logger.info('Some important info');
logger.warn('All the warnings to you');
logger.error('OH NO! SOMETHING HAPPENED!');
});
it('should support util.format syntax', function (done) {
logger.on('debug', function (msg) {
expect(msg).toEqual('printf style!');
done();
});
logger.debug('%s style!', 'printf');
});
it('should log an object as it is', function (done) {
logger.on('debug', function (msg) {
expect(msg).toEqual({ my: 'obj' });
done();
});
logger.debug({ my: 'obj' });
});
it('should log an array as it is', function (done) {
logger.on('info', function (msg) {
expect(msg).toEqual([1, 2, 3]);
done();
});
logger.info([1, 2, 3]);
});
it('logs all arguments if first argument is not a string', function (done) {
logger.on('info', function (arg1, arg2) {
expect(arg1).toEqual([1, 2, 3]);
expect(arg2).toEqual([4, 5, 6]);
done();
});
logger.info([1, 2, 3], [1, 2, 3]);
});
});