Adds unit testing for websocket server

This commit is contained in:
Yoann Ciabaud 2016-03-13 23:57:39 +01:00 committed by Feross Aboukhadijeh
parent a79dc1eb1e
commit c2115fbf7f
2 changed files with 33 additions and 11 deletions

View File

@ -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",

View File

@ -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')
})