-
Notifications
You must be signed in to change notification settings - Fork 28
/
test.js
75 lines (53 loc) · 2.18 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var bucker = require('./index');
var assert = require('assert');
// Null Logger Test --------------------------------------
var nullLogger = bucker.createNullLogger();
var logMethods = ['log', 'access', 'debug', 'info', 'warn', 'warning', 'error', 'exception', 'email'];
logMethods.forEach(function (logMethod) {
assert.doesNotThrow(function () {
nullLogger[logMethod]('Try to log');
}, 'Calling ' + logMethod + ' should do nothing');
});
assert.doesNotThrow(function () {
nullLogger.log('foo').debug('bar').exception('hi');
}, 'Can chain things');
assert.doesNotThrow(function () {
nullLogger.tags(['foo', 'bar']).info('Log something');
}, 'Can still try and make tags');
assert.doesNotThrow(function () {
nullLogger.module('new_module_name').info('Log something');
}, 'Can still try and submodule a nullLogger');
console.log('nullLogger tests pass');
// Logger test ------------------------------------------
var Console = require('./lib/console');
var logged = [];
Console.prototype.log = function (time, level, module, data, tags) {
logged.push({
time: time,
level: level,
module: module,
data: data,
tags: tags
});
};
var logger = bucker.createLogger({ console: true });
// Basic logging
logged = [];
logger.log('foo');
assert.equal(logged[0].data, 'foo', '[noModule] Logs string');
assert.equal(logged[0].module, '', '[noModule] No module');
// Module logging
logged = [];
logger.module('MyModule').log('foo');
assert.equal(logged[0].data, 'foo', '[WithModule] Logs string');
assert.equal(logged[0].module, 'MyModule', '[WithModule] Has module name');
// Chained logging
logged = [];
logger.module('MyModule').log('foo').warn('bar').debug('baz');
assert.equal(logged[0].data, 'foo', '[Chained] Logs first string');
assert.equal(logged[0].level, 'info', '[Chained] Logs first string as "log"');
assert.equal(logged[1].data, 'bar', '[Chained] Logs second string');
assert.equal(logged[1].level, 'warn', '[Chained] Logs second string as "warn"');
assert.equal(logged[2].data, 'baz', '[Chained] Logs last string');
assert.equal(logged[2].level, 'debug', '[Chained] Logs last string as "debug"');
console.log('Logger tests pass');