From bb6ad183fbb78fa38f4dcc104b11683722693ce1 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 9 Feb 2016 22:42:57 -0800 Subject: test: move node-only test to test/node --- test/node/seed-stream.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ test/stream.js | 63 ------------------------------------------------ 2 files changed, 63 insertions(+), 63 deletions(-) create mode 100644 test/node/seed-stream.js delete mode 100644 test/stream.js (limited to 'test') diff --git a/test/node/seed-stream.js b/test/node/seed-stream.js new file mode 100644 index 0000000..6a6f14c --- /dev/null +++ b/test/node/seed-stream.js @@ -0,0 +1,63 @@ +var test = require('tape') +var Readable = require('readable-stream').Readable +var concat = require('concat-stream') +var Tracker = require('bittorrent-tracker/server') +var WebTorrent = require('../../') + +test('client.seed: stream', function (t) { + t.plan(4) + + var announce = [] + var tracker = new Tracker() + var seeder, client + tracker.listen(function () { + var port = tracker.http.address().port + t.pass('tracker listening on ' + port) + announce.push('http://localhost:' + port + '/announce') + + 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', arguments) + }) + + 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) + 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') + })) + }) + }) + } +}) diff --git a/test/stream.js b/test/stream.js deleted file mode 100644 index 713f682..0000000 --- a/test/stream.js +++ /dev/null @@ -1,63 +0,0 @@ -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 () { - var port = tracker.http.address().port - t.pass('tracker listening on ' + port) - announce.push('http://localhost:' + port + '/announce') - - 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', arguments) - }) - - 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) - 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') - })) - }) - }) - } -}) -- cgit v1.2.3