1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

updated package.json

This commit is contained in:
2016-01-04 12:25:28 -05:00
parent 3443c97de4
commit 80ca24a715
1168 changed files with 73752 additions and 26424 deletions

40
node_modules/winston/test/cli-test.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
/*
* cli-test.js: Tests for the cli levels available in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston/logger/cli').addBatch({
"When an instance of winston.Logger": {
topic: function () {
return new winston.Logger({
transports: [
new winston.transports.Console()
]
})
},
"the cli() method": {
"should set the appropriate values on the logger": function (logger) {
logger.cli();
assert.isTrue(logger.padLevels);
assert.isTrue(logger.transports.console.colorize);
assert.isFalse(logger.transports.console.timestamp);
Object.keys(winston.config.cli.levels).forEach(function (level) {
assert.isNumber(logger.levels[level]);
});
Object.keys(winston.config.cli.colors).forEach(function (color) {
assert.isString(winston.config.allColors[color]);
});
}
}
}
}).export(module);

99
node_modules/winston/test/container-test.js generated vendored Normal file
View File

@@ -0,0 +1,99 @@
/*
* container-test.js: Tests for the Container object
*
* (C) 2011 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
fs = require('fs'),
http = require('http'),
path = require('path'),
vows = require('vows'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston/container').addBatch({
"An instance of winston.Container": {
topic: new winston.Container(),
"the add() method": {
topic: function (container) {
return container.add('default-test');
},
"should correctly instantiate a Logger": function (logger) {
assert.instanceOf(logger, winston.Logger);
},
"the get() method": {
topic: function (logger, container) {
this.callback.apply(this, arguments);
},
"should respond with the logger previously created": function (existing, container) {
var logger = container.get('default-test');
assert.isTrue(existing === logger);
}
},
"the has() method": {
topic: function (logger, container) {
this.callback.apply(this, arguments);
},
"should indicate `default-test` logger exists": function (existing, container) {
assert.isTrue(container.has('default-test'));
},
"should indicate `not-has` logger doesnt exists": function (existing, container) {
assert.isFalse(container.has('not-has'));
}
},
"the close() method": {
topic: function (logger, container) {
this.callback.apply(this, arguments);
},
"should remove the specified logger": function (logger, container) {
container.close('default-test');
assert.isTrue(!container.loggers['default-test']);
}
}
}
},
"An instance of winston.Container with explicit transports": {
topic: function () {
this.port = 9412;
this.transports = [
new winston.transports.Webhook({
port: this.port
})
];
this.container = new winston.Container({
transports: this.transports
});
return null;
},
"the get() method": {
topic: function (container) {
var server = http.createServer(function (req, res) {
res.end();
});
server.listen(this.port, this.callback.bind(this, null));
},
"should add the logger correctly": function () {
this.someLogger = this.container.get('some-logger');
assert.isObject(this.someLogger.transports);
assert.instanceOf(this.someLogger.transports['webhook'], winston.transports.Webhook);
assert.strictEqual(this.someLogger.transports['webhook'], this.transports[0]);
},
"a second call to get()": {
"should respond with the same transport object": function () {
this.someOtherLogger = this.container.get('some-other-logger');
assert.isObject(this.someOtherLogger.transports);
assert.instanceOf(this.someOtherLogger.transports['webhook'], winston.transports.Webhook);
assert.strictEqual(this.someOtherLogger.transports['webhook'], this.transports[0]);
assert.strictEqual(this.someOtherLogger.transports['webhook'], this.someLogger.transports['webhook']);
}
}
}
}
}).export(module);

62
node_modules/winston/test/custom-timestamp-test.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
/*
* custom-timestamp-test.js: Test function as timestamp option for transport `{ timestamp: function () {} }`
*
* (C) 2011 Charlie Robbins, Tom Shinnick
* MIT LICENSE
*
*/
var assert = require('assert'),
events = require('events'),
fs = require('fs'),
path = require('path'),
vows = require('vows'),
winston = require('../lib/winston'),
helpers = require('./helpers');
function assertTimestamp (basename, options) {
var filename = path.join(__dirname, 'fixtures', 'logs', basename + '.log');
try { fs.unlinkSync(filename) }
catch (ex) { }
return {
topic: function () {
options.filename = filename;
var transport = new (winston.transports.File)(options);
// We must wait until transport file has emitted the 'flush'
// event to be sure the file has been created and written
transport.once('flush', this.callback.bind(this, null, filename));
transport.log('info', 'When a fake tree falls in the forest...', null, function () {});
},
"should log with the appropriate timestamp": function (_, filename) {
var data = fs.readFileSync(filename, 'utf8');
assert.isNotNull(data.match(options.pattern));
}
}
}
vows.describe('winston/transport/timestamp').addBatch({
"When timestamp option is used": {
"with file transport": {
"with value set to false": assertTimestamp('noTimestamp', {
pattern: /^info\:/,
json: false,
timestamp: false
}),
"with value set to true ": assertTimestamp('defaultTimestamp', {
pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/,
json: false,
timestamp: true
}),
"and function value": assertTimestamp('customTimestamp', {
pattern: /^\d{8}\./,
json: false,
timestamp: function () {
return '20110803.171657';
}
})
}
}
}).export(module);

47
node_modules/winston/test/exception-test.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
/*
* exception-test.js: Tests for exception data gathering in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston/exception').addBatch({
"When using the winston exception module": {
"the getProcessInfo() method": {
topic: winston.exception.getProcessInfo(),
"should respond with the appropriate data": function (info) {
helpers.assertProcessInfo(info);
}
},
"the getOsInfo() method": {
topic: winston.exception.getOsInfo(),
"should respond with the appropriate data": function (info) {
helpers.assertOsInfo(info);
}
},
"the getTrace() method": {
topic: winston.exception.getTrace(new Error()),
"should have the appropriate info": function (trace) {
helpers.assertTrace(trace);
}
},
"the getAllInfo() method": {
topic: winston.exception.getAllInfo(new Error()),
"should have the appropriate info": function (info) {
assert.isObject(info);
assert.isArray(info.stack);
helpers.assertDateInfo(info.date);
helpers.assertProcessInfo(info.process);
helpers.assertOsInfo(info.os);
helpers.assertTrace(info.trace);
}
}
}
}).export(module);

0
node_modules/winston/test/fixtures/.gitkeep generated vendored Normal file
View File

View File

@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB7DCCAZYCCQC7gs0MDNn6MTANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQGEwJV
UzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQKEwZKb3llbnQxEDAO
BgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MjEgMB4GCSqGSIb3DQEJARYR
cnlAdGlueWNsb3Vkcy5vcmcwHhcNMTEwMzE0MTgyOTEyWhcNMzgwNzI5MTgyOTEy
WjB9MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYD
VQQKEwZKb3llbnQxEDAOBgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MjEg
MB4GCSqGSIb3DQEJARYRcnlAdGlueWNsb3Vkcy5vcmcwXDANBgkqhkiG9w0BAQEF
AANLADBIAkEAyXb8FrRdKbhrKLgLSsn61i1C7w7fVVVd7OQsmV/7p9WB2lWFiDlC
WKGU9SiIz/A6wNZDUAuc2E+VwtpCT561AQIDAQABMA0GCSqGSIb3DQEBBQUAA0EA
C8HzpuNhFLCI3A5KkBS5zHAQax6TFUOhbpBCR0aTDbJ6F1liDTK1lmU/BjvPoj+9
1LHwrmh29rK8kBPEjmymCQ==
-----END CERTIFICATE-----

View File

@@ -0,0 +1,9 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAMl2/Ba0XSm4ayi4C0rJ+tYtQu8O31VVXezkLJlf+6fVgdpVhYg5
QlihlPUoiM/wOsDWQ1ALnNhPlcLaQk+etQECAwEAAQJBAMT6Bf34+UHKY1ObpsbH
9u2jsVblFq1rWvs8GPMY6oertzvwm3DpuSUp7PTgOB1nLTLYtCERbQ4ovtN8tn3p
OHUCIQDzIEGsoCr5vlxXvy2zJwu+fxYuhTZWMVuo1397L0VyhwIhANQh+yzqUgaf
WRtSB4T2W7ADtJI35ET61jKBty3CqJY3AiAIwju7dVW3A5WeD6Qc1SZGKZvp9yCb
AFI2BfVwwaY11wIgXF3PeGcvACMyMWsuSv7aPXHfliswAbkWuzcwA4TW01ECIGWa
cgsDvVFxmfM5NPSuT/UDTa6R5BFISB5ea0N0AR3I
-----END RSA PRIVATE KEY-----

0
node_modules/winston/test/fixtures/logs/.gitkeep generated vendored Normal file
View File

View File

@@ -0,0 +1,21 @@
/*
* default-exceptions.js: A test fixture for logging exceptions with the default winston logger.
*
* (C) 2011 Charlie Robbins
* MIT LICENCE
*
*/
var path = require('path'),
winston = require('../../../lib/winston');
winston.handleExceptions([
new (winston.transports.File)({
filename: path.join(__dirname, '..', 'logs', 'default-exception.log'),
handleExceptions: true
})
]);
setTimeout(function () {
throw new Error('OH NOES! It failed!');
}, 1000);

View File

@@ -0,0 +1,25 @@
/*
* default-exceptions.js: A test fixture for logging exceptions with the default winston logger.
*
* (C) 2011 Charlie Robbins
* MIT LICENCE
*
*/
var path = require('path'),
winston = require('../../../lib/winston');
winston.exitOnError = function (err) {
return err.message !== 'Ignore this error';
};
winston.handleExceptions([
new (winston.transports.File)({
filename: path.join(__dirname, '..', 'logs', 'exit-on-error.log'),
handleExceptions: true
})
]);
setTimeout(function () {
throw new Error('Ignore this error');
}, 1000);

View File

@@ -0,0 +1,25 @@
/*
* log-exceptions.js: A test fixture for logging exceptions in winston.
*
* (C) 2011 Charlie Robbins
* MIT LICENCE
*
*/
var path = require('path'),
winston = require('../../../lib/winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
filename: path.join(__dirname, '..', 'logs', 'exception.log'),
handleExceptions: true
})
]
});
logger.handleExceptions();
setTimeout(function () {
throw new Error('OH NOES! It failed!');
}, 1000);

View File

@@ -0,0 +1,26 @@
/*
* unhandle-exceptions.js: A test fixture for using `.unhandleExceptions()` winston.
*
* (C) 2011 Charlie Robbins
* MIT LICENCE
*
*/
var path = require('path'),
winston = require('../../../lib/winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
filename: path.join(__dirname, '..', 'logs', 'unhandle-exception.log'),
handleExceptions: true
})
]
});
logger.handleExceptions();
logger.unhandleExceptions();
setTimeout(function () {
throw new Error('OH NOES! It failed!');
}, 1000);

183
node_modules/winston/test/helpers.js generated vendored Normal file
View File

@@ -0,0 +1,183 @@
/*
* helpers.js: Test helpers for winston
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn,
util = require('util'),
vows = require('vows'),
winston = require('../lib/winston');
var helpers = exports;
helpers.size = function (obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
size++;
}
}
return size;
};
helpers.tryUnlink = function (file) {
try { fs.unlinkSync(file) }
catch (ex) { }
};
helpers.assertDateInfo = function (info) {
assert.isNumber(Date.parse(info));
};
helpers.assertProcessInfo = function (info) {
assert.isNumber(info.pid);
assert.isNumber(info.uid);
assert.isNumber(info.gid);
assert.isString(info.cwd);
assert.isString(info.execPath);
assert.isString(info.version);
assert.isArray(info.argv);
assert.isObject(info.memoryUsage);
};
helpers.assertOsInfo = function (info) {
assert.isArray(info.loadavg);
assert.isNumber(info.uptime);
};
helpers.assertTrace = function (trace) {
trace.forEach(function (site) {
assert.isTrue(!site.column || typeof site.column === 'number');
assert.isTrue(!site.line || typeof site.line === 'number');
assert.isTrue(!site.file || typeof site.file === 'string');
assert.isTrue(!site.method || typeof site.method === 'string');
assert.isTrue(!site.function || typeof site.function === 'string');
assert.isTrue(typeof site.native === 'boolean');
});
};
helpers.assertLogger = function (logger, level) {
assert.instanceOf(logger, winston.Logger);
assert.isFunction(logger.log);
assert.isFunction(logger.add);
assert.isFunction(logger.remove);
assert.equal(logger.level, level || "info");
Object.keys(logger.levels).forEach(function (method) {
assert.isFunction(logger[method]);
});
};
helpers.assertConsole = function (transport) {
assert.instanceOf(transport, winston.transports.Console);
assert.isFunction(transport.log);
};
helpers.assertMemory = function (transport) {
assert.instanceOf(transport, winston.transports.Memory);
assert.isFunction(transport.log);
};
helpers.assertFile = function (transport) {
assert.instanceOf(transport, winston.transports.File);
assert.isFunction(transport.log);
}
helpers.assertDailyRotateFile = function (transport) {
assert.instanceOf(transport, winston.transports.DailyRotateFile);
assert.isFunction(transport.log);
}
helpers.assertWebhook = function (transport) {
assert.instanceOf(transport, winston.transports.Webhook);
assert.isFunction(transport.log);
};
helpers.assertCouchdb = function (transport) {
assert.instanceOf(transport, winston.transports.Couchdb);
assert.isFunction(transport.log);
};
helpers.assertHandleExceptions = function (options) {
return {
topic: function () {
var that = this,
child = spawn('node', [options.script]);
helpers.tryUnlink(options.logfile);
child.on('exit', function () {
fs.readFile(options.logfile, that.callback);
});
},
"should save the error information to the specified file": function (err, data) {
assert.isTrue(!err);
data = JSON.parse(data);
assert.isObject(data);
helpers.assertProcessInfo(data.process);
helpers.assertOsInfo(data.os);
helpers.assertTrace(data.trace);
}
}
}
helpers.testNpmLevels = function (transport, assertMsg, assertFn) {
return helpers.testLevels(winston.config.npm.levels, transport, assertMsg, assertFn);
};
helpers.testSyslogLevels = function (transport, assertMsg, assertFn) {
return helpers.testLevels(winston.config.syslog.levels, transport, assertMsg, assertFn);
};
helpers.testLevels = function (levels, transport, assertMsg, assertFn) {
var tests = {};
Object.keys(levels).forEach(function (level) {
var test = {
topic: function () {
transport.log(level, 'test message', {}, this.callback.bind(this, null));
}
};
test[assertMsg] = assertFn;
tests['with the ' + level + ' level'] = test;
});
var metadatatest = {
topic: function () {
transport.log('info', 'test message', { metadata: true }, this.callback.bind(this, null));
}
};
metadatatest[assertMsg] = assertFn;
tests['when passed metadata'] = metadatatest;
var primmetadatatest = {
topic: function () {
transport.log('info', 'test message', 'metadata', this.callback.bind(this, null));
}
};
primmetadatatest[assertMsg] = assertFn;
tests['when passed primitive metadata'] = primmetadatatest;
var circmetadata = { };
circmetadata['metadata'] = circmetadata;
var circmetadatatest = {
topic: function () {
transport.log('info', 'test message', circmetadata, this.callback.bind(this, null));
}
};
circmetadatatest[assertMsg] = assertFn;
tests['when passed circular metadata'] = circmetadatatest;
return tests;
};

60
node_modules/winston/test/log-exception-test.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
/*
* exception-test.js: Tests for exception data gathering in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
path = require('path'),
fs = require('fs'),
spawn = require('child_process').spawn,
vows = require('vows'),
winston = require('../lib/winston'),
helpers = require('./helpers'),
exists = (fs.exists || path.exists);
vows.describe('winston/logger/exceptions').addBatch({
"When using winston": {
"the handleException() method": {
"with a custom winston.Logger instance": helpers.assertHandleExceptions({
script: path.join(__dirname, 'fixtures', 'scripts', 'log-exceptions.js'),
logfile: path.join(__dirname, 'fixtures', 'logs', 'exception.log')
}),
"with the default winston logger": helpers.assertHandleExceptions({
script: path.join(__dirname, 'fixtures', 'scripts', 'default-exceptions.js'),
logfile: path.join(__dirname, 'fixtures', 'logs', 'default-exception.log')
}),
"when a custom exitOnError function is set": {
topic: function () {
var that = this,
scriptDir = path.join(__dirname, 'fixtures', 'scripts');
that.child = spawn('node', [path.join(scriptDir, 'exit-on-error.js')]);
setTimeout(this.callback.bind(this), 1500);
},
"should not exit the process": function () {
assert.isFalse(this.child.killed);
this.child.kill();
}
}
},
"the unhandleException() method": {
topic: function () {
var that = this,
child = spawn('node', [path.join(__dirname, 'fixtures', 'scripts', 'unhandle-exceptions.js')]),
exception = path.join(__dirname, 'fixtures', 'logs', 'unhandle-exception.log');
helpers.tryUnlink(exception);
child.on('exit', function () {
exists(exception, that.callback.bind(this, null));
});
},
"should not write to the specified error file": function (err, exists) {
assert.isTrue(!err);
assert.isFalse(exists);
}
}
}
}).export(module);

98
node_modules/winston/test/log-rewriter-test.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
/*
* log-rewriter-test.js: Tests for rewriting metadata in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
vows = require('vows'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston/logger/rewriter').addBatch({
"An instance of winston.Logger": {
topic: new (winston.Logger)({transports: [
new (winston.transports.Console)({ level: 'info' })
]}),
"the addRewriter() method": {
topic: function (logger) {
logger.addRewriter(function (level, msg, meta) {
meta.level = level;
meta.msg = msg;
meta.foo = 'bar';
return meta;
});
return logger;
},
"should add the rewriter": function (logger) {
assert.equal(helpers.size(logger.rewriters), 1);
},
"the log() method": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message', {"a": "b"});
},
"should run the rewriter": function (transport, level, msg, meta) {
assert.equal(meta.a, 'b');
assert.equal(meta.level, 'info');
assert.equal(meta.msg, 'test message');
assert.equal(meta.foo, 'bar');
}
}
}
}
}).addBatch({
"An instance of winston.Logger with explicit rewriter": {
topic: new (winston.Logger)({transports: [
new (winston.transports.Console)({ level: 'info'})
], rewriters: [
function (level, msg, meta) {
meta.level = level;
meta.msg = msg;
meta.foo = 'bar';
return meta;
}
]}),
"should add the rewriter": function (logger) {
assert.equal(helpers.size(logger.rewriters), 1);
},
"the log() method": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message', {"a": "b"});
},
"should run the rewriter": function (transport, level, msg, meta) {
assert.equal(meta.a, 'b');
assert.equal(meta.level, 'info');
assert.equal(meta.msg, 'test message');
assert.equal(meta.foo, 'bar');
}
}
}
}).addBatch({
"An instance of winston.Logger with rewriters": {
topic: new (winston.Logger)({transports: [
new (winston.transports.Console)({ level: 'info' })
], rewriters: [
function (level, msg, meta) {
meta.numbers.push(1);
return meta;
},
function (level, msg, meta) {
meta.numbers.push(2);
return meta;
}
]}),
"the log() method": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message', {"numbers": [0]});
},
"should run the rewriters in correct order": function (transport, level, msg, meta) {
assert.deepEqual(meta.numbers, [0, 1, 2]);
}
}
}
}).export(module);

116
node_modules/winston/test/logger-levels-test.js generated vendored Normal file
View File

@@ -0,0 +1,116 @@
/*
* log-rewriter-test.js: Tests for rewriting metadata in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
vows = require('vows'),
winston = require('../lib/winston'),
util = require('util'),
helpers = require('./helpers');
vows.describe('winston/logger/levels').addBatch({
"The winston logger": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.Console)()
]
}),
"the info() method": {
"when passed metadata": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message', {foo: 'bar'});
},
"should have metadata object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message');
assert.deepEqual(meta, {foo: 'bar'});
}
}
},
"when passed a string placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %s', 'my string');
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message my string');
},
},
"when passed a number placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %d', 123);
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message 123');
},
},
"when passed a json placholder and an empty object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %j', {number: 123}, {});
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message {"number":123}');
},
},
"when passed a escaped percent sign": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %%', {number: 123});
},
"should not interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, util.format('test message %%'));
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolation strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %s, %s', 'first', 'second' ,{number: 123});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message', 'first', 'second' , {number: 123});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolations strings, meta object and a callback": {
topic: function (logger) {
var that = this;
logger.info('test message %s, %s', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings, a meta object and a callback": {
topic: function (logger) {
var that = this;
logger.info('test message', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
}
}
}
}).export(module);

346
node_modules/winston/test/logger-test.js generated vendored Executable file
View File

@@ -0,0 +1,346 @@
/*
* logger-test.js: Tests for instances of the winston Logger
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
util = require('util'),
winston = require('../lib/winston'),
helpers = require('./helpers'),
transport = require('./transports/transport');
vows.describe('winton/logger').addBatch({
"An instance of winston.Logger": {
topic: new (winston.Logger)({ transports: [new (winston.transports.Console)({ level: 'info' })] }),
"should have the correct methods / properties defined": function (logger) {
helpers.assertLogger(logger);
},
"the add() with an unsupported transport": {
"should throw an error": function () {
assert.throws(function () { logger.add('unsupported') }, Error);
}
}
}
}).addBatch({
"An instance of winston.Logger": {
topic: new (winston.Logger)({ transports: [new (winston.transports.Console)({ level: 'info' })] }),
"the log() method": {
"when listening for the 'logging' event": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message');
},
"should emit the 'log' event with the appropriate transport": function (transport, ign) {
helpers.assertConsole(transport);
}
},
"when listening for the 'logged' event": {
topic: function (logger) {
logger.once('logged', this.callback);
logger.log('info', 'test message');
},
"should emit the 'logged' event": function (level, msg, meta) {
assert.equal(level, 'info');
assert.equal(msg, 'test message');
}
},
}
}
}).addBatch({
"An instance of winston.Logger with no transports": {
topic: new (winston.Logger)({ emitErrs: true }),
"the log() method should throw an error": function (logger) {
assert.throws(function () { logger.log('anything') }, Error);
},
"the extend() method called on an empty object": {
topic: function (logger) {
var empty = {};
logger.extend(empty);
return empty;
},
"should define the appropriate methods": function (extended) {
['log', 'profile', 'startTimer'].concat(Object.keys(winston.config.npm.levels)).forEach(function (method) {
assert.isFunction(extended[method]);
});
}
},
"the add() method with a supported transport": {
topic: function (logger) {
return logger.add(winston.transports.Console);
},
"should add the console Transport onto transports": function (logger) {
assert.equal(helpers.size(logger.transports), 1);
helpers.assertConsole(logger.transports.console);
},
"should throw an error when the same Transport is added": function (logger) {
assert.throws(function () { logger.add(winston.transports.Console) }, Error);
},
"the profile() method": {
"when passed a callback": {
topic: function (logger) {
var cb = this.callback;
logger.profile('test1');
setTimeout(function () {
logger.profile('test1', function (err, level, msg, meta) {
cb(err, level, msg, meta, logger);
});
}, 50);
},
"should respond with the appropriate profile message": function (err, level, msg, meta, logger) {
assert.isNull(err);
assert.equal(level, 'info');
assert.match(meta.duration, /(\d+)ms/);
assert.isTrue(typeof logger.profilers['test'] === 'undefined');
},
"when passed some metadata": {
topic: function () {
var logger = arguments[arguments.length - 1];
var cb = this.callback.bind(null, null);
logger.profile('test3');
setTimeout(function () {
logger.once('logging', cb);
logger.profile('test3', {
some: 'data'
});
}, 50);
},
"should respond with the right metadata": function (err, transport, level, msg, meta) {
assert.equal(msg, 'test3');
assert.isNull(err);
assert.equal(level, 'info');
assert.match(meta.duration, /(\d+)ms/);
assert.equal(meta.some, 'data');
},
"when not passed a callback": {
topic: function () {
var logger = arguments[arguments.length - 1];
var cb = this.callback.bind(null, null);
logger.profile('test2');
setTimeout(function () {
logger.once('logging', cb);
logger.profile('test2');
}, 50);
},
"should respond with the appropriate profile message": function (err, transport, level, msg, meta) {
assert.isNull(err);
assert.equal(msg, 'test2');
assert.equal(level, 'info');
assert.match(meta.duration, /(\d+)ms/);
}
}
}
}
},
"the startTimer() method": {
"when passed a callback": {
topic: function (logger) {
var that = this;
var timer = logger.startTimer()
setTimeout(function () {
timer.done('test', function (err, level, msg, meta) {
that.callback(err, level, msg, meta, logger);
});
}, 1000);
},
"should respond with the appropriate message": function (err, level, msg, meta, logger) {
assert.isNull(err);
assert.equal(level, 'info');
assert.match(meta.duration, /(\d+)ms/);
}
},
"when not passed a callback": {
topic: function (logger) {
var that = this;
var timer = logger.startTimer()
logger.once('logging', that.callback.bind(null, null));
setTimeout(function () {
timer.done();
}, 1000);
},
"should respond with the appropriate message": function (err, transport, level, msg, meta) {
assert.isNull(err);
assert.equal(level, 'info');
assert.match(meta.duration, /(\d+)ms/);
var duration = parseInt(meta.duration);
assert.isNumber(duration);
assert.isTrue(duration >= 50 && duration < 100);
}
}
},
"and adding an additional transport": {
topic: function (logger) {
return logger.add(winston.transports.File, {
filename: path.join(__dirname, 'fixtures', 'logs', 'testfile2.log')
});
},
"should be able to add multiple transports": function (logger) {
assert.equal(helpers.size(logger.transports), 2);
helpers.assertConsole(logger.transports.console);
helpers.assertFile(logger.transports.file);
}
}
}
}
}).addBatch({
"The winston logger": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename: path.join(__dirname, 'fixtures', 'logs', 'filelog.log' )})
]
}),
"should return have two transports": function (logger) {
assert.equal(helpers.size(logger.transports), 2);
},
"the remove() with an unadded transport": {
"should throw an Error": function (logger) {
assert.throws(function () { logger.remove(winston.transports.Webhook) }, Error);
}
},
"the remove() method with an added transport": {
topic: function (logger) {
return logger.remove(winston.transports.Console);
},
"should remove the Console transport from transports": function (logger) {
assert.equal(helpers.size(logger.transports), 1);
helpers.assertFile(logger.transports.file);
},
"and removing an additional transport": {
topic: function (logger) {
return logger.remove(winston.transports.File);
},
"should remove File transport from transports": function (logger) {
assert.equal(helpers.size(logger.transports), 0);
}
}
}
}
}).addBatch({
"The winston logger": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename: path.join(__dirname, 'fixtures', 'logs', 'filelog.log' )})
]
}),
"the clear() method": {
"should remove all transports": function (logger) {
logger.clear();
assert.equal(helpers.size(logger.transports), 0);
}
}
}
}).addBatch({
"The winston logger": {
topic: new (winston.Logger)({
exceptionHandlers: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename: path.join(__dirname, 'fixtures', 'logs', 'filelog.log' )})
]
}),
"the unhandleExceptions() method": {
"should remove all transports": function (logger) {
assert.equal(helpers.size(logger.exceptionHandlers), 2);
logger.unhandleExceptions();
assert.equal(helpers.size(logger.exceptionHandlers), 0);
}
}
}
}).addBatch({
"The winston logger": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.Console)()
]
}),
"the log() method": {
"when passed a string placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message %s', 'my string');
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message my string');
},
},
"when passed a number placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message %d', 123);
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message 123');
},
},
"when passed a json placholder and an empty object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message %j', {number: 123}, {});
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message {"number":123}');
},
},
"when passed a escaped percent sign": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message %%', {number: 123});
},
"should not interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, util.format('test message %%'));
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolation strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message %s, %s', 'first', 'second' ,{number: 123});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.log('info', 'test message', 'first', 'second' , {number: 123});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolations strings, meta object and a callback": {
topic: function (logger) {
var that = this;
logger.log('info', 'test message %s, %s', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings, a meta object and a callback": {
topic: function (logger) {
var that = this;
logger.log('info', 'test message', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
},
}
}
}
}).export(module);

39
node_modules/winston/test/transports/console-test.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
/*
* console-test.js: Tests for instances of the Console transport
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var npmTransport = new (winston.transports.Console)(),
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels });
vows.describe('winston/transports/console').addBatch({
"An instance of the Console Transport": {
"with npm levels": {
"should have the proper methods defined": function () {
helpers.assertConsole(npmTransport);
},
"the log() method": helpers.testNpmLevels(npmTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
},
"with syslog levels": {
"should have the proper methods defined": function () {
helpers.assertConsole(syslogTransport);
},
"the log() method": helpers.testSyslogLevels(syslogTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).export(module);

View File

@@ -0,0 +1,62 @@
/*
* file-test.js: Tests for instances of the Daily Rotate File transport
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
fs = require('fs'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var transport = require('./transport');
var stream = fs.createWriteStream(
path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log.2012-12-18')
),
dailyRotateFileTransport = new (winston.transports.DailyRotateFile)({
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log'),
datePattern: '.yyyy-MM-dd'
}),
streamTransport = new (winston.transports.DailyRotateFile)({ stream: stream });
vows.describe('winston/transports/daily-rotate-file').addBatch({
"An instance of the Daily Rotate File Transport": {
"when passed a valid filename": {
"should have the proper methods defined": function () {
helpers.assertDailyRotateFile(dailyRotateFileTransport);
},
"the log() method": helpers.testNpmLevels(dailyRotateFileTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
},
"when passed a valid file stream": {
"should have the proper methods defined": function () {
helpers.assertDailyRotateFile(streamTransport);
},
"the log() method": helpers.testNpmLevels(streamTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).addBatch({
"These tests have a non-deterministic end": {
topic: function () {
setTimeout(this.callback, 200);
},
"and this should be fixed before releasing": function () {
assert.isTrue(true);
}
}
}).addBatch({
"An instance of the Daily Rotate File Transport": transport(winston.transports.DailyRotateFile, {
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log'),
datePattern: '.2012-12-18'
})
}).export(module);

View File

@@ -0,0 +1,102 @@
/*
* file-maxfiles-test.js: Tests for instances of the File transport setting the max file size,
* and setting a number for max files created.
* maxSize * maxFiles = total storage used by winston.
*
* (C) 2011 Daniel Aristizabal
* MIT LICENSE
*
*/
var assert = require('assert'),
exec = require('child_process').exec,
fs = require('fs'),
path = require('path'),
vows = require('vows'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var maxfilesTransport = new winston.transports.File({
timestamp: false,
json: false,
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxfiles.log'),
maxsize: 4096,
maxFiles: 3
});
vows.describe('winston/transports/file/maxfiles').addBatch({
"An instance of the File Transport": {
"when passed a valid filename": {
topic: maxfilesTransport,
"should be a valid transporter": function (transportTest) {
helpers.assertFile(transportTest);
},
"should set the maxFiles option correctly": function (transportTest) {
assert.isNumber(transportTest.maxFiles);
}
},
"when delete old test files": {
topic: function () {
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxfiles*'), this.callback);
},
"and when passed more files than the maxFiles": {
topic: function () {
var that = this,
created = 0;
function data(ch) {
return new Array(1018).join(String.fromCharCode(65 + ch));
};
function logKbytes(kbytes, txt) {
//
// With no timestamp and at the info level,
// winston adds exactly 7 characters:
// [info](4)[ :](2)[\n](1)
//
for (var i = 0; i < kbytes; i++) {
maxfilesTransport.log('info', data(txt), null, function () { });
}
}
maxfilesTransport.on('logged', function () {
if (++created === 6) {
return that.callback();
}
logKbytes(4, created);
});
logKbytes(4, created);
},
"should be only 3 files called 5.log, 4.log and 3.log": function () {
for (var num = 0; num < 6; num++) {
var file = !num ? 'testmaxfiles.log' : 'testmaxfiles' + num + '.log',
fullpath = path.join(__dirname, '..', 'fixtures', 'logs', file);
// There should be no files with that name
if (num >= 0 && num < 3) {
return assert.throws(function () {
fs.statSync(file);
}, Error);
}
// The other files should be exist
assert.doesNotThrow(function () {
fs.statSync(file);
}, Error);
}
},
"should have the correct content": function () {
['D', 'E', 'F'].forEach(function (name, inx) {
var counter = inx + 3,
logsDir = path.join(__dirname, '..', 'fixtures', 'logs'),
content = fs.readFileSync(path.join(logsDir, 'testmaxfiles' + counter + '.log'), 'utf-8');
// The content minus the 7 characters added by winston
assert.lengthOf(content.match(new RegExp(name, 'g')), 4068);
});
}
}
}
}
}).export(module);

View File

@@ -0,0 +1,82 @@
/*
* file-test.js: Tests for instances of the File transport
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
exec = require('child_process').exec,
fs = require('fs'),
path = require('path'),
vows = require('vows'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var maxsizeTransport = new winston.transports.File({
timestamp: false,
json: false,
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'),
maxsize: 4096
});
vows.describe('winston/transports/file/maxsize').addBatch({
"An instance of the File Transport": {
"when passed a valid filename": {
"the log() method": {
topic: function () {
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), this.callback);
},
"when passed more than the maxsize": {
topic: function () {
var that = this,
data = new Array(1018).join('-');
//
// Setup a list of files which we will later stat.
//
that.files = [];
function logKbytes (kbytes) {
//
// With no timestamp and at the info level,
// winston adds exactly 7 characters:
// [info](4)[ :](2)[\n](1)
//
for (var i = 0; i < kbytes; i++) {
maxsizeTransport.log('info', data, null, function () { });
}
}
maxsizeTransport.on('open', function (file) {
var match = file.match(/(\d+)\.log$/),
count = match ? match[1] : 0;
that.files.push(file);
if (that.files.length === 5) {
return that.callback();
}
logKbytes(4);
});
logKbytes(4);
},
"should create multiple files correctly": function () {
this.files.forEach(function (file) {
try {
var stats = fs.statSync(file);
assert.equal(stats.size, 4096);
}
catch (ex) {
assert.isNull(ex);
}
});
}
}
}
}
}
}).export(module);

61
node_modules/winston/test/transports/file-open-test.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
/*
* file-open-test.js: Tests for File transport "open" event
*
* (C) 2014 William Wong
* MIT LICENSE
*
*/
!function (assert, fs, os, path, vows, winston) {
'use strict';
vows.describe('winston/transports/file').addBatch({
'An instance of the File Transport': {
topic: function () {
var callback = this.callback.bind(this),
logPath = path.resolve(__dirname, '../fixtures/logs/file-open-test.log');
try {
fs.unlinkSync(logPath);
} catch (ex) {
if (ex && ex.code !== 'ENOENT') { return callback(ex); }
}
var fileTransport = new (winston.transports.File)({
filename: logPath
}),
logger = new (winston.Logger)({
transports: [fileTransport]
}),
timeline = {};
fileTransport.open(function () {
timeline.open = Date.now();
setTimeout(function () {
logger.info('Hello, World!', function () {
timeline.logged = Date.now();
});
}, 100);
setTimeout(function () {
callback(null, timeline);
}, 1000);
});
},
'should fire "open" event': function (results) {
assert.isTrue(!!results.open);
},
'should fire "logged" event': function (results) {
assert.isTrue(!!results.logged);
}
}
}).export(module);
}(
require('assert'),
require('fs'),
require('os'),
require('path'),
require('vows'),
require('../../lib/winston')
);

View File

@@ -0,0 +1,76 @@
/*
* file-stress-test.js: Tests for stressing File transport
*
* (C) 2014 William Wong
* MIT LICENSE
*
*/
!function (assert, fs, os, path, vows, winston) {
'use strict';
vows.describe('winston/transports/file').addBatch({
'A stressed instance of the File Transport': {
topic: function () {
var callback = this.callback.bind(this),
logPath = path.resolve(__dirname, '../fixtures/logs/file-stress-test.log');
try {
fs.unlinkSync(logPath);
} catch (ex) {
if (ex && ex.code !== 'ENOENT') { return callback(ex); }
}
var fileTransport = new (winston.transports.File)({
filename: logPath
}),
logger = new (winston.Logger)({
transports: [fileTransport]
});
fileTransport.on('open', function () {
setTimeout(function () {
clearInterval(interval);
logger.query({ order: 'asc' }, function (err, results) {
callback(null, results);
});
}, 100);
});
var logIndex = 0,
interval = setInterval(function () {
logger.info(++logIndex);
stress(200);
}, 0);
logger.info(++logIndex);
stress(200);
function stress(duration) {
var startTime = Date.now();
while (Date.now() - startTime < duration) {
Math.sqrt(Math.PI);
}
}
},
'should not skip any log lines': function (results) {
var testIndex = 0;
results.file.forEach(function (log) {
if (+log.message !== ++testIndex) {
throw new Error('Number skipped');
}
});
}
}
}).export(module);
}(
require('assert'),
require('fs'),
require('os'),
require('path'),
require('vows'),
require('../../lib/winston')
);

60
node_modules/winston/test/transports/file-test.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
/*
* file-test.js: Tests for instances of the File transport
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
fs = require('fs'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var transport = require('./transport');
var stream = fs.createWriteStream(
path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')
),
fileTransport = new (winston.transports.File)({
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log')
}),
streamTransport = new (winston.transports.File)({ stream: stream });
vows.describe('winston/transports/file').addBatch({
"An instance of the File Transport": {
"when passed a valid filename": {
"should have the proper methods defined": function () {
helpers.assertFile(fileTransport);
},
"the log() method": helpers.testNpmLevels(fileTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
},
"when passed a valid file stream": {
"should have the proper methods defined": function () {
helpers.assertFile(streamTransport);
},
"the log() method": helpers.testNpmLevels(streamTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).addBatch({
"These tests have a non-deterministic end": {
topic: function () {
setTimeout(this.callback, 200);
},
"and this should be fixed before releasing": function () {
assert.isTrue(true);
}
}
}).addBatch({
"An instance of the File Transport": transport(winston.transports.File, {
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')
})
}).export(module);

31
node_modules/winston/test/transports/memory-test.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var npmTransport = new (winston.transports.Memory)(),
syslogTransport = new (winston.transports.Memory)({ levels: winston.config.syslog.levels });
vows.describe('winston/transports/memory').addBatch({
"An instance of the Memory Transport": {
"with npm levels": {
"should have the proper methods defined": function () {
helpers.assertMemory(npmTransport);
},
"the log() method": helpers.testNpmLevels(npmTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
},
"with syslog levels": {
"should have the proper methods defined": function () {
helpers.assertMemory(syslogTransport);
},
"the log() method": helpers.testSyslogLevels(syslogTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).export(module);

215
node_modules/winston/test/transports/transport.js generated vendored Normal file
View File

@@ -0,0 +1,215 @@
var assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
module.exports = function (transport, options) {
var logger = transport instanceof winston.Logger
? transport
: new winston.Logger({
transports: [
new transport(options)
]
});
// hack to fix transports that don't log
// any unit of time smaller than seconds
var common = require('../../lib/winston/common');
common.timestamp = function() {
return new Date().toISOString();
};
var transport = logger.transports[logger._names[0]];
var out = {
'topic': logger,
'when passed valid options': {
'should have the proper methods defined': function () {
switch (transport.name) {
case 'console':
helpers.assertConsole(transport);
break;
case 'file':
helpers.assertFile(transport);
break;
case 'webhook':
helpers.assertWebhook(transport);
break;
case 'couchdb':
helpers.assertCouchdb(transport);
break;
}
assert.isFunction(transport.log);
}
},
'the log() method': helpers.testNpmLevels(transport,
'should respond with true', function (ign, err, logged) {
assert.isNull(err);
assert.isNotNull(logged);
}
),
'the stream() method': {
'using no options': {
'topic': function () {
if (!transport.stream) return;
logger.log('info', 'hello world', {});
var cb = this.callback,
j = 10,
i = 10,
results = [],
stream = logger.stream();
stream.on('log', function (log) {
results.push(log);
results.stream = stream;
if (!--j) cb(null, results);
});
stream.on('error', function (err) {
j = -1; //don't call the callback again
cb(err);
});
while (i--) logger.log('info', 'hello world ' + i, {});
},
'should stream logs': function (err, results) {
if (!transport.stream) return;
assert.isNull(err);
results.forEach(function (log) {
assert.ok(log.message.indexOf('hello world') === 0
|| log.message.indexOf('test message') === 0);
});
results.stream.destroy();
}
},
'using the `start` option': {
'topic': function () {
if (!transport.stream) return;
var cb = this.callback,
stream = logger.stream({ start: 0 });
stream.on('log', function (log) {
log.stream = stream;
if (cb) cb(null, log);
cb = null;
});
},
'should stream logs': function (err, log) {
if (!transport.stream) return;
assert.isNull(err);
assert.isNotNull(log.message);
log.stream.destroy();
}
}
},
'after the logs have flushed': {
topic: function () {
setTimeout(this.callback, 1000);
},
'the query() method': {
'using basic querying': {
'topic': function () {
if (!transport.query) return;
var cb = this.callback;
logger.log('info', 'hello world', {}, function () {
logger.query(cb);
});
},
'should return matching results': function (err, results) {
if (!transport.query) return;
assert.isNull(err);
results = results[transport.name];
while (!Array.isArray(results)) {
results = results[Object.keys(results).pop()];
}
var log = results.pop();
assert.ok(log.message.indexOf('hello world') === 0
|| log.message.indexOf('test message') === 0);
}
},
'using the `rows` option': {
'topic': function () {
if (!transport.query) return;
var cb = this.callback;
logger.log('info', 'hello world', {}, function () {
logger.query({ rows: 1 }, cb);
});
},
'should return one result': function (err, results) {
if (!transport.query) return;
assert.isNull(err);
results = results[transport.name];
while (!Array.isArray(results)) {
results = results[Object.keys(results).pop()];
}
assert.equal(results.length, 1);
}
},
'using `fields` and `order` option': {
'topic': function () {
if (!transport.query) return;
var cb = this.callback;
logger.log('info', 'hello world', {}, function () {
logger.query({ order: 'asc', fields: ['timestamp'] }, cb);
});
},
'should return matching results': function (err, results) {
if (!transport.query) return;
assert.isNull(err);
results = results[transport.name];
while (!Array.isArray(results)) {
results = results[Object.keys(results).pop()];
}
assert.equal(Object.keys(results[0]).length, 1);
assert.ok(new Date(results.shift().timestamp)
< new Date(results.pop().timestamp));
}
},
'using the `from` and `until` option': {
'topic': function () {
if (!transport.query) return;
var cb = this.callback;
var start = new Date - 100 * 1000;
var end = new Date + 100 * 1000;
logger.query({ from: start, until: end }, cb);
},
'should return matching results': function (err, results) {
if (!transport.query) return;
assert.isNull(err);
results = results[transport.name];
while (!Array.isArray(results)) {
results = results[Object.keys(results).pop()];
}
assert.ok(results.length >= 1);
}
},
'using a bad `from` and `until` option': {
'topic': function () {
if (!transport.query) return;
var cb = this.callback;
logger.log('info', 'bad from and until', {}, function () {
var now = new Date + 1000000;
logger.query({ from: now, until: now }, cb);
});
},
'should return no results': function (err, results) {
if (!transport.query) return;
assert.isNull(err);
results = results[transport.name];
while (!Array.isArray(results)) {
results = results[Object.keys(results).pop()];
}
results = [results.filter(function(log) {
return log.message === 'bad from and until';
}).pop()];
assert.isUndefined(results[0]);
}
}
}
}
};
return out;
};

125
node_modules/winston/test/transports/webhook-test.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
/*
* webhook-test.js: Tests for instances of the Webhook transport
*
* (C) 2011 Marak Squires
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
fs = require('fs'),
http = require('http'),
https = require('https'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');
var webhookTransport = new (winston.transports.Webhook)({
"host": "localhost",
"port": 8080,
"path": "/winston-test"
});
var httpsWebhookTransport = new (winston.transports.Webhook)({
"host": "localhost",
"port": 8081,
"path": "/winston-test",
"ssl": true
});
var authWebhookTransport = new (winston.transports.Webhook)({
"host": "localhost",
"port": 8080,
"path": "/winston-auth-test",
"auth": {
"username": "winston",
"password": "churchill"
}
});
var requestsAuthenticated = true;
var server = http.createServer(function (req, res) {
if (req.url == '/winston-auth-test') {
//
// Test if request has been correctly authenticated
//
// Strip 'Basic' from Authorization header
var signature = req.headers['authorization'].substr(6);
requestsAuthenticated = requestsAuthenticated &&
new Buffer(signature, 'base64').toString('utf8') == 'winston:churchill';
}
res.end();
});
server.listen(8080);
var httpsServer = https.createServer({
cert: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-key.pem'))
}, function (req, res) {
res.end();
});
httpsServer.listen(8081);
vows.describe('winston/transports/webhook').addBatch({
"An instance of the Webhook Transport": {
"when passed valid options": {
"should have the proper methods defined": function () {
helpers.assertWebhook(webhookTransport);
},
"the log() method": helpers.testNpmLevels(webhookTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
},
"An https instance of the Webhook Transport": {
"when passed valid options": {
"should have the proper methods defined": function () {
helpers.assertWebhook(httpsWebhookTransport);
},
"the log() method": helpers.testNpmLevels(httpsWebhookTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
},
"An http Basic Auth instance of the Webhook Transport": {
"when passed valid options": {
"should have the proper methods defined": function () {
helpers.assertWebhook(authWebhookTransport);
},
"the log() method": helpers.testNpmLevels(authWebhookTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).addBatch({
"When the tests are over": {
topic: function () {
//
// Delay destruction of the server since the
// WebHook transport responds before the request
// has actually be completed.
//
setTimeout(this.callback, 1000);
},
"the server should cleanup": function () {
server.close();
},
"requests have been correctly authenticated": function () {
assert.ok(requestsAuthenticated);
}
}
}).addBatch({
// "An instance of the Webhook Transport": transport(winston.transports.Webhook, {
// "host": "localhost",
// "port": 8080,
// "path": "/winston-test"
// })
}).export(module);

98
node_modules/winston/test/winston-test.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
/*
* logger-test.js: Tests for instances of the winston Logger
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var fs = require('fs'),
path = require('path'),
vows = require('vows'),
http = require('http'),
assert = require('assert'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston').addBatch({
"The winston module": {
topic: function () {
winston.default.transports.console.level = 'silly';
return null;
},
"should have the correct methods defined": function () {
assert.isObject(winston.transports);
assert.isFunction(winston.Transport);
assert.isTrue(!winston.transports.Transport);
assert.isFunction(winston.transports.Console);
assert.isFunction(winston.transports.File);
assert.isFunction(winston.transports.Webhook);
assert.isObject(winston.default.transports.console);
assert.isFalse(winston.emitErrs);
assert.isObject(winston.config);
['Logger', 'add', 'remove', 'extend', 'clear']
.concat(Object.keys(winston.config.npm.levels))
.forEach(function (key) {
assert.isFunction(winston[key]);
});
},
"it should": {
topic: function () {
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
},
"have the correct version set": function (err, data) {
assert.isNull(err);
data = JSON.parse(data.toString());
assert.equal(winston.version, data.version);
}
},
"the log() method": helpers.testNpmLevels(winston, "should respond without an error", function (err) {
assert.isNull(err);
}),
"the extend() method called on an empty object": {
topic: function (logger) {
var empty = {};
winston.extend(empty);
return empty;
},
"should define the appropriate methods": function (extended) {
['log', 'profile', 'startTimer'].concat(Object.keys(winston.config.npm.levels)).forEach(function (method) {
assert.isFunction(extended[method]);
});
}
}
}
}).addBatch({
"The winston module": {
"the setLevels() method": {
topic: function () {
winston.setLevels(winston.config.syslog.levels);
return null;
},
"should have the proper methods defined": function () {
assert.isObject(winston.transports);
assert.isFunction(winston.transports.Console);
assert.isFunction(winston.transports.Webhook);
assert.isObject(winston.default.transports.console);
assert.isFalse(winston.emitErrs);
assert.isObject(winston.config);
var newLevels = Object.keys(winston.config.syslog.levels);
['Logger', 'add', 'remove', 'extend', 'clear']
.concat(newLevels)
.forEach(function (key) {
assert.isFunction(winston[key]);
});
Object.keys(winston.config.npm.levels)
.filter(function (key) {
return newLevels.indexOf(key) === -1;
})
.forEach(function (key) {
assert.isTrue(typeof winston[key] === 'undefined');
});
}
}
}
}).export(module);