Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* logger-test.js: Tests for instances of the winston Logger
3
*
4
* (C) 2010 Charlie Robbins
5
* MIT LICENSE
6
*
7
*/
8
9
var fs = require('fs'),
10
path = require('path'),
11
vows = require('vows'),
12
http = require('http'),
13
assert = require('assert'),
14
winston = require('../lib/winston'),
15
helpers = require('./helpers');
16
17
vows.describe('winston').addBatch({
18
"The winston module": {
19
topic: function () {
20
winston.default.transports.console.level = 'silly';
21
return null;
22
},
23
"should have the correct methods defined": function () {
24
assert.isObject(winston.transports);
25
assert.isFunction(winston.Transport);
26
assert.isTrue(!winston.transports.Transport);
27
assert.isFunction(winston.transports.Console);
28
assert.isFunction(winston.transports.File);
29
assert.isFunction(winston.transports.Webhook);
30
assert.isObject(winston.default.transports.console);
31
assert.isFalse(winston.emitErrs);
32
assert.isObject(winston.config);
33
['Logger', 'add', 'remove', 'extend']
34
.concat(Object.keys(winston.config.npm.levels))
35
.forEach(function (key) {
36
assert.isFunction(winston[key]);
37
});
38
},
39
"it should": {
40
topic: function () {
41
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
42
},
43
"have the correct version set": function (err, data) {
44
assert.isNull(err);
45
data = JSON.parse(data.toString());
46
assert.equal(winston.version, data.version);
47
}
48
},
49
"the log() method": helpers.testNpmLevels(winston, "should respond without an error", function (err) {
50
assert.isNull(err);
51
}),
52
"the extend() method called on an empty object": {
53
topic: function (logger) {
54
var empty = {};
55
winston.extend(empty);
56
return empty;
57
},
58
"should define the appropriate methods": function (extended) {
59
['log', 'profile', 'startTimer'].concat(Object.keys(winston.config.npm.levels)).forEach(function (method) {
60
assert.isFunction(extended[method]);
61
});
62
}
63
}
64
}
65
}).addBatch({
66
"The winston module": {
67
"the setLevels() method": {
68
topic: function () {
69
winston.setLevels(winston.config.syslog.levels);
70
return null;
71
},
72
"should have the proper methods defined": function () {
73
assert.isObject(winston.transports);
74
assert.isFunction(winston.transports.Console);
75
assert.isFunction(winston.transports.Webhook);
76
assert.isObject(winston.default.transports.console);
77
assert.isFalse(winston.emitErrs);
78
assert.isObject(winston.config);
79
80
var newLevels = Object.keys(winston.config.syslog.levels);
81
['Logger', 'add', 'remove', 'extend']
82
.concat(newLevels)
83
.forEach(function (key) {
84
assert.isFunction(winston[key]);
85
});
86
87
88
Object.keys(winston.config.npm.levels)
89
.filter(function (key) {
90
return newLevels.indexOf(key) === -1;
91
})
92
.forEach(function (key) {
93
assert.isTrue(typeof winston[key] === 'undefined');
94
});
95
}
96
}
97
}
98
}).export(module);
99
100