1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
var common = require('./common')
var http = require('http')
var test = require('tape')
var WebTorrent = require('../')
test('client.add: http url to a torrent file, string', function (t) {
t.plan(8)
var server = http.createServer(function (req, res) {
t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
res.end(common.leaves.torrent)
})
server.listen(0, function () {
var port = server.address().port
var url = 'http://127.0.0.1:' + port
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.add(url, function (torrent) {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.leaves.magnetURI)
client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
server.close(function () { t.pass('http server closed') })
client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})
})
test('client.add: filesystem path to a torrent file, string', function (t) {
t.plan(6)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.add(common.leaves.torrentPath, function (torrent) {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.leaves.magnetURI)
client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})
test('client.seed: filesystem path to file, string', function (t) {
t.plan(6)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.seed(common.leaves.contentPath, {
name: 'Leaves of Grass by Walt Whitman.epub'
}, function (torrent) {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.leaves.magnetURI)
client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})
test('client.seed: filesystem path to folder with one file, string', function (t) {
t.plan(6)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.seed(common.folder.contentPath, function (torrent) {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, common.folder.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.folder.magnetURI)
client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})
test('client.seed: filesystem path to folder with multiple files, string', function (t) {
t.plan(6)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.seed(common.numbers.contentPath, function (torrent) {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, common.numbers.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.numbers.magnetURI)
client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})
|