mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-19 04:31:36 +00:00
Adds unit testing for websocket server
This commit is contained in:
parent
a79dc1eb1e
commit
c2115fbf7f
@ -42,6 +42,7 @@
|
|||||||
"xtend": "^4.0.0"
|
"xtend": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"electron-webrtc": "^0.1.0",
|
||||||
"magnet-uri": "^5.1.3",
|
"magnet-uri": "^5.1.3",
|
||||||
"standard": "^6.0.4",
|
"standard": "^6.0.4",
|
||||||
"tape": "^4.0.0",
|
"tape": "^4.0.0",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var Client = require('../')
|
var Client = require('../')
|
||||||
var common = require('./common')
|
var common = require('./common')
|
||||||
var test = require('tape')
|
var test = require('tape')
|
||||||
|
var wrtc
|
||||||
|
|
||||||
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
||||||
var peerId = new Buffer('01234567890123456789')
|
var peerId = new Buffer('01234567890123456789')
|
||||||
@ -25,7 +26,7 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
infoHash: infoHash,
|
infoHash: infoHash,
|
||||||
length: torrentLength,
|
length: torrentLength,
|
||||||
announce: [ announceUrl ]
|
announce: [ announceUrl ]
|
||||||
})
|
}, { wrtc: wrtc })
|
||||||
|
|
||||||
client1.start()
|
client1.start()
|
||||||
|
|
||||||
@ -45,14 +46,19 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
t.equal(swarm.complete, 0)
|
t.equal(swarm.complete, 0)
|
||||||
t.equal(swarm.incomplete, 1)
|
t.equal(swarm.incomplete, 1)
|
||||||
t.equal(Object.keys(swarm.peers).length, 1)
|
t.equal(Object.keys(swarm.peers).length, 1)
|
||||||
t.deepEqual(swarm.peers[hostname + ':6881'], {
|
|
||||||
type: serverType,
|
if (serverType !== 'ws') {
|
||||||
ip: clientIp,
|
t.deepEqual(swarm.peers[hostname + ':6881'], {
|
||||||
port: 6881,
|
type: serverType,
|
||||||
peerId: peerId.toString('hex'),
|
ip: clientIp,
|
||||||
complete: false,
|
port: 6881,
|
||||||
socket: undefined
|
peerId: peerId.toString('hex'),
|
||||||
})
|
complete: false,
|
||||||
|
socket: undefined
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
t.equal(swarm.peers[peerId.toString('hex')].complete, false)
|
||||||
|
}
|
||||||
|
|
||||||
client1.complete()
|
client1.complete()
|
||||||
|
|
||||||
@ -73,7 +79,7 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
infoHash: infoHash,
|
infoHash: infoHash,
|
||||||
length: torrentLength,
|
length: torrentLength,
|
||||||
announce: [ announceUrl ]
|
announce: [ announceUrl ]
|
||||||
})
|
}, { wrtc: wrtc })
|
||||||
|
|
||||||
client2.start()
|
client2.start()
|
||||||
|
|
||||||
@ -82,7 +88,7 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
client2.once('peer', function (addr) {
|
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.stop()
|
||||||
client2.once('update', function (data) {
|
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) {
|
test('http ipv4 server', function (t) {
|
||||||
serverTest(t, 'http', 'inet')
|
serverTest(t, 'http', 'inet')
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user