Name: js-handler/node_modules/restify/node_modules/bunyan/test/ctor.test.js 
1:
/*
2:
 * Copyright (c) 2012 Trent Mick. All rights reserved.
3:
 *
4:
 * Test type checking on creation of the Logger.
5:
 */
6:
 
7:
var bunyan = require('../lib/bunyan'),
8:
        Logger = bunyan;
9:
 
10:
// node-tap API
11:
if (require.cache[__dirname + '/tap4nodeunit.js'])
12:
        delete require.cache[__dirname + '/tap4nodeunit.js'];
13:
var tap4nodeunit = require('./tap4nodeunit.js');
14:
var after = tap4nodeunit.after;
15:
var before = tap4nodeunit.before;
16:
var test = tap4nodeunit.test;
17:
 
18:
 
19:
 
20:
test('ensure Logger creation options', function (t) {
21:
    t.throws(function () { new Logger(); },
22:
        'options (object) is required',
23:
        'no options should throw');
24:
 
25:
    t.throws(function () { new Logger({}); },
26:
        'options.name (string) is required',
27:
        'no options.name should throw');
28:
 
29:
    t.doesNotThrow(function () { new Logger({name: 'foo'}); },
30:
        'just options.name should be sufficient');
31:
 
32:
    var options = {name: 'foo', stream: process.stdout, streams: []};
33:
    t.throws(function () { new Logger(options); },
34:
        'cannot use "stream" and "streams"');
35:
 
36:
    // https://github.com/trentm/node-bunyan/issues/3
37:
    options = {name: 'foo', streams: {}};
38:
    t.throws(function () { new Logger(options); },
39:
        'invalid options.streams: must be an array',
40:
        '"streams" must be an array');
41:
 
42:
    options = {name: 'foo', serializers: 'a string'};
43:
    t.throws(function () { new Logger(options); },
44:
        'invalid options.serializers: must be an object',
45:
        '"serializers" cannot be a string');
46:
 
47:
    options = {name: 'foo', serializers: [1, 2, 3]};
48:
    t.throws(function () { new Logger(options); },
49:
        'invalid options.serializers: must be an object',
50:
        '"serializers" cannot be an array');
51:
 
52:
    t.end();
53:
});
54:
 
55:
 
56:
test('ensure Logger creation options (createLogger)', function (t) {
57:
    t.throws(function () { bunyan.createLogger(); },
58:
        'options (object) is required',
59:
        'no options should throw');
60:
 
61:
    t.throws(function () { bunyan.createLogger({}); },
62:
        'options.name (string) is required',
63:
        'no options.name should throw');
64:
 
65:
    t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
66:
        'just options.name should be sufficient');
67:
 
68:
    var options = {name: 'foo', stream: process.stdout, streams: []};
69:
    t.throws(function () { bunyan.createLogger(options); },
70:
        'cannot use "stream" and "streams"');
71:
 
72:
    // https://github.com/trentm/node-bunyan/issues/3
73:
    options = {name: 'foo', streams: {}};
74:
    t.throws(function () { bunyan.createLogger(options); },
75:
        'invalid options.streams: must be an array',
76:
        '"streams" must be an array');
77:
 
78:
    options = {name: 'foo', serializers: 'a string'};
79:
    t.throws(function () { bunyan.createLogger(options); },
80:
        'invalid options.serializers: must be an object',
81:
        '"serializers" cannot be a string');
82:
 
83:
    options = {name: 'foo', serializers: [1, 2, 3]};
84:
    t.throws(function () { bunyan.createLogger(options); },
85:
        'invalid options.serializers: must be an object',
86:
        '"serializers" cannot be an array');
87:
 
88:
    t.end();
89:
});
90:
 
91:
 
92:
test('ensure Logger child() options', function (t) {
93:
    var log = new Logger({name: 'foo'});
94:
 
95:
    t.doesNotThrow(function () { log.child(); },
96:
        'no options should be fine');
97:
 
98:
    t.doesNotThrow(function () { log.child({}); },
99:
        'empty options should be fine too');
100:
 
101:
    t.throws(function () { log.child({name: 'foo'}); },
102:
        'invalid options.name: child cannot set logger name',
103:
        'child cannot change name');
104:
 
105:
    var options = {stream: process.stdout, streams: []};
106:
    t.throws(function () { log.child(options); },
107:
        'cannot use "stream" and "streams"');
108:
 
109:
    // https://github.com/trentm/node-bunyan/issues/3
110:
    options = {streams: {}};
111:
    t.throws(function () { log.child(options); },
112:
        'invalid options.streams: must be an array',
113:
        '"streams" must be an array');
114:
 
115:
    options = {serializers: 'a string'};
116:
    t.throws(function () { log.child(options); },
117:
        'invalid options.serializers: must be an object',
118:
        '"serializers" cannot be a string');
119:
 
120:
    options = {serializers: [1, 2, 3]};
121:
    t.throws(function () { log.child(options); },
122:
        'invalid options.serializers: must be an object',
123:
        '"serializers" cannot be an array');
124:
 
125:
    t.end();
126:
});