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
diff options
context:
space:
mode:
Diffstat (limited to 'test/basic.js')
-rw-r--r--test/basic.js84
1 files changed, 38 insertions, 46 deletions
diff --git a/test/basic.js b/test/basic.js
index 4fedcb8..3a19e4c 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -1,28 +1,20 @@
-var path = require('path')
-var fs = require('fs')
+var common = require('./common')
var extend = require('xtend')
-var parseTorrent = require('parse-torrent')
var test = require('tape')
var WebTorrent = require('../')
-var leaves = fs.readFileSync(path.resolve(__dirname, 'torrents', 'leaves.torrent'))
-var leavesTorrent = parseTorrent(leaves)
-var leavesBook = fs.readFileSync(path.resolve(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub'))
-
-var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80'
-
test('client.add/remove: magnet uri, utf-8 string', function (t) {
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ var torrent = client.add('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
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(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) === 0)
+ client.remove('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -35,12 +27,12 @@ test('client.add/remove: torrent file, buffer', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leaves)
+ var torrent = client.add(common.leaves.torrent)
t.equal(client.torrents.length, 1)
torrent.on('infoHash', function () {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
- client.remove(leaves)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.equal(torrent.magnetURI, common.leaves.magnetURI)
+ client.remove(common.leaves.torrent)
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -53,12 +45,12 @@ test('client.add/remove: info hash, hex string', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leavesTorrent.infoHash)
+ var torrent = client.add(common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
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(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) === 0)
+ client.remove(common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -71,12 +63,12 @@ test('client.add/remove: info hash, buffer', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(new Buffer(leavesTorrent.infoHash, 'hex'))
+ var torrent = client.add(common.leaves.parsedTorrent.infoHashBuffer)
t.equal(client.torrents.length, 1)
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(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) === 0)
+ client.remove(new Buffer(common.leaves.parsedTorrent.infoHash, 'hex'))
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -89,12 +81,12 @@ test('client.add/remove: parsed torrent, from `parse-torrent`', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leavesTorrent)
+ var torrent = client.add(common.leaves.parsedTorrent)
t.equal(client.torrents.length, 1)
torrent.on('infoHash', function () {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
- client.remove(leavesTorrent)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.equal(torrent.magnetURI, common.leaves.magnetURI)
+ client.remove(common.leaves.parsedTorrent)
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -107,14 +99,14 @@ test('client.add/remove: parsed torrent, with string type announce property', fu
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var modifiedParsedTorrent = extend(leavesTorrent, {
- announce: leavesTorrent.announce[0]
+ var modifiedParsedTorrent = extend(common.leaves.parsedTorrent, {
+ announce: common.leaves.parsedTorrent.announce[0]
})
var torrent = client.add(modifiedParsedTorrent)
t.equal(client.torrents.length, 1)
torrent.on('infoHash', function () {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- client.remove(leavesTorrent)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ client.remove(common.leaves.parsedTorrent)
t.equal(client.torrents.length, 0)
client.destroy()
t.end()
@@ -127,10 +119,10 @@ test('client.remove: remove by Torrent object', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leavesTorrent.infoHash)
+ var torrent = client.add(common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
torrent.on('infoHash', function () {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
client.remove(torrent)
t.equal(client.torrents.length, 0)
client.destroy()
@@ -144,10 +136,10 @@ test('torrent.destroy: destroy and remove torrent', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leavesTorrent.infoHash)
+ var torrent = client.add(common.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
torrent.on('infoHash', function () {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
torrent.destroy()
t.equal(client.torrents.length, 0)
client.destroy()
@@ -175,10 +167,10 @@ test('client.seed: torrent file (Buffer)', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- client.seed(leavesBook, opts, function (torrent) {
+ client.seed(common.leaves.content, opts, function (torrent) {
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.equal(torrent.magnetURI, common.leaves.magnetURI)
client.remove(torrent)
t.equal(client.torrents.length, 0)
client.destroy()
@@ -205,10 +197,10 @@ test('client.seed: torrent file (Blob)', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- client.seed(new global.Blob([ leavesBook ]), opts, function (torrent) {
+ client.seed(new global.Blob([ common.leaves.content ]), opts, function (torrent) {
t.equal(client.torrents.length, 1)
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- t.equal(torrent.magnetURI, leavesMagnetURI)
+ t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
+ t.equal(torrent.magnetURI, common.leaves.magnetURI)
client.remove(torrent)
t.equal(client.torrents.length, 0)
client.destroy()
@@ -231,7 +223,7 @@ test('after client.destroy(), throw on client.add() or client.seed()', function
t.pass('client destroyed')
})
t.throws(function () {
- client.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
+ client.add('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash)
})
t.throws(function () {
client.seed(new Buffer('sup'))
@@ -246,10 +238,10 @@ test('after client.destroy(), no "torrent" or "ready" events emitted', function
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- client.add(leaves, { name: 'leaves' }, function () {
+ client.add(common.leaves.torrent, { name: 'leaves' }, function () {
t.fail('unexpected "torrent" event (from add)')
})
- client.seed(leavesBook, { name: 'leavesBook' }, function () {
+ client.seed(common.leaves.content, { name: 'leaves' }, function () {
t.fail('unexpected "torrent" event (from seed)')
})
client.on('ready', function () {