From c2115fbf7fd0d31122699c4effdea878fe02ef05 Mon Sep 17 00:00:00 2001 From: Yoann Ciabaud Date: Sun, 13 Mar 2016 23:57:39 +0100 Subject: [PATCH] Adds unit testing for websocket server --- package.json | 1 + test/server.js | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index d898fd0..c923a49 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "xtend": "^4.0.0" }, "devDependencies": { + "electron-webrtc": "^0.1.0", "magnet-uri": "^5.1.3", "standard": "^6.0.4", "tape": "^4.0.0", diff --git a/test/server.js b/test/server.js index 1934f75..30b38de 100644 --- a/test/server.js +++ b/test/server.js @@ -1,6 +1,7 @@ var Client = require('../') var common = require('./common') var test = require('tape') +var wrtc var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705' var peerId = new Buffer('01234567890123456789') @@ -25,7 +26,7 @@ function serverTest (t, serverType, serverFamily) { infoHash: infoHash, length: torrentLength, announce: [ announceUrl ] - }) + }, { wrtc: wrtc }) client1.start() @@ -45,14 +46,19 @@ function serverTest (t, serverType, serverFamily) { t.equal(swarm.complete, 0) t.equal(swarm.incomplete, 1) t.equal(Object.keys(swarm.peers).length, 1) - t.deepEqual(swarm.peers[hostname + ':6881'], { - type: serverType, - ip: clientIp, - port: 6881, - peerId: peerId.toString('hex'), - complete: false, - socket: undefined - }) + + if (serverType !== 'ws') { + t.deepEqual(swarm.peers[hostname + ':6881'], { + type: serverType, + ip: clientIp, + port: 6881, + peerId: peerId.toString('hex'), + complete: false, + socket: undefined + }) + } else { + t.equal(swarm.peers[peerId.toString('hex')].complete, false) + } client1.complete() @@ -73,7 +79,7 @@ function serverTest (t, serverType, serverFamily) { infoHash: infoHash, length: torrentLength, announce: [ announceUrl ] - }) + }, { wrtc: wrtc }) client2.start() @@ -82,7 +88,7 @@ function serverTest (t, serverType, serverFamily) { }) client2.once('peer', function (addr) { - t.ok(addr === hostname + ':6881' || addr === hostname + ':6882') + t.ok(addr === hostname + ':6881' || addr === hostname + ':6882' || addr.id === peerId.toString('hex')) client2.stop() client2.once('update', function (data) { @@ -109,6 +115,21 @@ function serverTest (t, serverType, serverFamily) { }) } +test('create daemon', function (t) { + wrtc = require('electron-webrtc')() + wrtc.electronDaemon.once('ready', t.end) +}) + +test('websocket server', function (t) { + serverTest(t, 'ws', 'inet') +}) + +// cleanup +test('cleanup electron-eval daemon', function (t) { + wrtc.close() + t.end() +}) + test('http ipv4 server', function (t) { serverTest(t, 'http', 'inet') })