From e31197d5cd9cd1b923cd56bc59d45a51b671ae1c Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 9 Dec 2015 23:59:52 -0800 Subject: tests: lots of cleanup --- index.js | 2 +- test/basic-node.js | 97 ++++++++--------- test/basic.js | 218 +++++++++++++++++++++++---------------- test/blocklist-dht.js | 2 +- test/blocklist-tracker.js | 2 +- test/blocklist.js | 2 +- test/cmd.js | 4 +- test/common.js | 26 ++++- test/download-dht-magnet.js | 2 +- test/download-dht-torrent.js | 2 +- test/download-private-dht.js | 2 +- test/download-tracker-magnet.js | 2 +- test/download-tracker-torrent.js | 2 +- test/download-webseed-torrent.js | 9 +- test/duplicates.js | 2 +- test/extensions.js | 2 +- test/metadata.js | 2 +- test/server.js | 3 +- test/torrents/folder.torrent | 1 + test/torrents/leaves.torrent | Bin 994 -> 639 bytes test/torrents/numbers.torrent | 1 + test/torrents/pride.torrent | Bin 3666 -> 2150 bytes test/torrents/sintel-5gb.torrent | Bin 26727 -> 26474 bytes 23 files changed, 216 insertions(+), 167 deletions(-) create mode 100644 test/torrents/folder.torrent create mode 100644 test/torrents/numbers.torrent diff --git a/index.js b/index.js index b6cf733..c61a82a 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,9 @@ var inherits = require('inherits') var loadIPSet = require('load-ip-set') // browser exclude var parallel = require('run-parallel') var parseTorrent = require('parse-torrent') +var path = require('path') var speedometer = require('speedometer') var zeroFill = require('zero-fill') -var path = require('path') var Torrent = require('./lib/torrent') diff --git a/test/basic-node.js b/test/basic-node.js index d776a52..a33cde1 100644 --- a/test/basic-node.js +++ b/test/basic-node.js @@ -4,7 +4,7 @@ var test = require('tape') var WebTorrent = require('../') test('client.add: http url to a torrent file, string', function (t) { - t.plan(3) + t.plan(8) var server = http.createServer(function (req, res) { t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1) @@ -20,16 +20,21 @@ test('client.add: http url to a torrent file, string', function (t) { 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.destroy() - server.close() + + 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(2) + t.plan(6) var client = new WebTorrent({ dht: false, tracker: false }) @@ -37,87 +42,75 @@ test('client.add: filesystem path to a torrent file, string', function (t) { 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.destroy() + + 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(2) - - var opts = { - name: 'Leaves of Grass by Walt Whitman.epub', - announce: [ - 'http://tracker.thepiratebay.org/announce', - 'udp://tracker.openbittorrent.com:80', - 'udp://tracker.ccc.de:80', - 'udp://tracker.publicbt.com:80', - 'udp://fr33domtracker.h33t.com:3310/announce', - 'http://tracker.bittorrent.am/announce' - ] - } + 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, opts, function (torrent) { + 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.destroy() + + 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(2) - - var opts = { - pieceLength: 32768, // force piece length to 32KB so info-hash will - // match what transmission generated, since we use - // a different algo for picking piece length - - private: false, // also force `private: false` to match transmission - announce: [ - 'udp://tracker.webtorrent.io:80' - ] - } + 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, opts, function (torrent) { - t.equal(torrent.infoHash, '3a686c32404af0a66913dd5f8d2b40673f8d4490') - t.equal(torrent.magnetURI, 'magnet:?xt=urn:btih:3a686c32404af0a66913dd5f8d2b40673f8d4490&dn=folder&tr=udp%3A%2F%2Ftracker.webtorrent.io%3A80') - client.destroy() + 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(2) - - var opts = { - pieceLength: 32768, // force piece length to 32KB so info-hash will - // match what transmission generated, since we use - // a different algo for picking piece length - - private: false, // also force `private: false` to match transmission - announce: [ - 'udp://tracker.webtorrent.io:80' - ] - } + 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, opts, function (torrent) { - t.equal(torrent.infoHash, '80562f38656b385ea78959010e51a2cc9db41ea0') - t.equal(torrent.magnetURI, 'magnet:?xt=urn:btih:80562f38656b385ea78959010e51a2cc9db41ea0&dn=numbers&tr=udp%3A%2F%2Ftracker.webtorrent.io%3A80') - client.destroy() + 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') }) }) }) diff --git a/test/basic.js b/test/basic.js index 3a19e4c..64472b4 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,27 +1,35 @@ +/* global Blob */ + var common = require('./common') var extend = require('xtend') var test = require('tape') var WebTorrent = require('../') -test('client.add/remove: magnet uri, utf-8 string', function (t) { +test('client.add: magnet uri, utf-8 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) }) - var torrent = client.add('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) + var torrent = client.add(common.leaves.magnetURI) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { 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(torrent.magnetURI, common.leaves.magnetURI) + + client.remove(common.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) -test('client.add/remove: torrent file, buffer', function (t) { +test('client.add: torrent file, buffer', function (t) { + t.plan(6) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -29,17 +37,21 @@ test('client.add/remove: torrent file, buffer', function (t) { var torrent = client.add(common.leaves.torrent) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash) t.equal(torrent.magnetURI, common.leaves.magnetURI) - client.remove(common.leaves.torrent) + + client.remove(common.leaves.torrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) -test('client.add/remove: info hash, hex string', function (t) { +test('client.add: info hash, hex string', function (t) { + t.plan(6) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -47,17 +59,21 @@ test('client.add/remove: info hash, hex string', function (t) { var torrent = client.add(common.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { 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(torrent.magnetURI, 'magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) + + client.remove(common.leaves.parsedTorrent.infoHash, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) -test('client.add/remove: info hash, buffer', function (t) { +test('client.add: info hash, buffer', function (t) { + t.plan(6) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -65,17 +81,21 @@ test('client.add/remove: info hash, buffer', function (t) { var torrent = client.add(common.leaves.parsedTorrent.infoHashBuffer) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { 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')) + + client.remove(new Buffer(common.leaves.parsedTorrent.infoHash, 'hex'), function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) -test('client.add/remove: parsed torrent, from `parse-torrent`', function (t) { +test('client.add: parsed torrent, from `parse-torrent`', function (t) { + t.plan(6) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -83,37 +103,46 @@ test('client.add/remove: parsed torrent, from `parse-torrent`', function (t) { var torrent = client.add(common.leaves.parsedTorrent) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash) t.equal(torrent.magnetURI, common.leaves.magnetURI) - client.remove(common.leaves.parsedTorrent) + + client.remove(common.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) -test('client.add/remove: parsed torrent, with string type announce property', function (t) { +test('client.add: parsed torrent, with string type announce property', 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) }) - var modifiedParsedTorrent = extend(common.leaves.parsedTorrent, { - announce: common.leaves.parsedTorrent.announce[0] - }) - var torrent = client.add(modifiedParsedTorrent) + var parsedTorrent = extend(common.leaves.parsedTorrent) + parsedTorrent.announce = 'http://tracker.local:80' + + var torrent = client.add(parsedTorrent) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash) - client.remove(common.leaves.parsedTorrent) + t.equal(torrent.magnetURI, common.leaves.magnetURI + '&tr=' + encodeURIComponent('http://tracker.local:80')) + + client.remove(common.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) test('client.remove: remove by Torrent object', function (t) { + t.plan(5) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -121,16 +150,20 @@ test('client.remove: remove by Torrent object', function (t) { var torrent = client.add(common.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash) - client.remove(torrent) + + client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) test('torrent.destroy: destroy and remove torrent', function (t) { + t.plan(5) + var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) @@ -138,77 +171,84 @@ test('torrent.destroy: destroy and remove torrent', function (t) { var torrent = client.add(common.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) + torrent.on('infoHash', function () { t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash) - torrent.destroy() + + torrent.destroy(function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) - client.destroy() - t.end() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) test('client.seed: torrent file (Buffer)', function (t) { - t.plan(4) - - var opts = { - name: 'Leaves of Grass by Walt Whitman.epub', - announce: [ - 'http://tracker.thepiratebay.org/announce', - 'udp://tracker.openbittorrent.com:80', - 'udp://tracker.ccc.de:80', - 'udp://tracker.publicbt.com:80', - 'udp://fr33domtracker.h33t.com:3310/announce', - 'http://tracker.bittorrent.am/announce' - ] - } + 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.content, opts, function (torrent) { + client.seed(common.leaves.content, { + 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) + + client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) - client.destroy() + + client.destroy(function (err) { t.error(err, 'client destroyed') }) + }) +}) + +test('client.seed: torrent file (Buffer), set name on buffer', 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) }) + + var buf = new Buffer(common.leaves.content) + buf.name = 'Leaves of Grass by Walt Whitman.epub' + + client.seed(common.leaves.content, 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 removed') }) + t.equal(client.torrents.length, 0) + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) }) test('client.seed: torrent file (Blob)', function (t) { - var opts = { - name: 'Leaves of Grass by Walt Whitman.epub', - announce: [ - 'http://tracker.thepiratebay.org/announce', - 'udp://tracker.openbittorrent.com:80', - 'udp://tracker.ccc.de:80', - 'udp://tracker.publicbt.com:80', - 'udp://fr33domtracker.h33t.com:3310/announce', - 'http://tracker.bittorrent.am/announce' - ] - } - - if (global.Blob !== undefined) { - t.plan(4) - 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(new global.Blob([ common.leaves.content ]), opts, 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) - t.equal(client.torrents.length, 0) - client.destroy() - }) - } else { - t.pass('Skipping Blob test because missing `Blob` constructor') - t.end() - } + if (typeof Blob === 'undefined') return t.end() + + 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(new global.Blob([ common.leaves.content ]), { + 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 removed') }) + t.equal(client.torrents.length, 0) + + client.destroy(function (err) { t.error(err, 'client destroyed') }) + }) }) test('after client.destroy(), throw on client.add() or client.seed()', function (t) { @@ -219,9 +259,8 @@ test('after client.destroy(), throw on client.add() or client.seed()', function client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - client.destroy(function () { - t.pass('client destroyed') - }) + client.destroy(function (err) { t.error(err, 'client destroyed') }) + t.throws(function () { client.add('magnet:?xt=urn:btih:' + common.leaves.parsedTorrent.infoHash) }) @@ -247,7 +286,6 @@ test('after client.destroy(), no "torrent" or "ready" events emitted', function client.on('ready', function () { t.fail('unexpected "ready" event') }) - client.destroy(function () { - t.pass('client destroyed') - }) + + client.destroy(function (err) { t.error(err, 'client destroyed') }) }) diff --git a/test/blocklist-dht.js b/test/blocklist-dht.js index 60ec4fd..e437f27 100644 --- a/test/blocklist-dht.js +++ b/test/blocklist-dht.js @@ -1,9 +1,9 @@ var auto = require('run-auto') var DHT = require('bittorrent-dht/server') -var path = require('path') var fs = require('fs') var networkAddress = require('network-address') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/blocklist-tracker.js b/test/blocklist-tracker.js index 1db8415..39269a1 100644 --- a/test/blocklist-tracker.js +++ b/test/blocklist-tracker.js @@ -1,7 +1,7 @@ var auto = require('run-auto') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') var WebTorrent = require('../') diff --git a/test/blocklist.js b/test/blocklist.js index 73ec815..2f4e165 100644 --- a/test/blocklist.js +++ b/test/blocklist.js @@ -1,7 +1,7 @@ -var path = require('path') var fs = require('fs') var http = require('http') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') var zlib = require('zlib') diff --git a/test/cmd.js b/test/cmd.js index 5699a0e..461b54d 100644 --- a/test/cmd.js +++ b/test/cmd.js @@ -1,8 +1,8 @@ var cp = require('child_process') -var spawn = require('cross-spawn-async') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') +var spawn = require('cross-spawn-async') var test = require('tape') var CMD_PATH = path.resolve(__dirname, '..', 'bin', 'cmd.js') diff --git a/test/common.js b/test/common.js index 691d178..b68b0f4 100644 --- a/test/common.js +++ b/test/common.js @@ -17,18 +17,34 @@ module.exports = { parsedTorrent: parseTorrent( fs.readFileSync(path.join(torrents, 'leaves.torrent')) ), - magnetURI: parseTorrent.toMagnetURI( - parseTorrent(fs.readFileSync(path.join(torrents, 'leaves.torrent'))) - ) + magnetURI: parseTorrent.toMagnetURI(parseTorrent( + fs.readFileSync(path.join(torrents, 'leaves.torrent')) + )) }, // Folder which contains single file folder: { - contentPath: path.join(content, 'folder') + contentPath: path.join(content, 'folder'), + torrentPath: path.join(torrents, 'folder.torrent'), + torrent: fs.readFileSync(path.join(torrents, 'folder.torrent')), + parsedTorrent: parseTorrent( + fs.readFileSync(path.join(torrents, 'folder.torrent')) + ), + magnetURI: parseTorrent.toMagnetURI(parseTorrent( + fs.readFileSync(path.join(torrents, 'folder.torrent')) + )) }, // Folder which contains multiple files numbers: { - contentPath: path.join(content, 'numbers') + contentPath: path.join(content, 'numbers'), + torrentPath: path.join(torrents, 'numbers.torrent'), + torrent: fs.readFileSync(path.join(torrents, 'numbers.torrent')), + parsedTorrent: parseTorrent( + fs.readFileSync(path.join(torrents, 'numbers.torrent')) + ), + magnetURI: parseTorrent.toMagnetURI(parseTorrent( + fs.readFileSync(path.join(torrents, 'numbers.torrent')) + )) } } diff --git a/test/download-dht-magnet.js b/test/download-dht-magnet.js index cdd99ac..b9c0869 100644 --- a/test/download-dht-magnet.js +++ b/test/download-dht-magnet.js @@ -1,8 +1,8 @@ var auto = require('run-auto') var DHT = require('bittorrent-dht/server') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/download-dht-torrent.js b/test/download-dht-torrent.js index 19e8b56..9985629 100644 --- a/test/download-dht-torrent.js +++ b/test/download-dht-torrent.js @@ -1,8 +1,8 @@ var auto = require('run-auto') var DHT = require('bittorrent-dht/server') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/download-private-dht.js b/test/download-private-dht.js index 5653755..63ad74c 100644 --- a/test/download-private-dht.js +++ b/test/download-private-dht.js @@ -1,8 +1,8 @@ var auto = require('run-auto') var DHT = require('bittorrent-dht/server') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/download-tracker-magnet.js b/test/download-tracker-magnet.js index 445c23c..b4c89a2 100644 --- a/test/download-tracker-magnet.js +++ b/test/download-tracker-magnet.js @@ -1,7 +1,7 @@ var auto = require('run-auto') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') var WebTorrent = require('../') diff --git a/test/download-tracker-torrent.js b/test/download-tracker-torrent.js index 438450a..fdbf559 100644 --- a/test/download-tracker-torrent.js +++ b/test/download-tracker-torrent.js @@ -1,7 +1,7 @@ var auto = require('run-auto') -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') var WebTorrent = require('../') diff --git a/test/download-webseed-torrent.js b/test/download-webseed-torrent.js index 3a5c197..7cbc889 100644 --- a/test/download-webseed-torrent.js +++ b/test/download-webseed-torrent.js @@ -1,14 +1,13 @@ var auto = require('run-auto') +var finalhandler = require('finalhandler') var fs = require('fs') +var http = require('http') var parseTorrent = require('parse-torrent') +var path = require('path') +var serveStatic = require('serve-static') var test = require('tape') var WebTorrent = require('../') -var http = require('http') -var serveStatic = require('serve-static') -var finalhandler = require('finalhandler') -var path = require('path') - var leavesPath = path.resolve(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub') var leavesFilename = 'Leaves of Grass by Walt Whitman.epub' var leavesFile = fs.readFileSync(leavesPath) diff --git a/test/duplicates.js b/test/duplicates.js index 6c1cbc9..a89f649 100644 --- a/test/duplicates.js +++ b/test/duplicates.js @@ -1,5 +1,5 @@ -var path = require('path') var fs = require('fs') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/extensions.js b/test/extensions.js index 14ea63b..82943d7 100644 --- a/test/extensions.js +++ b/test/extensions.js @@ -1,6 +1,6 @@ -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/metadata.js b/test/metadata.js index eb205f3..efcfbab 100644 --- a/test/metadata.js +++ b/test/metadata.js @@ -1,6 +1,6 @@ -var path = require('path') var fs = require('fs') var parseTorrent = require('parse-torrent') +var path = require('path') var test = require('tape') var WebTorrent = require('../') diff --git a/test/server.js b/test/server.js index 8aae268..8571a9e 100644 --- a/test/server.js +++ b/test/server.js @@ -4,10 +4,11 @@ var get = require('simple-get') var test = require('tape') var WebTorrent = require('../') -test('torrent.createServer(): programmatic http server', function (t) { +test('torrent.createServer: programmatic http server', function (t) { t.plan(9) var client = new WebTorrent({ tracker: false, dht: false }) + client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/torrents/folder.torrent b/test/torrents/folder.torrent new file mode 100644 index 0000000..cbc8c69 --- /dev/null +++ b/test/torrents/folder.torrent @@ -0,0 +1 @@ +d13:creation datei1449730049429e8:encoding5:UTF-84:infod5:filesld6:lengthi15e4:pathl8:file.txteee4:name6:folder12:piece lengthi16384e6:pieces20:yHӟ+TP./7ee \ No newline at end of file diff --git a/test/torrents/leaves.torrent b/test/torrents/leaves.torrent index f18e7c1..f5541af 100644 Binary files a/test/torrents/leaves.torrent and b/test/torrents/leaves.torrent differ diff --git a/test/torrents/numbers.torrent b/test/torrents/numbers.torrent new file mode 100644 index 0000000..12e2db6 --- /dev/null +++ b/test/torrents/numbers.torrent @@ -0,0 +1 @@ +d13:creation datei1449730287842e8:encoding5:UTF-84:infod5:filesld6:lengthi1e4:pathl5:1.txteed6:lengthi2e4:pathl5:2.txteed6:lengthi3e4:pathl5:3.txteee4:name7:numbers12:piece lengthi16384e6:pieces20:tdPpJ'cSk|ee \ No newline at end of file diff --git a/test/torrents/pride.torrent b/test/torrents/pride.torrent index a9bf635..b74e40e 100644 Binary files a/test/torrents/pride.torrent and b/test/torrents/pride.torrent differ diff --git a/test/torrents/sintel-5gb.torrent b/test/torrents/sintel-5gb.torrent index 65f43c4..49c35de 100644 Binary files a/test/torrents/sintel-5gb.torrent and b/test/torrents/sintel-5gb.torrent differ -- cgit v1.2.3