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:
authorJames Halliday <mail@substack.net>2016-02-09 23:24:33 +0300
committerJames Halliday <mail@substack.net>2016-02-09 23:24:33 +0300
commit83226a40445d0a6987f15a7e010758ab8bc8dc0a (patch)
treeb541a464020df3c3a84cc25a92224e80d8354705 /test
parent70fe9ab7f1e29c788f3ffbbf5e907aab16df31d5 (diff)
failing stream test, actually failing magnet uri test
Diffstat (limited to 'test')
-rw-r--r--test/stream.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/stream.js b/test/stream.js
new file mode 100644
index 0000000..c50b51f
--- /dev/null
+++ b/test/stream.js
@@ -0,0 +1,63 @@
+/* global Blob */
+
+var test = require('tape')
+var Readable = require('readable-stream').Readable
+var WebTorrent = require('../')
+var concat = require('concat-stream')
+var Tracker = require('bittorrent-tracker/server')
+
+test('client.seed: stream', function (t) {
+ t.plan(4)
+
+ var announce = []
+ var tracker = new Tracker()
+ var seeder, client
+ tracker.listen(function () {
+ announce.push('http://localhost:'+tracker.http.address().port)
+ seeder = new WebTorrent({ dht: false })
+ client = new WebTorrent({ dht: false })
+
+ seeder.on('error', function (err) { t.fail(err) })
+ seeder.on('warning', function (err) { t.fail(err) })
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ seed()
+ })
+ tracker.on('start', function () {
+ console.log('START', argument)
+ })
+
+ t.once('end', function () {
+ seeder.destroy(function (err) { if (err) t.error(err, 'seeder destroyed') })
+ client.destroy(function (err) { if (err) t.error(err, 'client destroyed') })
+ tracker.close()
+ })
+
+ var stream = new Readable
+ stream._read = function () {}
+ stream.push('HELLO WORLD\n')
+ stream.push(null)
+
+ function seed () {
+ var sopts = {
+ name: 'hello.txt',
+ pieceLength: 5,
+ announce: announce
+ }
+ var copts = { announce: announce }
+ seeder.seed([stream], sopts, function (torrent) {
+ console.log(torrent.magnetURI)
+ // this works: client.add(torrent, copts, function (dl) {
+ client.add(torrent.magnetURI, copts, function (dl) {
+ t.equal(dl.files.length, 1)
+ t.equal(dl.files[0].name, 'hello.txt')
+ t.equal(dl.files[0].length, 12)
+ dl.files[0].createReadStream()
+ .pipe(concat({ encoding: 'string' }, function (body) {
+ t.equal(body, 'HELLO WORLD\n', 'content')
+ }))
+ })
+ })
+ }
+})