Added node modules
This commit is contained in:
		
							
								
								
									
										40
									
								
								node_modules/winston/test/cli-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								node_modules/winston/test/cli-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										99
									
								
								node_modules/winston/test/container-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										62
									
								
								node_modules/winston/test/custom-timestamp-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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\d? \w{3}/, | ||||
|         json: false, | ||||
|         timestamp: true  | ||||
|       }), | ||||
|       "and function value": assertTimestamp('customTimestamp', { | ||||
|         pattern: /^\d{8}\./, | ||||
|         json: false, | ||||
|         timestamp: function () { | ||||
|           return '20110803.171657'; | ||||
|         } | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										46
									
								
								node_modules/winston/test/exception-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								node_modules/winston/test/exception-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * 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.assertProcessInfo(info.process); | ||||
|         helpers.assertOsInfo(info.os); | ||||
|         helpers.assertTrace(info.trace); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										0
									
								
								node_modules/winston/test/fixtures/.gitkeep
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								node_modules/winston/test/fixtures/.gitkeep
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										13
									
								
								node_modules/winston/test/fixtures/keys/agent2-cert.pem
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								node_modules/winston/test/fixtures/keys/agent2-cert.pem
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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----- | ||||
							
								
								
									
										9
									
								
								node_modules/winston/test/fixtures/keys/agent2-key.pem
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								node_modules/winston/test/fixtures/keys/agent2-key.pem
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										0
									
								
								node_modules/winston/test/fixtures/logs/.gitkeep
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										21
									
								
								node_modules/winston/test/fixtures/scripts/default-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								node_modules/winston/test/fixtures/scripts/default-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										25
									
								
								node_modules/winston/test/fixtures/scripts/exit-on-error.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								node_modules/winston/test/fixtures/scripts/exit-on-error.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										25
									
								
								node_modules/winston/test/fixtures/scripts/log-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								node_modules/winston/test/fixtures/scripts/log-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										26
									
								
								node_modules/winston/test/fixtures/scripts/unhandle-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								node_modules/winston/test/fixtures/scripts/unhandle-exceptions.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										179
									
								
								node_modules/winston/test/helpers.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										179
									
								
								node_modules/winston/test/helpers.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,179 @@ | ||||
| /* | ||||
|  * 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'), | ||||
|     loggly = require('loggly'), | ||||
|     vows = require('vows'), | ||||
|     winston = require('../lib/winston');     | ||||
|      | ||||
| var helpers = exports; | ||||
|  | ||||
| helpers.loadConfig = function (dir) { | ||||
|   try { | ||||
|     if (helpers.config) return helpers.config; | ||||
|     var configFile = path.join(dir || __dirname, 'fixtures', 'test-config.json'), | ||||
|         stats = fs.statSync(configFile), | ||||
|         config = JSON.parse(fs.readFileSync(configFile).toString()); | ||||
|      | ||||
|     helpers.config = config; | ||||
|     return config; | ||||
|   } | ||||
|   catch (ex) { | ||||
|     console.error('test/fixtures/test-config.json must be created with valid data before running tests'); | ||||
|     return false; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| 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.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.assertFile = function (transport) { | ||||
|   assert.instanceOf(transport, winston.transports.File); | ||||
|   assert.isFunction(transport.log); | ||||
| } | ||||
|  | ||||
| helpers.assertLoggly = function (transport) { | ||||
|   assert.instanceOf(transport, winston.transports.Loggly); | ||||
|   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; | ||||
|  | ||||
|   return tests; | ||||
| }; | ||||
							
								
								
									
										58
									
								
								node_modules/winston/test/log-exception-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								node_modules/winston/test/log-exception-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| /* | ||||
|  * exception-test.js: Tests for exception data gathering in winston. | ||||
|  * | ||||
|  * (C) 2010 Charlie Robbins | ||||
|  * MIT LICENSE | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| var assert = require('assert'), | ||||
|     path = require('path'), | ||||
|     spawn = require('child_process').spawn, | ||||
|     vows = require('vows'), | ||||
|     winston = require('../lib/winston'), | ||||
|     helpers = require('./helpers'); | ||||
|  | ||||
| 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 () { | ||||
|           path.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); | ||||
							
								
								
									
										184
									
								
								node_modules/winston/test/logger-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								node_modules/winston/test/logger-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,184 @@ | ||||
| /* | ||||
|  * 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'), | ||||
|     winston = require('../lib/winston'), | ||||
|     helpers = require('./helpers'); | ||||
|  | ||||
| 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 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 log() method": { | ||||
|         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); | ||||
|         } | ||||
|       }, | ||||
|       "the profile() method": { | ||||
|         "when passed a callback": { | ||||
|           topic: function (logger) { | ||||
|             var that = this; | ||||
|             logger.profile('test1'); | ||||
|             setTimeout(function () { | ||||
|               logger.profile('test1', function (err, level, msg, meta) { | ||||
|                 that.callback(err, level, msg, meta, logger); | ||||
|               }); | ||||
|             }, 1000); | ||||
|           }, | ||||
|           "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 not passed a callback": { | ||||
|           topic: function (logger) { | ||||
|             var that = this; | ||||
|             logger.profile('test2'); | ||||
|             logger.once('logging', that.callback.bind(null, null)); | ||||
|             setTimeout(function () { | ||||
|               logger.profile('test2'); | ||||
|             }, 1000); | ||||
|           }, | ||||
|           "should respond with the appropriate profile message": function (err, transport, level, msg, meta) { | ||||
|             assert.isNull(err); | ||||
|             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 > 900 && duration < 1100); | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|       "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.Loggly) }, 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); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										39
									
								
								node_modules/winston/test/transports/console-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								node_modules/winston/test/transports/console-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										47
									
								
								node_modules/winston/test/transports/couchdb-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								node_modules/winston/test/transports/couchdb-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| /* | ||||
|  * couchdb-test.js: Tests for instances of the Couchdb transport | ||||
|  * | ||||
|  * (C) 2011 Max Ogden | ||||
|  * MIT LICENSE | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| var path = require('path'), | ||||
|     vows = require('vows'), | ||||
|     fs = require('fs'), | ||||
|     http = require('http'), | ||||
|     assert = require('assert'), | ||||
|     winston = require('../../lib/winston'), | ||||
|     helpers = require('../helpers'); | ||||
|  | ||||
| var couchdbTransport = new (winston.transports.Couchdb)({  | ||||
|   "host": "localhost", | ||||
|   "port": 1337, | ||||
|   "db": "logs" | ||||
| }); | ||||
|  | ||||
| var server = http.createServer(function (req, res) { | ||||
|   res.end(); | ||||
| }); | ||||
|  | ||||
| server.listen(1337); | ||||
|  | ||||
| vows.describe('winston/transports/couchdb').addBatch({ | ||||
|   "An instance of the Couchdb Transport": { | ||||
|     "when passed valid options": { | ||||
|       "should have the proper methods defined": function () { | ||||
|         helpers.assertCouchdb(couchdbTransport); | ||||
|       }, | ||||
|       "the log() method": helpers.testNpmLevels(couchdbTransport, "should respond with true", function (ign, err, logged) { | ||||
|         assert.isNull(err); | ||||
|         assert.isTrue(logged); | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| }).addBatch({ | ||||
|   "When the tests are over": { | ||||
|     "the server should cleanup": function () { | ||||
|       server.close(); | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										102
									
								
								node_modules/winston/test/transports/file-maxfiles-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								node_modules/winston/test/transports/file-maxfiles-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										82
									
								
								node_modules/winston/test/transports/file-maxsize-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								node_modules/winston/test/transports/file-maxsize-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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); | ||||
							
								
								
									
										50
									
								
								node_modules/winston/test/transports/file-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								node_modules/winston/test/transports/file-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| /* | ||||
|  * 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 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); | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										61
									
								
								node_modules/winston/test/transports/loggly-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								node_modules/winston/test/transports/loggly-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| /* | ||||
|  * loggly-test.js: Tests for instances of the Loggly 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 config = helpers.loadConfig(); | ||||
|  | ||||
| if (!config) { | ||||
|   return; | ||||
| } | ||||
|  | ||||
| var tokenTransport = new (winston.transports.Loggly)({ | ||||
|       subdomain: config.transports.loggly.subdomain, | ||||
|       inputToken: config.transports.loggly.inputToken | ||||
|     }), | ||||
|     nameTransport = new (winston.transports.Loggly)({  | ||||
|       subdomain: config.transports.loggly.subdomain, | ||||
|       inputName: config.transports.loggly.inputName, | ||||
|       auth: config.transports.loggly.auth | ||||
|     }); | ||||
|  | ||||
| vows.describe('winston/transports/loggly').addBatch({ | ||||
|   "An instance of the Loggly Transport": { | ||||
|     "when passed an input token": { | ||||
|       "should have the proper methods defined": function () { | ||||
|         helpers.assertLoggly(tokenTransport); | ||||
|       }, | ||||
|       "the log() method": helpers.testNpmLevels(tokenTransport, "should log messages to loggly", function (ign, err, logged) { | ||||
|         assert.isNull(err); | ||||
|         assert.isTrue(logged); | ||||
|       }), | ||||
|       "the log() method with no metadata": { | ||||
|         topic: function () { | ||||
|         tokenTransport.log('info', 'test-message', null, this.callback.bind(null, null)); | ||||
|         }, | ||||
|         "should respond immediately": function () { | ||||
|           assert.isTrue(true); | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "when passed an input name": { | ||||
|       "should have the proper methods defined": function () { | ||||
|         helpers.assertLoggly(nameTransport); | ||||
|       }, | ||||
|       "the log() method": helpers.testNpmLevels(nameTransport, "should log messages to loggly", function (ign, err, result) { | ||||
|         assert.isNull(err); | ||||
|         assert.isTrue(result === true || result.response === 'ok'); | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
|  | ||||
							
								
								
									
										119
									
								
								node_modules/winston/test/transports/webhook-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								node_modules/winston/test/transports/webhook-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,119 @@ | ||||
| /* | ||||
|  * 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); | ||||
|     } | ||||
|   } | ||||
| }).export(module); | ||||
							
								
								
									
										100
									
								
								node_modules/winston/test/winston-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								node_modules/winston/test/winston-test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,100 @@ | ||||
| /* | ||||
|  * 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.Loggly); | ||||
|       assert.isFunction(winston.transports.Webhook); | ||||
|       assert.isObject(winston.default.transports.console); | ||||
|       assert.isFalse(winston.emitErrs); | ||||
|       assert.isObject(winston.config); | ||||
|       ['Logger', 'add', 'remove', 'extend'] | ||||
|         .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.Loggly); | ||||
|         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'] | ||||
|           .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); | ||||
		Reference in New Issue
	
	Block a user