Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* container-test.js: Tests for the Container object
3
*
4
* (C) 2011 Charlie Robbins
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
fs = require('fs'),
11
http = require('http'),
12
path = require('path'),
13
vows = require('vows'),
14
winston = require('../lib/winston'),
15
helpers = require('./helpers');
16
17
vows.describe('winston/container').addBatch({
18
"An instance of winston.Container": {
19
topic: new winston.Container(),
20
"the add() method": {
21
topic: function (container) {
22
return container.add('default-test');
23
},
24
"should correctly instantiate a Logger": function (logger) {
25
assert.instanceOf(logger, winston.Logger);
26
},
27
"the get() method": {
28
topic: function (logger, container) {
29
this.callback.apply(this, arguments);
30
},
31
"should respond with the logger previously created": function (existing, container) {
32
var logger = container.get('default-test');
33
assert.isTrue(existing === logger);
34
}
35
},
36
"the has() method": {
37
topic: function (logger, container) {
38
this.callback.apply(this, arguments);
39
},
40
"should indicate `default-test` logger exists": function (existing, container) {
41
assert.isTrue(container.has('default-test'));
42
},
43
"should indicate `not-has` logger doesnt exists": function (existing, container) {
44
assert.isFalse(container.has('not-has'));
45
}
46
},
47
"the close() method": {
48
topic: function (logger, container) {
49
this.callback.apply(this, arguments);
50
},
51
"should remove the specified logger": function (logger, container) {
52
container.close('default-test');
53
assert.isTrue(!container.loggers['default-test']);
54
}
55
}
56
}
57
},
58
"An instance of winston.Container with explicit transports": {
59
topic: function () {
60
this.port = 9412;
61
this.transports = [
62
new winston.transports.Webhook({
63
port: this.port
64
})
65
];
66
67
this.container = new winston.Container({
68
transports: this.transports
69
});
70
71
return null;
72
},
73
"the get() method": {
74
topic: function (container) {
75
var server = http.createServer(function (req, res) {
76
res.end();
77
});
78
79
server.listen(this.port, this.callback.bind(this, null));
80
},
81
"should add the logger correctly": function () {
82
this.someLogger = this.container.get('some-logger');
83
assert.isObject(this.someLogger.transports);
84
assert.instanceOf(this.someLogger.transports['webhook'], winston.transports.Webhook);
85
assert.strictEqual(this.someLogger.transports['webhook'], this.transports[0]);
86
},
87
"a second call to get()": {
88
"should respond with the same transport object": function () {
89
this.someOtherLogger = this.container.get('some-other-logger');
90
91
assert.isObject(this.someOtherLogger.transports);
92
assert.instanceOf(this.someOtherLogger.transports['webhook'], winston.transports.Webhook);
93
assert.strictEqual(this.someOtherLogger.transports['webhook'], this.transports[0]);
94
assert.strictEqual(this.someOtherLogger.transports['webhook'], this.someLogger.transports['webhook']);
95
}
96
}
97
}
98
}
99
}).export(module);
100