From 0a51e59bd0ca3728a2cc85ce93fdf587b59a49cf Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 10 Jul 2014 21:00:02 -0700 Subject: [PATCH] better test error messages --- test/client.js | 47 +++++++++++++++++++++------------------------- test/server.js | 2 +- test/udp-server.js | 2 +- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/client.js b/test/client.js index 2087c01..7cf8a9f 100644 --- a/test/client.js +++ b/test/client.js @@ -13,38 +13,36 @@ var peerId = new Buffer('01234567890123456789') var announceUrl = '' var port = 6881 -function createServer (cb) { +function createServer (t, cb) { var server = new Server({ udp: false }) server.on('error', function (err) { - cb(err) + t.error(err) }) server.on('warning', function (err) { - cb(err) + t.error(err) }) portfinder.getPort(function (err, port) { - if (err) return cb(err) + if (err) return t.error(err) announceUrl = 'http://127.0.0.1:' + port + '/announce' parsedTorrent.announce = [ announceUrl ] server.listen(port) - cb(null, server) + cb(server) }) } -test('torrent: client.start()', function (t) { - t.plan(6) - - createServer(function (err, server) { - t.error(err) +test('http: client.start()', function (t) { + t.plan(5) + createServer(t, function (server) { var client = new Client(peerId, port, parsedTorrent) client.on('error', function (err) { - t.fail(err) + t.error(err) }) client.once('update', function (data) { @@ -68,15 +66,14 @@ test('torrent: client.start()', function (t) { }) }) -test('torrent: client.stop()', function (t) { - t.plan(5) +test('http: client.stop()', function (t) { + t.plan(4) - createServer(function (err, server) { - t.error(err) + createServer(t, function (server) { var client = new Client(peerId, port, parsedTorrent) client.on('error', function (err) { - t.fail(err) + t.error(err) }) client.start() @@ -99,15 +96,14 @@ test('torrent: client.stop()', function (t) { }) }) -test('torrent: client.update()', function (t) { - t.plan(5) +test('http: client.update()', function (t) { + t.plan(4) - createServer(function (err, server) { - t.error(err) + createServer(t, function (server) { var client = new Client(peerId, port, parsedTorrent, { interval: 5000 }) client.on('error', function (err) { - t.fail(err) + t.error(err) }) client.start() @@ -131,15 +127,14 @@ test('torrent: client.update()', function (t) { }) }) -test('torrent: client.scrape()', function (t) { - t.plan(6) +test('http: client.scrape()', function (t) { + t.plan(5) - createServer(function (err, server) { - t.error(err) + createServer(t, function (server) { var client = new Client(peerId, port, parsedTorrent) client.on('error', function (err) { - t.fail(err) + t.error(err) }) client.once('scrape', function (data) { diff --git a/test/server.js b/test/server.js index c3099f1..87ba2d8 100644 --- a/test/server.js +++ b/test/server.js @@ -8,7 +8,7 @@ var peerId = '01234567890123456789' var peerId2 = '12345678901234567890' var torrentLength = 50000 -test('server', function (t) { +test('http server', function (t) { t.plan(27) var server = new Server({ udp: false }) // { interval: 50000, compactOnly: false } diff --git a/test/udp-server.js b/test/udp-server.js index a034c15..c06a6ec 100644 --- a/test/udp-server.js +++ b/test/udp-server.js @@ -8,7 +8,7 @@ var peerId = '01234567890123456789' var peerId2 = '12345678901234567890' var torrentLength = 50000 -test('server', function (t) { +test('udp server', function (t) { t.plan(27) var server = new Server({ http: false })