From 8b8844694f03e6e1fc946fdabba94945eca902a5 Mon Sep 17 00:00:00 2001 From: Emile Cantin Date: Fri, 27 Sep 2013 09:45:10 -0400 Subject: [PATCH] Fixed unit tests, now with regexes. --- test/clusteredAppender-test.js | 6 ++++-- test/multiprocess-test.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/clusteredAppender-test.js b/test/clusteredAppender-test.js index a8cafa3..91e0a0f 100755 --- a/test/clusteredAppender-test.js +++ b/test/clusteredAppender-test.js @@ -113,9 +113,11 @@ vows.describe('log4js cluster appender').addBatch({ }, "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(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); } } diff --git a/test/multiprocess-test.js b/test/multiprocess-test.js index e808d7f..920e72a 100644 --- a/test/multiprocess-test.js +++ b/test/multiprocess-test.js @@ -101,8 +101,11 @@ vows.describe('Multiprocess Appender').addBatch({ assert.equal(net.createConnectionCalled, 2); }, '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.equal(net.data[8], JSON.stringify(expected)); + assert(JSON.parse(net.data[8]).stack, "Expected:\n\n" + net.data[8] + "\n\n to have a 'stack' property"); + 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': {