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-17 02:27:00 +0300
committerFeross Aboukhadijeh <feross@feross.org>2014-12-17 02:43:06 +0300
commit9e55cc7eec04e07060f32d1695b44f30a7c25187 (patch)
tree02eb370c356f97733c81649de7edba888839745f /test
parent8e6503ab5dcbc698c02de88b5e0f65e015269591 (diff)
add client.seed tests (buffer, blob, path to file)
Diffstat (limited to 'test')
-rw-r--r--test/basic-node.js30
-rw-r--r--test/basic.js24
-rw-r--r--test/content/Leaves of Grass by Walt Whitman.epub (renamed from test/torrents/Leaves of Grass by Walt Whitman.epub)bin362017 -> 362017 bytes
-rw-r--r--test/download.js2
-rw-r--r--test/server.js2
5 files changed, 45 insertions, 13 deletions
diff --git a/test/basic-node.js b/test/basic-node.js
index 9d18928..950ba84 100644
--- a/test/basic-node.js
+++ b/test/basic-node.js
@@ -8,11 +8,7 @@ var test = require('tape')
var leavesPath = __dirname + '/torrents/leaves.torrent'
var leaves = fs.readFileSync(leavesPath)
var leavesTorrent = parseTorrent(leaves)
-
-function verify (t, client, torrent) {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- client.destroy()
-}
+var leavesBookPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
test('client.add (http url to a torrent file (string))', function (t) {
t.plan(1)
@@ -25,9 +21,10 @@ test('client.add (http url to a torrent file (string))', function (t) {
if (err) throw err
server.listen(port, function () {
var url = 'http://127.0.0.1:' + port
- var client1 = new WebTorrent({ dht: false, trackers: false })
- client1.add(url, function (torrent) {
- verify(t, client1, torrent)
+ var client = new WebTorrent({ dht: false, trackers: false })
+ client.add(url, function (torrent) {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.destroy()
server.close()
})
})
@@ -37,8 +34,19 @@ 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)
- var client1 = new WebTorrent({ dht: false, trackers: false })
- client1.add(leavesPath, function (torrent) {
- verify(t, client1, torrent)
+ var client = new WebTorrent({ dht: false, trackers: false })
+ client.add(leavesPath, function (torrent) {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.destroy()
+ })
+})
+
+test('client.seed (filesystem path to file (string))', function (t) {
+ t.plan(1)
+
+ var client = new WebTorrent({ dht: false, trackers: false })
+ client.seed(leavesBookPath, function (torrent) {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.destroy()
})
})
diff --git a/test/basic.js b/test/basic.js
index a413e94..2211593 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -5,6 +5,7 @@ var test = require('tape')
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)
@@ -33,5 +34,28 @@ test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', fun
// parsed torrent (from parse-torrent)
var client5 = new WebTorrent({ dht: false, trackers: false })
verify(t, client5, client5.add(leavesTorrent))
+})
+
+test('client.seed (Buffer, Blob)', function (t) {
+ t.plan(2)
+ var opts = {
+ name: 'Leaves of Grass by Walt Whitman.epub'
+ }
+
+ // torrent file (Buffer)
+ var client1 = new WebTorrent({ dht: false, trackers: false })
+ client1.seed(leavesBook, opts, function (torrent) {
+ verify(t, client1, torrent)
+ })
+
+ // Blob
+ if (typeof Blob !== 'undefined') {
+ var client2 = new WebTorrent({ dht: false, trackers: false })
+ client2.seed(new Blob([ leavesBook ]), opts, function (torrent) {
+ verify(t, client2, torrent)
+ })
+ } else {
+ t.pass('Skipping Blob test because missing `Blob` constructor')
+ }
})
diff --git a/test/torrents/Leaves of Grass by Walt Whitman.epub b/test/content/Leaves of Grass by Walt Whitman.epub
index 66791ed..66791ed 100644
--- a/test/torrents/Leaves of Grass by Walt Whitman.epub
+++ b/test/content/Leaves of Grass by Walt Whitman.epub
Binary files differ
diff --git a/test/download.js b/test/download.js
index 9ec7e03..e5dfe4b 100644
--- a/test/download.js
+++ b/test/download.js
@@ -7,7 +7,7 @@ var parseTorrent = require('parse-torrent')
var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
-var leavesFile = __dirname + '/torrents/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
diff --git a/test/server.js b/test/server.js
index 27239d5..f00c22b 100644
--- a/test/server.js
+++ b/test/server.js
@@ -5,7 +5,7 @@ var portfinder = require('portfinder')
var test = require('tape')
var WebTorrent = require('../')
-var leavesFile = __dirname + '/torrents/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
test('start http server programmatically', function (t) {