Skip to content

Commit

Permalink
[fix test] Added failing tests for #396.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Oct 6, 2014
1 parent fffe13d commit 76f8152
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
25 changes: 25 additions & 0 deletions test/fixtures/scripts/log-string-exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* log-string-exceptions.js: A test fixture for logging string 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', 'string-exception.log'),
handleExceptions: true
})
]
});

logger.handleExceptions();

setTimeout(function () {
throw 'OMG NEVER DO THIS STRING EXCEPTIONS ARE AWFUL';
}, 1000);
19 changes: 11 additions & 8 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var assert = require('assert'),
spawn = require('child_process').spawn,
util = require('util'),
vows = require('vows'),
winston = require('../lib/winston');
winston = require('../lib/winston');

var helpers = exports;

helpers.size = function (obj) {
Expand All @@ -23,7 +23,7 @@ helpers.size = function (obj) {
size++;
}
}

return size;
};

Expand Down Expand Up @@ -123,6 +123,9 @@ helpers.assertHandleExceptions = function (options) {
helpers.assertProcessInfo(data.process);
helpers.assertOsInfo(data.os);
helpers.assertTrace(data.trace);
if (options.message) {
assert.equal('uncaughtException: ' + options.message, data.message);
}
}
}
}
Expand All @@ -137,24 +140,24 @@ helpers.testSyslogLevels = function (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;

Expand All @@ -167,7 +170,7 @@ helpers.testLevels = function (levels, transport, assertMsg, assertFn) {
primmetadatatest[assertMsg] = assertFn;
tests['when passed primitive metadata'] = primmetadatatest;

var circmetadata = { };
var circmetadata = { };
circmetadata['metadata'] = circmetadata;

var circmetadatatest = {
Expand Down
9 changes: 7 additions & 2 deletions test/log-exception-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ vows.describe('winston/logger/exceptions').addBatch({
script: path.join(__dirname, 'fixtures', 'scripts', 'default-exceptions.js'),
logfile: path.join(__dirname, 'fixtures', 'logs', 'default-exception.log')
}),
"when strings are thrown as errors": helpers.assertHandleExceptions({
script: path.join(__dirname, 'fixtures', 'scripts', 'log-string-exception.js'),
logfile: path.join(__dirname, 'fixtures', 'logs', 'string-exception.log'),
message: 'OMG NEVER DO THIS STRING EXCEPTIONS ARE AWFUL'
}),
"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);
},
Expand All @@ -45,7 +50,7 @@ vows.describe('winston/logger/exceptions').addBatch({
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));
Expand Down

0 comments on commit 76f8152

Please sign in to comment.