Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-05-29 22:59:55 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-05-29 22:59:55 +0300
commit8dfcea0e818dc072202ffef93731e74e16128c8b (patch)
tree83733afe6c8f6f136b923c3a64922eeda5e511b6 /test
parent07f0685cbf3ec8a4ddcb9ebac7b8f4343d6787e8 (diff)
moved remote torrent handling into parse-torrent@5.1
Diffstat (limited to 'test')
-rw-r--r--test/basic.js154
-rw-r--r--test/blocklist.js95
2 files changed, 131 insertions, 118 deletions
diff --git a/test/basic.js b/test/basic.js
index 9e2b9a6..4b44c46 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -14,65 +14,70 @@ test('client.add/remove: magnet uri, utf-8 string', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
- client.remove('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
+ client.remove('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.add/remove: torrent file, buffer', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(leaves)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
- client.remove(leaves)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.magnetURI, leavesMagnetURI)
+ client.remove(leaves)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.add/remove: info hash, hex string', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(leavesTorrent.infoHash)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
- client.remove(leavesTorrent.infoHash)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
+ client.remove(leavesTorrent.infoHash)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.add/remove: info hash, buffer', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(new Buffer(leavesTorrent.infoHash, 'hex'))
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
- client.remove(new Buffer(leavesTorrent.infoHash, 'hex'))
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + leavesTorrent.infoHash) === 0)
+ client.remove(new Buffer(leavesTorrent.infoHash, 'hex'))
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.add/remove: parsed torrent, from `parse-torrent`', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(leavesTorrent)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
- client.remove(leavesTorrent)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.magnetURI, leavesMagnetURI)
+ client.remove(leavesTorrent)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.add/remove: parsed torrent, with string type announce property', function (t) {
@@ -82,29 +87,30 @@ test('client.add/remove: parsed torrent, with string type announce property', fu
})
var torrent = client.add(modifiedParsedTorrent)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- client.remove(leavesTorrent)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.remove(leavesTorrent)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
test('client.remove: remove by Torrent object', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(leavesTorrent.infoHash)
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
-
- client.remove(torrent)
- t.equal(client.torrents.length, 0)
- client.destroy()
-
- t.end()
+ torrent.on('infoHash', function () {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.remove(torrent)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
+ t.end()
+ })
})
-test('client.seed (Buffer, Blob)', function (t) {
- t.plan(global.Blob !== undefined ? 8 : 4)
+test('client.seed: torrent file (Buffer)', function (t) {
+ t.plan(4)
var opts = {
name: 'Leaves of Grass by Walt Whitman.epub',
@@ -118,30 +124,44 @@ test('client.seed (Buffer, Blob)', function (t) {
]
}
- // torrent file (Buffer)
- var client1 = new WebTorrent({ dht: false, tracker: false })
- client1.seed(leavesBook, opts, function (torrent1) {
- t.equal(client1.torrents.length, 1)
+ var client = new WebTorrent({ dht: false, tracker: false })
+ client.seed(leavesBook, opts, function (torrent1) {
+ t.equal(client.torrents.length, 1)
t.equal(torrent1.infoHash, leavesTorrent.infoHash)
t.equal(torrent1.magnetURI, leavesMagnetURI)
- client1.remove(torrent1)
- t.equal(client1.torrents.length, 0)
- client1.destroy()
+ client.remove(torrent1)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
})
+})
+
+test('client.seed: torrent file (Blob)', function (t) {
+ var opts = {
+ name: 'Leaves of Grass by Walt Whitman.epub',
+ announce: [
+ 'http://tracker.thepiratebay.org/announce',
+ 'udp://tracker.openbittorrent.com:80',
+ 'udp://tracker.ccc.de:80',
+ 'udp://tracker.publicbt.com:80',
+ 'udp://fr33domtracker.h33t.com:3310/announce',
+ 'http://tracker.bittorrent.am/announce'
+ ]
+ }
- // Blob
if (global.Blob !== undefined) {
- var client2 = new WebTorrent({ dht: false, tracker: false })
- client2.seed(new global.Blob([ leavesBook ]), opts, function (torrent2) {
- t.equal(client2.torrents.length, 1)
+ t.plan(4)
+ var client = new WebTorrent({ dht: false, tracker: false })
+ client.seed(new global.Blob([ leavesBook ]), opts, function (torrent2) {
+ t.equal(client.torrents.length, 1)
t.equal(torrent2.infoHash, leavesTorrent.infoHash)
t.equal(torrent2.magnetURI, leavesMagnetURI)
- client2.remove(torrent2)
- t.equal(client2.torrents.length, 0)
- client2.destroy()
+ client.remove(torrent2)
+ t.equal(client.torrents.length, 0)
+ client.destroy()
})
} else {
- console.log('Skipping Blob test because missing `Blob` constructor')
+ t.pass('Skipping Blob test because missing `Blob` constructor')
+ t.end()
}
})
@@ -164,10 +184,10 @@ test('after client.destroy(), no "torrent" or "ready" events emitted', function
t.plan(1)
var client = new WebTorrent({ dht: false, tracker: false })
- client.add(leaves, function () {
+ client.add(leaves, { name: 'leaves' }, function () {
t.fail('unexpected "torrent" event (from add)')
})
- client.seed(leavesBook, function () {
+ client.seed(leavesBook, { name: 'leavesBook' }, function () {
t.fail('unexpected "torrent" event (from seed)')
})
client.on('ready', function () {
diff --git a/test/blocklist.js b/test/blocklist.js
index ab36bc3..bc03432 100644
--- a/test/blocklist.js
+++ b/test/blocklist.js
@@ -38,14 +38,14 @@ test('blocklist (single IP)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
+ client.add(leavesParsed, function (torrent) {
+ assertBlocked(t, torrent, '1.2.3.4:1234')
+ assertBlocked(t, torrent, '1.2.3.4:6969')
+ assertReachable(t, torrent, '1.1.1.1:1234')
+ assertReachable(t, torrent, '1.1.1.1:6969')
- assertBlocked(t, torrent, '1.2.3.4:1234')
- assertBlocked(t, torrent, '1.2.3.4:6969')
- assertReachable(t, torrent, '1.1.1.1:1234')
- assertReachable(t, torrent, '1.1.1.1:6969')
-
- client.destroy()
+ client.destroy()
+ })
})
})
@@ -59,16 +59,16 @@ test('blocklist (array of IPs)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
+ client.add(leavesParsed, function (torrent) {
+ assertBlocked(t, torrent, '1.2.3.4:1234')
+ assertBlocked(t, torrent, '1.2.3.4:6969')
+ assertBlocked(t, torrent, '5.6.7.8:1234')
+ assertBlocked(t, torrent, '5.6.7.8:6969')
+ assertReachable(t, torrent, '1.1.1.1:1234')
+ assertReachable(t, torrent, '1.1.1.1:6969')
- assertBlocked(t, torrent, '1.2.3.4:1234')
- assertBlocked(t, torrent, '1.2.3.4:6969')
- assertBlocked(t, torrent, '5.6.7.8:1234')
- assertBlocked(t, torrent, '5.6.7.8:6969')
- assertReachable(t, torrent, '1.1.1.1:1234')
- assertReachable(t, torrent, '1.1.1.1:6969')
-
- client.destroy()
+ client.destroy()
+ })
})
})
@@ -123,11 +123,10 @@ test('blocklist (array of IP ranges)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ })
})
})
@@ -137,8 +136,7 @@ test('blocklist (http url)', function (t) {
// Check that WebTorrent declares a user agent
t.equal(req.headers['user-agent'], 'WebTorrent (http://webtorrent.io)')
- fs.createReadStream(blocklistPath)
- .pipe(res)
+ fs.createReadStream(blocklistPath).pipe(res)
})
server.listen(0, function () {
@@ -151,12 +149,11 @@ test('blocklist (http url)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
- server.close()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ server.close()
+ })
})
})
})
@@ -183,12 +180,11 @@ test('blocklist (http url with gzip encoding)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
- server.close()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ server.close()
+ })
})
})
})
@@ -215,12 +211,11 @@ test('blocklist (http url with deflate encoding)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
- server.close()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ server.close()
+ })
})
})
})
@@ -234,11 +229,10 @@ test('blocklist (fs path)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ })
})
})
@@ -251,10 +245,9 @@ test('blocklist (fs path with gzip)', function (t) {
})
.on('error', function (err) { t.fail(err) })
.on('ready', function () {
- var torrent = client.add(leavesParsed)
-
- assertList(t, torrent)
-
- client.destroy()
+ client.add(leavesParsed, function (torrent) {
+ assertList(t, torrent)
+ client.destroy()
+ })
})
})