Fixed unit tests, now with regexes.

This commit is contained in:
Emile Cantin 2013-09-27 09:45:10 -04:00
parent abdba8e56f
commit 8b8844694f
2 changed files with 9 additions and 4 deletions

View File

@ -113,9 +113,11 @@ vows.describe('log4js cluster appender').addBatch({
}, },
"worker should serialize an Error correctly" : function(topic) { "worker should serialize an Error correctly" : function(topic) {
var expected = { stack: 'Error: Error test\n at Object.vows.describe.addBatch.when in worker mode.topic (/home/vagrant/log4js-node/test/clusteredAppender-test.js:100:53)\n at run (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:134:35)\n at EventEmitter.Suite.runBatch.callback (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:234:40)\n at EventEmitter.emit (events.js:126:20)\n at EventEmitter.vows.describe.options.Emitter.emit (/home/vagrant/log4js-node/node_modules/vows/lib/vows.js:237:24)\n at Suite.runBatch.topic (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:169:45)\n at process.startup.processNextTick.process._tickCallback (node.js:245:9)' };
assert.equal(topic.registeredProcessEvents[1].type, '::log-message'); assert.equal(topic.registeredProcessEvents[1].type, '::log-message');
assert.equal(JSON.stringify(JSON.parse(topic.registeredProcessEvents[1].event).data[0]), JSON.stringify(expected)); assert(JSON.parse(topic.registeredProcessEvents[1].event).data[0].stack);
var actual = JSON.parse(topic.registeredProcessEvents[1].event).data[0].stack;
var expectedRegex = /^Error: Error test/;
assert(actual.match(expectedRegex), "Expected: \n\n " + actual + "\n\n to match " + expectedRegex);
} }
} }

View File

@ -101,8 +101,11 @@ vows.describe('Multiprocess Appender').addBatch({
assert.equal(net.createConnectionCalled, 2); assert.equal(net.createConnectionCalled, 2);
}, },
'should serialize an Error correctly': function(net) { 'should serialize an Error correctly': function(net) {
var expected = { stack: 'Error: Error test\n at Object.vows.describe.addBatch.worker.topic (/home/vagrant/log4js-node/test/multiprocess-test.js:78:13)\n at run (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:134:35)\n at EventEmitter.Suite.runBatch.callback (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:234:40)\n at EventEmitter.emit (events.js:126:20)\n at EventEmitter.vows.describe.options.Emitter.emit (/home/vagrant/log4js-node/node_modules/vows/lib/vows.js:237:24)\n at Suite.runBatch.topic (/home/vagrant/log4js-node/node_modules/vows/lib/vows/suite.js:169:45)\n at process.startup.processNextTick.process._tickCallback (node.js:245:9)' }; assert(JSON.parse(net.data[8]).stack, "Expected:\n\n" + net.data[8] + "\n\n to have a 'stack' property");
assert.equal(net.data[8], JSON.stringify(expected)); var actual = JSON.parse(net.data[8]).stack;
var expectedRegex = /^Error: Error test/;
assert(actual.match(expectedRegex), "Expected: \n\n " + actual + "\n\n to match " + expectedRegex);
} }
}, },
'worker with timeout': { 'worker with timeout': {