forked from trentm/node-bunyan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctor.test.js
More file actions
154 lines (115 loc) · 5.02 KB
/
ctor.test.js
File metadata and controls
154 lines (115 loc) · 5.02 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (c) 2012 Trent Mick. All rights reserved.
*
* Test type checking on creation of the Logger.
*/
var bunyan = require('../lib/bunyan'),
Logger = bunyan;
// node-tap API
if (require.cache[__dirname + '/tap4nodeunit.js'])
delete require.cache[__dirname + '/tap4nodeunit.js'];
var tap4nodeunit = require('./tap4nodeunit.js');
var after = tap4nodeunit.after;
var before = tap4nodeunit.before;
var test = tap4nodeunit.test;
test('ensure Logger creation options', function (t) {
t.throws(function () { new Logger(); },
/options \(object\) is required/,
'no options should throw');
t.throws(function () { new Logger({}); },
/options\.name \(string\) is required/,
'no options.name should throw');
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
'just options.name should be sufficient');
var options = {name: 'foo', stream: process.stdout, streams: []};
t.throws(function () { new Logger(options); },
/* JSSTYLED */
/cannot mix "streams" and "stream" options/,
'cannot use "stream" and "streams"');
// https://github.com/trentm/node-bunyan/issues/3
options = {name: 'foo', streams: {}};
t.throws(function () { new Logger(options); },
/invalid options.streams: must be an array/,
'"streams" must be an array');
options = {name: 'foo', serializers: 'a string'};
t.throws(function () { new Logger(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be a string');
options = {name: 'foo', serializers: [1, 2, 3]};
t.throws(function () { new Logger(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be an array');
t.end();
});
test('ensure Logger constructor is safe without new', function (t) {
t.doesNotThrow(function () { Logger({name: 'foo'}); },
'constructor should call self with new if necessary');
t.end();
});
test('ensure Logger creation options (createLogger)', function (t) {
t.throws(function () { bunyan.createLogger(); },
/options \(object\) is required/,
'no options should throw');
t.throws(function () { bunyan.createLogger({}); },
/options\.name \(string\) is required/,
'no options.name should throw');
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
'just options.name should be sufficient');
var options = {name: 'foo', stream: process.stdout, streams: []};
t.throws(function () { bunyan.createLogger(options); },
/* JSSTYLED */
/cannot mix "streams" and "stream" options/,
'cannot use "stream" and "streams"');
// https://github.com/trentm/node-bunyan/issues/3
options = {name: 'foo', streams: {}};
t.throws(function () { bunyan.createLogger(options); },
/invalid options.streams: must be an array/,
'"streams" must be an array');
options = {name: 'foo', serializers: 'a string'};
t.throws(function () { bunyan.createLogger(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be a string');
options = {name: 'foo', serializers: [1, 2, 3]};
t.throws(function () { bunyan.createLogger(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be an array');
t.end();
});
test('ensure Logger child() options', function (t) {
var log = new Logger({name: 'foo'});
t.doesNotThrow(function () { log.child(); },
'no options should be fine');
t.doesNotThrow(function () { log.child({}); },
'empty options should be fine too');
t.throws(function () { log.child({name: 'foo'}); },
/invalid options.name: child cannot set logger name/,
'child cannot change name');
var options = {stream: process.stdout, streams: []};
t.throws(function () { log.child(options); },
/* JSSTYLED */
/cannot mix "streams" and "stream" options/,
'cannot use "stream" and "streams"');
// https://github.com/trentm/node-bunyan/issues/3
options = {streams: {}};
t.throws(function () { log.child(options); },
/invalid options.streams: must be an array/,
'"streams" must be an array');
options = {serializers: 'a string'};
t.throws(function () { log.child(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be a string');
options = {serializers: [1, 2, 3]};
t.throws(function () { log.child(options); },
/invalid options.serializers: must be an object/,
'"serializers" cannot be an array');
t.end();
});
test('ensure Logger() rejects non-Logger parents', function (t) {
var dad = new Logger({name: 'dad', streams: []});
t.throws(function () { new Logger({}, {}); },
/invalid Logger creation: do not pass a second arg/,
'Logger arguments must be valid');
t.doesNotThrow(function () { new Logger(dad, {}); },
'Logger allows Logger instance as parent');
t.end();
});