From e90fe728dcfeb35e7a4b2ad5332f0036181d3eaf Mon Sep 17 00:00:00 2001 From: seanstrom Date: Sat, 9 May 2015 15:02:07 -0700 Subject: [PATCH 1/2] changes tests to run assertions on tests --- tests/test-body.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test-body.js b/tests/test-body.js index a49640f87..335267bc1 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -20,6 +20,11 @@ function addTest(name, data) { t.equal(err, null) if (data.expectBody && Buffer.isBuffer(data.expectBody)) { t.deepEqual(data.expectBody.toString(), body.toString()) + } else if (data.expectBody) { + t.deepEqual(data.expectBody, body) + } else { + // not sure what to test when we dont have expectBody + console.log('untested code') } t.end() }) From 8a478f0ef36912b737df9c5aea900e7f776ed371 Mon Sep 17 00:00:00 2001 From: seanstrom Date: Tue, 12 May 2015 09:15:45 -0700 Subject: [PATCH 2/2] revise tests and test helpers --- tests/server.js | 2 +- tests/test-body.js | 3 --- tests/test-pipes.js | 9 +++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/server.js b/tests/server.js index 5c5585bb3..99d004a30 100644 --- a/tests/server.js +++ b/tests/server.js @@ -94,7 +94,7 @@ exports.createPostValidator = function (text, reqContentType) { assert.ok(~req.headers['content-type'].indexOf(reqContentType)) } resp.writeHead(200, {'content-type':'text/plain'}) - resp.write('OK') + resp.write(r) resp.end() }) } diff --git a/tests/test-body.js b/tests/test-body.js index 335267bc1..77b826d46 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -22,9 +22,6 @@ function addTest(name, data) { t.deepEqual(data.expectBody.toString(), body.toString()) } else if (data.expectBody) { t.deepEqual(data.expectBody, body) - } else { - // not sure what to test when we dont have expectBody - console.log('untested code') } t.end() }) diff --git a/tests/test-pipes.js b/tests/test-pipes.js index 0e4be002c..140c96c4d 100644 --- a/tests/test-pipes.js +++ b/tests/test-pipes.js @@ -80,7 +80,7 @@ tape('piping to a request object', function(t) { }, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(body, 'OK') + t.equal(body, 'mydata') t.end() }) mydata.pipe(r1) @@ -90,8 +90,9 @@ tape('piping to a request object', function(t) { }) tape('piping to a request object with a json body', function(t) { - s.once('/push-json', server.createPostValidator('{"foo":"bar"}', 'application/json')) - + var obj = {foo: 'bar'} + var json = JSON.stringify(obj) + s.once('/push-json', server.createPostValidator(json, 'application/json')) var mybodydata = new stream.Stream() mybodydata.readable = true @@ -101,7 +102,7 @@ tape('piping to a request object with a json body', function(t) { }, function(err, res, body) { t.equal(err, null) t.equal(res.statusCode, 200) - t.equal(body, 'OK') + t.deepEqual(body, obj) t.end() }) mybodydata.pipe(r2)