From b6fcffc3023af939ce1f23909b2479c84687414f Mon Sep 17 00:00:00 2001 From: anton Date: Mon, 24 Dec 2012 17:37:38 +0200 Subject: [PATCH] write messages for assertions --- test/unit/copystream/copyfrom-tests.js | 15 ++++++++++----- test/unit/copystream/copyto-tests.js | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/unit/copystream/copyfrom-tests.js b/test/unit/copystream/copyfrom-tests.js index bccec5af..7b96049e 100644 --- a/test/unit/copystream/copyfrom-tests.js +++ b/test/unit/copystream/copyfrom-tests.js @@ -24,7 +24,7 @@ var buf1 = new Buffer("asdfasd"), buf3 = new Buffer(542), buf4 = new Buffer("93jfemialfjkasjlfas"); -test('stream has to finish data stream to connection exactly once', function () { +test('CopyFromStream, start streaming before data, end after data. no drain event', function () { var stream = new CopyFromStream(); var conn = new ConnectionImitation(); stream.on('drain', function () { @@ -38,8 +38,9 @@ test('stream has to finish data stream to connection exactly once', function () stream.end(conn.updateHasToBeSend(buf4)); assert.ok(!stream.writable, "stream has not to be writable"); stream.end(); + assert.equal(conn.hasToBeSend, conn.send); }); -test('', function () { +test('CopyFromStream, start streaming after end, end after data. drain event', function () { var stream = new CopyFromStream(); assert.emits(stream, 'drain', function() {}, 'drain have to be emitted'); var conn = new ConnectionImitation() @@ -51,8 +52,9 @@ test('', function () { assert.ok(!stream.writable, "stream has not to be writable"); stream.end(); stream.startStreamingToConnection(conn); + assert.equal(conn.hasToBeSend, conn.send); }); -test('', function () { +test('CopyFromStream, start streaming between data chunks. end after data. drain event', function () { var stream = new CopyFromStream(); var conn = new ConnectionImitation() assert.emits(stream, 'drain', function() {}, 'drain have to be emitted'); @@ -62,10 +64,11 @@ test('', function () { stream.write(conn.updateHasToBeSend(buf3)); assert.ok(stream.writable, "stream has to be writable"); stream.end(conn.updateHasToBeSend(buf4)); + assert.equal(conn.hasToBeSend, conn.send); assert.ok(!stream.writable, "stream has not to be writable"); stream.end(); }); -test('', function () { +test('CopyFromStream, start sreaming before end. end stream with data. drain event', function () { var stream = new CopyFromStream(); var conn = new ConnectionImitation() assert.emits(stream, 'drain', function() {}, 'drain have to be emitted'); @@ -75,10 +78,11 @@ test('', function () { stream.startStreamingToConnection(conn); assert.ok(stream.writable, "stream has to be writable"); stream.end(conn.updateHasToBeSend(buf4)); + assert.equal(conn.hasToBeSend, conn.send); assert.ok(!stream.writable, "stream has not to be writable"); stream.end(); }); -test('', function(){ +test('CopyFromStream, start streaming after end. end with data. drain event', function(){ var stream = new CopyFromStream(); var conn = new ConnectionImitation() assert.emits(stream, 'drain', function() {}, 'drain have to be emitted'); @@ -89,6 +93,7 @@ test('', function(){ assert.ok(stream.writable, "stream has to be writable"); stream.end(conn.updateHasToBeSend(buf4)); stream.startStreamingToConnection(conn); + assert.equal(conn.hasToBeSend, conn.send); assert.ok(!stream.writable, "stream has not to be writable"); stream.end(); }); diff --git a/test/unit/copystream/copyto-tests.js b/test/unit/copystream/copyto-tests.js index bd5ff16c..7a6255b7 100644 --- a/test/unit/copystream/copyto-tests.js +++ b/test/unit/copystream/copyto-tests.js @@ -13,7 +13,7 @@ DataCounter.prototype = { this.recievedBytes += chunk.length; }, assert: function () { - assert.equal(this.sendBytes, this.recievedBytes); + assert.equal(this.sendBytes, this.recievedBytes, "data bytes send and recieved has to match"); } }; var buf1 = new Buffer("asdfasd"), @@ -36,7 +36,7 @@ test('CopyToStream pause/resume/close', function () { var stream = new CopyToStream(), dc = new DataCounter(); stream.on('data', dc.recieve.bind(dc)); - assert.emits(stream, 'end', function () {}, ''); + assert.emits(stream, 'end', function () {}, 'stream has to emit end after closing'); stream.pause(); stream.handleChunk(dc.send(buf1)); stream.handleChunk(dc.send(buf2)); @@ -50,7 +50,7 @@ test('CopyToStream pause/resume/close', function () { dc.assert(); stream.pause(); stream.handleChunk(dc.send(buf4)); - assert(dc.sendBytes - dc.recievedBytes, buf4.length); + assert(dc.sendBytes - dc.recievedBytes, buf4.length, "stream has not emit, data while it is in paused state"); stream.resume(); dc.assert(); stream.close(); @@ -59,7 +59,7 @@ test('CopyToStream error', function () { var stream = new CopyToStream(), dc = new DataCounter(); stream.on('data', dc.recieve.bind(dc)); - assert.emits(stream, 'error', function () {}, ''); + assert.emits(stream, 'error', function () {}, 'stream has to emit error event, when error method called'); stream.handleChunk(dc.send(buf1)); stream.handleChunk(dc.send(buf2)); stream.error(new Error('test error'));