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>2014-12-30 06:52:01 +0300
committerFeross Aboukhadijeh <feross@feross.org>2014-12-30 06:52:01 +0300
commitffcb0700e73a2fb21ff7d2a1bd3a19340823fcfa (patch)
treee5c6be77a5f84d7fa5b7711e08c5ef43ba654b15 /test
parent3db656bd9b427339bcbd1ec38b0fe2e50d5588e8 (diff)
add `torrent.magnetURI` getter function
Depends on https://github.com/feross/parse-torrent/pull/8
Diffstat (limited to 'test')
-rw-r--r--test/basic-node.js27
-rw-r--r--test/basic.js60
2 files changed, 64 insertions, 23 deletions
diff --git a/test/basic-node.js b/test/basic-node.js
index 6039405..ad269f0 100644
--- a/test/basic-node.js
+++ b/test/basic-node.js
@@ -10,9 +10,10 @@ var leaves = fs.readFileSync(leavesPath)
var leavesTorrent = parseTorrent(leaves)
var leavesBookPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var numbersPath = __dirname + '/content/numbers'
+var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce'
test('client.add (http url to a torrent file (string))', function (t) {
- t.plan(1)
+ t.plan(2)
var server = http.createServer(function (req, res) {
res.end(leaves)
@@ -25,6 +26,7 @@ test('client.add (http url to a torrent file (string))', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
client.add(url, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.magnetURI, leavesMagnetURI)
client.destroy()
server.close()
})
@@ -33,27 +35,41 @@ test('client.add (http url to a torrent file (string))', function (t) {
})
test('client.add (filesystem path to a torrent file (string))', function (t) {
- t.plan(1)
+ t.plan(2)
var client = new WebTorrent({ dht: false, tracker: false })
client.add(leavesPath, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.magnetURI, leavesMagnetURI)
client.destroy()
})
})
test('client.seed (filesystem path to file (string))', function (t) {
- t.plan(1)
+ t.plan(2)
+
+ 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'
+ ]
+ }
var client = new WebTorrent({ dht: false, tracker: false })
- client.seed(leavesBookPath, function (torrent) {
+ client.seed(leavesBookPath, opts, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.magnetURI, leavesMagnetURI)
client.destroy()
})
})
test('client.seed (filesystem path to folder (string))', function (t) {
- t.plan(1)
+ t.plan(2)
var opts = {
pieceLength: 32768, // force piece length to 32KB so info-hash will
@@ -66,6 +82,7 @@ test('client.seed (filesystem path to folder (string))', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
client.seed(numbersPath, opts, function (torrent) {
t.equal(torrent.infoHash, '80562f38656b385ea78959010e51a2cc9db41ea0')
+ t.equal(torrent.magnetURI, 'magnet:?xt=urn:btih:80562f38656b385ea78959010e51a2cc9db41ea0&dn=numbers&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.webtorrent.io%3A80&tr=wss%3A%2F%2Ftracker.webtorrent.io')
client.destroy()
})
})
diff --git a/test/basic.js b/test/basic.js
index 5de4f67..d244bdd 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -7,55 +7,79 @@ var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesTorrent = parseTorrent(leaves)
var leavesBook = fs.readFileSync(__dirname + '/content/Leaves of Grass by Walt Whitman.epub')
-function verify (t, client, torrent) {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- client.destroy()
-}
+var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce'
test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', function (t) {
- t.plan(5)
-
// magnet uri (utf8 string)
var client1 = new WebTorrent({ dht: false, tracker: false })
- verify(t, client1, client1.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash))
+ var torrent1 = client1.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ t.equal(torrent1.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent1.magnetURI, 'magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ client1.destroy()
// torrent file (buffer)
var client2 = new WebTorrent({ dht: false, tracker: false })
- verify(t, client2, client2.add(leaves))
+ var torrent2 = client2.add(leaves)
+ t.equal(torrent2.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent2.magnetURI, leavesMagnetURI)
+ client2.destroy()
// info hash (hex string)
var client3 = new WebTorrent({ dht: false, tracker: false })
- verify(t, client3, client3.add(leavesTorrent.infoHash))
+ var torrent3 = client3.add(leavesTorrent.infoHash)
+ t.equal(torrent3.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent3.magnetURI, 'magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ client3.destroy()
// info hash (buffer)
var client4 = new WebTorrent({ dht: false, tracker: false })
- verify(t, client4, client4.add(new Buffer(leavesTorrent.infoHash, 'hex')))
+ var torrent4 = client4.add(new Buffer(leavesTorrent.infoHash, 'hex'))
+ t.equal(torrent4.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent4.magnetURI, 'magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ client4.destroy()
// parsed torrent (from parse-torrent)
var client5 = new WebTorrent({ dht: false, tracker: false })
- verify(t, client5, client5.add(leavesTorrent))
+ var torrent5 = client5.add(leavesTorrent)
+ t.equal(torrent5.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent5.magnetURI, leavesMagnetURI)
+ client5.destroy()
+
+ t.end()
})
test('client.seed (Buffer, Blob)', function (t) {
- t.plan(2)
+ t.plan(typeof Blob !== 'undefined' ? 4 : 2)
var opts = {
- name: 'Leaves of Grass by Walt Whitman.epub'
+ 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'
+ ]
}
// torrent file (Buffer)
var client1 = new WebTorrent({ dht: false, tracker: false })
- client1.seed(leavesBook, opts, function (torrent) {
- verify(t, client1, torrent)
+ client1.seed(leavesBook, opts, function (torrent1) {
+ t.equal(torrent1.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent1.magnetURI, leavesMagnetURI)
+ client1.destroy()
})
// Blob
if (typeof Blob !== 'undefined') {
var client2 = new WebTorrent({ dht: false, tracker: false })
- client2.seed(new Blob([ leavesBook ]), opts, function (torrent) {
- verify(t, client2, torrent)
+ client2.seed(new Blob([ leavesBook ]), opts, function (torrent2) {
+ t.equal(torrent2.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent2.magnetURI, leavesMagnetURI)
+ client2.destroy()
})
} else {
- t.pass('Skipping Blob test because missing `Blob` constructor')
+ console.log('Skipping Blob test because missing `Blob` constructor')
}
})