diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-12-30 02:03:00 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-12-30 02:03:00 +0300 |
commit | 0b4dfc608600390b108b846a7bebd293ebf73937 (patch) | |
tree | 976d21b7bd13dc6f162884aaad969619d731444d /test | |
parent | b378a8e40b62348733d7bef4a75ec1798e2b1131 (diff) |
Add more browser tests
Run more of the tests in the browser. There's now a test/node and test/browser folder for tests that are specific to each environment. Anything in test/ will be run in both environments.
Diffstat (limited to 'test')
-rw-r--r-- | test/browser/basic.js (renamed from test/basic-browser.js) | 4 | ||||
-rw-r--r-- | test/common.js | 38 | ||||
-rw-r--r-- | test/fixtures/Leaves of Grass by Walt Whitman.epub (renamed from test/content/Leaves of Grass by Walt Whitman.epub) | bin | 362017 -> 362017 bytes | |||
-rw-r--r-- | test/fixtures/big-buck-bunny-private.torrent (renamed from test/torrents/big-buck-bunny-private.torrent) | bin | 17058 -> 17058 bytes | |||
-rw-r--r-- | test/fixtures/bitlove-intro.torrent (renamed from test/torrents/bitlove-intro.torrent) | bin | 597 -> 597 bytes | |||
-rw-r--r-- | test/fixtures/blocklist.txt (renamed from test/content/blocklist.txt) | 0 | ||||
-rw-r--r-- | test/fixtures/blocklist.txt.gz (renamed from test/content/blocklist.txt.gz) | bin | 91 -> 91 bytes | |||
-rw-r--r-- | test/fixtures/folder.torrent (renamed from test/torrents/folder.torrent) | 0 | ||||
-rw-r--r-- | test/fixtures/folder/file.txt (renamed from test/content/folder/file.txt) | 0 | ||||
-rw-r--r-- | test/fixtures/leaves.torrent (renamed from test/torrents/leaves.torrent) | bin | 639 -> 639 bytes | |||
-rw-r--r-- | test/fixtures/numbers.torrent (renamed from test/torrents/numbers.torrent) | 0 | ||||
-rw-r--r-- | test/fixtures/numbers/1.txt (renamed from test/content/numbers/1.txt) | 0 | ||||
-rw-r--r-- | test/fixtures/numbers/2.txt (renamed from test/content/numbers/2.txt) | 0 | ||||
-rw-r--r-- | test/fixtures/numbers/3.txt (renamed from test/content/numbers/3.txt) | 0 | ||||
-rw-r--r-- | test/fixtures/pride.torrent (renamed from test/torrents/pride.torrent) | bin | 2150 -> 2150 bytes | |||
-rw-r--r-- | test/fixtures/sintel-5gb.torrent (renamed from test/torrents/sintel-5gb.torrent) | bin | 26474 -> 26474 bytes | |||
-rw-r--r-- | test/node/basic.js (renamed from test/basic-node.js) | 4 | ||||
-rw-r--r-- | test/node/blocklist-dht.js (renamed from test/blocklist-dht.js) | 4 | ||||
-rw-r--r-- | test/node/blocklist-tracker.js (renamed from test/blocklist-tracker.js) | 4 | ||||
-rw-r--r-- | test/node/blocklist.js (renamed from test/blocklist.js) | 30 | ||||
-rw-r--r-- | test/node/cmd.js (renamed from test/cmd.js) | 21 | ||||
-rw-r--r-- | test/node/download-dht-magnet.js (renamed from test/download-dht-magnet.js) | 4 | ||||
-rw-r--r-- | test/node/download-dht-torrent.js (renamed from test/download-dht-torrent.js) | 4 | ||||
-rw-r--r-- | test/node/download-private-dht.js (renamed from test/download-private-dht.js) | 4 | ||||
-rw-r--r-- | test/node/download-tracker-magnet.js (renamed from test/download-tracker-magnet.js) | 4 | ||||
-rw-r--r-- | test/node/download-tracker-torrent.js (renamed from test/download-tracker-torrent.js) | 4 | ||||
-rw-r--r-- | test/node/download-webseed-magnet.js (renamed from test/download-webseed-magnet.js) | 4 | ||||
-rw-r--r-- | test/node/download-webseed-torrent.js (renamed from test/download-webseed-torrent.js) | 4 | ||||
-rw-r--r-- | test/node/duplicates.js (renamed from test/duplicates.js) | 4 | ||||
-rw-r--r-- | test/node/extensions.js (renamed from test/extensions.js) | 13 | ||||
-rw-r--r-- | test/node/metadata.js (renamed from test/metadata.js) | 15 | ||||
-rw-r--r-- | test/node/multiple.js (renamed from test/multiple.js) | 4 | ||||
-rw-r--r-- | test/node/server.js (renamed from test/server.js) | 4 | ||||
-rw-r--r-- | test/rarity-map.js | 2 |
34 files changed, 77 insertions, 98 deletions
diff --git a/test/basic-browser.js b/test/browser/basic.js index d79bf81..09889d7 100644 --- a/test/basic-browser.js +++ b/test/browser/basic.js @@ -1,8 +1,8 @@ var fs = require('fs') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') -var img = fs.readFileSync(__dirname + '/../img/logo.png') +var img = fs.readFileSync(__dirname + '/../../img/logo.png') img.name = 'logo.png' function verifyImage (t, err, elem) { diff --git a/test/common.js b/test/common.js index a2e14ad..129efb3 100644 --- a/test/common.js +++ b/test/common.js @@ -7,36 +7,36 @@ var parseTorrent = require('parse-torrent') module.exports = { // Leaves of Grass by Walt Whitman.epub leaves: { - contentPath: path.join(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub'), - torrentPath: path.join(__dirname, 'torrents', 'leaves.torrent'), - content: fs.readFileSync(path.join(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub')), - torrent: fs.readFileSync(path.join(__dirname, 'torrents', 'leaves.torrent')), - parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'leaves.torrent'))), - magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'leaves.torrent')))) + contentPath: path.join(__dirname, 'fixtures', 'Leaves of Grass by Walt Whitman.epub'), + torrentPath: path.join(__dirname, 'fixtures', 'leaves.torrent'), + content: fs.readFileSync(path.join(__dirname, 'fixtures', 'Leaves of Grass by Walt Whitman.epub')), + torrent: fs.readFileSync(path.join(__dirname, 'fixtures', 'leaves.torrent')), + parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'leaves.torrent'))), + magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'leaves.torrent')))) }, // Folder which contains single file folder: { - contentPath: path.join(__dirname, 'content', 'folder'), - torrentPath: path.join(__dirname, 'torrents', 'folder.torrent'), - torrent: fs.readFileSync(path.join(__dirname, 'torrents', 'folder.torrent')), - parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'folder.torrent'))), - magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'folder.torrent')))) + contentPath: path.join(__dirname, 'fixtures', 'folder'), + torrentPath: path.join(__dirname, 'fixtures', 'folder.torrent'), + torrent: fs.readFileSync(path.join(__dirname, 'fixtures', 'folder.torrent')), + parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'folder.torrent'))), + magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'folder.torrent')))) }, // Folder which contains multiple files numbers: { - contentPath: path.join(__dirname, 'content', 'numbers'), - torrentPath: path.join(__dirname, 'torrents', 'numbers.torrent'), - torrent: fs.readFileSync(path.join(__dirname, 'torrents', 'numbers.torrent')), - parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'numbers.torrent'))), - magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'numbers.torrent')))) + contentPath: path.join(__dirname, 'fixtures', 'numbers'), + torrentPath: path.join(__dirname, 'fixtures', 'numbers.torrent'), + torrent: fs.readFileSync(path.join(__dirname, 'fixtures', 'numbers.torrent')), + parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'numbers.torrent'))), + magnetURI: parseTorrent.toMagnetURI(parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'numbers.torrent')))) }, // Torrent file with "private" flag bunny: { - torrentPath: path.join(__dirname, 'torrents', 'big-buck-bunny-private.torrent'), - torrent: fs.readFileSync(path.join(__dirname, 'torrents', 'big-buck-bunny-private.torrent')), - parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'torrents', 'big-buck-bunny-private.torrent'))) + torrentPath: path.join(__dirname, 'fixtures', 'big-buck-bunny-private.torrent'), + torrent: fs.readFileSync(path.join(__dirname, 'fixtures', 'big-buck-bunny-private.torrent')), + parsedTorrent: parseTorrent(fs.readFileSync(path.join(__dirname, 'fixtures', 'big-buck-bunny-private.torrent'))) } } diff --git a/test/content/Leaves of Grass by Walt Whitman.epub b/test/fixtures/Leaves of Grass by Walt Whitman.epub Binary files differindex 66791ed..66791ed 100644 --- a/test/content/Leaves of Grass by Walt Whitman.epub +++ b/test/fixtures/Leaves of Grass by Walt Whitman.epub diff --git a/test/torrents/big-buck-bunny-private.torrent b/test/fixtures/big-buck-bunny-private.torrent Binary files differindex da15903..da15903 100644 --- a/test/torrents/big-buck-bunny-private.torrent +++ b/test/fixtures/big-buck-bunny-private.torrent diff --git a/test/torrents/bitlove-intro.torrent b/test/fixtures/bitlove-intro.torrent Binary files differindex 1c91bf1..1c91bf1 100644 --- a/test/torrents/bitlove-intro.torrent +++ b/test/fixtures/bitlove-intro.torrent diff --git a/test/content/blocklist.txt b/test/fixtures/blocklist.txt index 167627d..167627d 100644 --- a/test/content/blocklist.txt +++ b/test/fixtures/blocklist.txt diff --git a/test/content/blocklist.txt.gz b/test/fixtures/blocklist.txt.gz Binary files differindex 5f401ed..5f401ed 100644 --- a/test/content/blocklist.txt.gz +++ b/test/fixtures/blocklist.txt.gz diff --git a/test/torrents/folder.torrent b/test/fixtures/folder.torrent index cbc8c69..cbc8c69 100644 --- a/test/torrents/folder.torrent +++ b/test/fixtures/folder.torrent diff --git a/test/content/folder/file.txt b/test/fixtures/folder/file.txt index 0637880..0637880 100644 --- a/test/content/folder/file.txt +++ b/test/fixtures/folder/file.txt diff --git a/test/torrents/leaves.torrent b/test/fixtures/leaves.torrent Binary files differindex f5541af..f5541af 100644 --- a/test/torrents/leaves.torrent +++ b/test/fixtures/leaves.torrent diff --git a/test/torrents/numbers.torrent b/test/fixtures/numbers.torrent index 12e2db6..12e2db6 100644 --- a/test/torrents/numbers.torrent +++ b/test/fixtures/numbers.torrent diff --git a/test/content/numbers/1.txt b/test/fixtures/numbers/1.txt index 56a6051..56a6051 100644 --- a/test/content/numbers/1.txt +++ b/test/fixtures/numbers/1.txt diff --git a/test/content/numbers/2.txt b/test/fixtures/numbers/2.txt index 8fdd954..8fdd954 100644 --- a/test/content/numbers/2.txt +++ b/test/fixtures/numbers/2.txt diff --git a/test/content/numbers/3.txt b/test/fixtures/numbers/3.txt index 4f37670..4f37670 100644 --- a/test/content/numbers/3.txt +++ b/test/fixtures/numbers/3.txt diff --git a/test/torrents/pride.torrent b/test/fixtures/pride.torrent Binary files differindex b74e40e..b74e40e 100644 --- a/test/torrents/pride.torrent +++ b/test/fixtures/pride.torrent diff --git a/test/torrents/sintel-5gb.torrent b/test/fixtures/sintel-5gb.torrent Binary files differindex 49c35de..49c35de 100644 --- a/test/torrents/sintel-5gb.torrent +++ b/test/fixtures/sintel-5gb.torrent diff --git a/test/basic-node.js b/test/node/basic.js index a33cde1..c03eb93 100644 --- a/test/basic-node.js +++ b/test/node/basic.js @@ -1,7 +1,7 @@ -var common = require('./common') +var common = require('../common') var http = require('http') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('client.add: http url to a torrent file, string', function (t) { t.plan(8) diff --git a/test/blocklist-dht.js b/test/node/blocklist-dht.js index 852dc17..b492057 100644 --- a/test/blocklist-dht.js +++ b/test/node/blocklist-dht.js @@ -1,9 +1,9 @@ -var common = require('./common') +var common = require('../common') var DHT = require('bittorrent-dht/server') var networkAddress = require('network-address') var series = require('run-series') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('blocklist blocks peers discovered via DHT', function (t) { t.plan(9) diff --git a/test/blocklist-tracker.js b/test/node/blocklist-tracker.js index 1156069..90ac3be 100644 --- a/test/blocklist-tracker.js +++ b/test/node/blocklist-tracker.js @@ -1,9 +1,9 @@ -var common = require('./common') +var common = require('../common') var extend = require('xtend') var series = require('run-series') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('blocklist blocks peers discovered via tracker', function (t) { t.plan(9) diff --git a/test/blocklist.js b/test/node/blocklist.js index 1471ca9..8a7ee9c 100644 --- a/test/blocklist.js +++ b/test/node/blocklist.js @@ -1,19 +1,13 @@ +var common = require('../common') 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 WebTorrent = require('../../') var zlib = require('zlib') -var blocklistPath = path.resolve(__dirname, 'content', 'blocklist.txt') -var blocklistGzipPath = path.resolve(__dirname, 'content', 'blocklist.txt.gz') - -var leavesTorrent = fs.readFileSync(path.resolve(__dirname, 'torrents', 'leaves.torrent')) -var leavesParsed = parseTorrent(leavesTorrent) - -// remove trackers from .torrent file -leavesParsed.announce = [] +var blocklistPath = path.resolve(__dirname, '..', 'fixtures', 'blocklist.txt') +var blocklistGzipPath = path.resolve(__dirname, '..', 'fixtures', 'blocklist.txt.gz') function assertBlocked (t, torrent, addr) { torrent.once('blockedPeer', function (_addr) { @@ -42,7 +36,7 @@ test('blocklist (single IP)', function (t) { // blocklist isn't fully loaded until `ready` event client.on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertBlocked(t, torrent, '1.2.3.4:1234') assertBlocked(t, torrent, '1.2.3.4:6969') assertReachable(t, torrent, '1.1.1.1:1234') @@ -66,7 +60,7 @@ test('blocklist (array of IPs)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertBlocked(t, torrent, '1.2.3.4:1234') assertBlocked(t, torrent, '1.2.3.4:6969') assertBlocked(t, torrent, '5.6.7.8:1234') @@ -133,7 +127,7 @@ test('blocklist (array of IP ranges)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') @@ -162,7 +156,7 @@ test('blocklist (http url)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') @@ -198,7 +192,7 @@ test('blocklist (http url with gzip encoding)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') @@ -234,7 +228,7 @@ test('blocklist (http url with deflate encoding)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') @@ -257,7 +251,7 @@ test('blocklist (fs path)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') @@ -276,7 +270,7 @@ test('blocklist (fs path with gzip)', function (t) { .on('error', function (err) { t.fail(err) }) .on('warning', function (err) { t.fail(err) }) .on('ready', function () { - client.add(leavesParsed, function (torrent) { + client.add(common.leaves.parsedTorrent, function (torrent) { assertList(t, torrent) client.destroy(function (err) { t.error(err, 'client destroyed') diff --git a/test/cmd.js b/test/node/cmd.js index cf7dc3c..94a70cc 100644 --- a/test/cmd.js +++ b/test/node/cmd.js @@ -1,11 +1,12 @@ +var common = require('../common') var cp = require('child_process') -var fs = require('fs') +var extend = require('xtend') 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') +var CMD_PATH = path.resolve(__dirname, '..', '..', 'bin', 'cmd.js') var CMD = 'node ' + CMD_PATH test('Command line: webtorrent help', function (t) { @@ -29,7 +30,7 @@ test('Command line: webtorrent help', function (t) { test('Command line: webtorrent version', function (t) { t.plan(6) - var expectedVersion = require(path.resolve(__dirname, '..', 'package.json')).version + '\n' + var expectedVersion = require(path.resolve(__dirname, '..', '..', 'package.json')).version + '\n' cp.exec(CMD + ' version', function (err, data) { t.error(err) @@ -50,13 +51,10 @@ test('Command line: webtorrent version', function (t) { test('Command line: webtorrent info /path/to/file.torrent', function (t) { t.plan(3) - var leavesPath = path.resolve(__dirname, 'torrents', 'leaves.torrent') - var leaves = fs.readFileSync(leavesPath) - - cp.exec(CMD + ' info ' + leavesPath, function (err, data) { + cp.exec(CMD + ' info ' + common.leaves.torrentPath, function (err, data) { t.error(err) data = JSON.parse(data) - var parsedTorrent = parseTorrent(leaves) + var parsedTorrent = extend(common.leaves.parsedTorrent) delete parsedTorrent.info delete parsedTorrent.infoBuffer t.deepEqual(data, JSON.parse(JSON.stringify(parsedTorrent, undefined, 2))) @@ -83,9 +81,7 @@ test('Command line: webtorrent info magnet_uri', function (t) { test('Command line: webtorrent create /path/to/file', function (t) { t.plan(1) - var leavesPath = path.resolve(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub') - - var child = spawn('node', [ CMD_PATH, 'create', leavesPath ]) + var child = spawn('node', [ CMD_PATH, 'create', common.leaves.contentPath ]) child.on('error', function (err) { t.fail(err) }) var chunks = [] @@ -102,12 +98,11 @@ test('Command line: webtorrent create /path/to/file', function (t) { test('Command line: webtorrent download <torrent file> (with local content)', function (t) { t.plan(2) - cp.exec(CMD + ' download test/torrents/leaves.torrent --out test/content', function (err, data) { + cp.exec(CMD + ' download ' + common.leaves.torrentPath + ' --out test/fixtures', function (err, data) { t.error(err) t.ok(data.indexOf('successfully') !== -1) }) }) -// TODO: test 'webtorrent download /path/to/torrent' // TODO: test 'webtorrent download magnet_uri' // TODO: test 'webtorrent seed /path/to/file' diff --git a/test/download-dht-magnet.js b/test/node/download-dht-magnet.js index 02e9e17..e7a7232 100644 --- a/test/download-dht-magnet.js +++ b/test/node/download-dht-magnet.js @@ -1,9 +1,9 @@ -var common = require('./common') +var common = require('../common') var DHT = require('bittorrent-dht/server') var fs = require('fs') var series = require('run-series') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using DHT (via magnet uri)', function (t) { t.plan(10) diff --git a/test/download-dht-torrent.js b/test/node/download-dht-torrent.js index 5888bbe..0963fca 100644 --- a/test/download-dht-torrent.js +++ b/test/node/download-dht-torrent.js @@ -1,9 +1,9 @@ -var common = require('./common') +var common = require('../common') var DHT = require('bittorrent-dht/server') var fs = require('fs') var series = require('run-series') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using DHT (via .torrent file)', function (t) { t.plan(8) diff --git a/test/download-private-dht.js b/test/node/download-private-dht.js index 812f57c..ca0a8e3 100644 --- a/test/download-private-dht.js +++ b/test/node/download-private-dht.js @@ -1,8 +1,8 @@ -var common = require('./common') +var common = require('../common') var DHT = require('bittorrent-dht/server') var series = require('run-series') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('private torrent should not use DHT', function (t) { t.plan(4) diff --git a/test/download-tracker-magnet.js b/test/node/download-tracker-magnet.js index 9f24067..919957b 100644 --- a/test/download-tracker-magnet.js +++ b/test/node/download-tracker-magnet.js @@ -1,10 +1,10 @@ -var common = require('./common') +var common = require('../common') var extend = require('xtend') var fs = require('fs') var series = require('run-series') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using UDP tracker (via magnet uri)', function (t) { magnetDownloadTest(t, 'udp') diff --git a/test/download-tracker-torrent.js b/test/node/download-tracker-torrent.js index 1c31236..5949a39 100644 --- a/test/download-tracker-torrent.js +++ b/test/node/download-tracker-torrent.js @@ -1,10 +1,10 @@ -var common = require('./common') +var common = require('../common') var extend = require('xtend') var fs = require('fs') var series = require('run-series') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using UDP tracker (via .torrent file)', function (t) { torrentDownloadTest(t, 'udp') diff --git a/test/download-webseed-magnet.js b/test/node/download-webseed-magnet.js index 1808989..6c57e9d 100644 --- a/test/download-webseed-magnet.js +++ b/test/node/download-webseed-magnet.js @@ -1,11 +1,11 @@ -var common = require('./common') +var common = require('../common') var finalhandler = require('finalhandler') var http = require('http') var path = require('path') var series = require('run-series') var serveStatic = require('serve-static') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using webseed (via magnet uri)', function (t) { t.plan(9) diff --git a/test/download-webseed-torrent.js b/test/node/download-webseed-torrent.js index 0caa4e7..c71e90b 100644 --- a/test/download-webseed-torrent.js +++ b/test/node/download-webseed-torrent.js @@ -1,4 +1,4 @@ -var common = require('./common') +var common = require('../common') var extend = require('xtend') var finalhandler = require('finalhandler') var http = require('http') @@ -6,7 +6,7 @@ var path = require('path') var series = require('run-series') var serveStatic = require('serve-static') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('Download using webseed (via .torrent file)', function (t) { t.plan(6) diff --git a/test/duplicates.js b/test/node/duplicates.js index b19355e..d54abdd 100644 --- a/test/duplicates.js +++ b/test/node/duplicates.js @@ -1,6 +1,6 @@ -var common = require('./common') +var common = require('../common') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('client.seed followed by duplicate client.add', function (t) { t.plan(5) diff --git a/test/extensions.js b/test/node/extensions.js index 4278a13..399c1e3 100644 --- a/test/extensions.js +++ b/test/node/extensions.js @@ -1,11 +1,6 @@ -var fs = require('fs') -var parseTorrent = require('parse-torrent') -var path = require('path') +var common = require('../common') var test = require('tape') -var WebTorrent = require('../') - -var leaves = fs.readFileSync(path.resolve(__dirname, 'torrents', 'leaves.torrent')) -var leavesTorrent = parseTorrent(leaves) +var WebTorrent = require('../../') test('extension support', function (t) { t.plan(6) @@ -44,12 +39,12 @@ test('extension support', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - client1.add(leavesTorrent, function (torrent1) { + client1.add(common.leaves.parsedTorrent, function (torrent1) { torrent1.on('wire', function (wire) { t.pass('client1 onWire') wire.use(Extension) }) - var torrent2 = client2.add(leavesTorrent.infoHash) + var torrent2 = client2.add(common.leaves.parsedTorrent.infoHash) torrent2.on('wire', function (wire) { t.pass('client2 onWire') wire.use(Extension) diff --git a/test/metadata.js b/test/node/metadata.js index 891cb21..a6d082d 100644 --- a/test/metadata.js +++ b/test/node/metadata.js @@ -1,11 +1,6 @@ -var fs = require('fs') -var parseTorrent = require('parse-torrent') -var path = require('path') +var common = require('../common') var test = require('tape') -var WebTorrent = require('../') - -var leaves = fs.readFileSync(path.resolve(__dirname, 'torrents', 'leaves.torrent')) -var leavesTorrent = parseTorrent(leaves) +var WebTorrent = require('../../') test('ut_metadata transfer', function (t) { t.plan(6) @@ -25,13 +20,13 @@ test('ut_metadata transfer', function (t) { }) // client1 starts with metadata from torrent file - client1.add(leaves) + client1.add(common.leaves.torrent) client1.on('torrent', function (torrent1) { - t.deepEqual(torrent1.info, leavesTorrent.info) + t.deepEqual(torrent1.info, common.leaves.parsedTorrent.info) // client2 starts with infohash - client2.add(leavesTorrent.infoHash) + client2.add(common.leaves.parsedTorrent.infoHash) client2.on('listening', function (port, torrent2) { // manually add the peer diff --git a/test/multiple.js b/test/node/multiple.js index f843bf7..1c021f2 100644 --- a/test/multiple.js +++ b/test/node/multiple.js @@ -2,10 +2,10 @@ var path = require('path') var fs = require('fs') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') var torrents = [ 'leaves', 'pride' ].map(function (name) { - return fs.readFileSync(path.resolve(__dirname, 'torrents', name + '.torrent')) + return fs.readFileSync(path.resolve(__dirname, 'fixtures', name + '.torrent')) }) // TODO: replace this with a test that can run offline diff --git a/test/server.js b/test/node/server.js index cd5801d..4c7da45 100644 --- a/test/server.js +++ b/test/node/server.js @@ -1,8 +1,8 @@ -var common = require('./common') +var common = require('../common') var fs = require('fs') var get = require('simple-get') var test = require('tape') -var WebTorrent = require('../') +var WebTorrent = require('../../') test('torrent.createServer: programmatic http server', function (t) { t.plan(9) diff --git a/test/rarity-map.js b/test/rarity-map.js index f906120..50b63b0 100644 --- a/test/rarity-map.js +++ b/test/rarity-map.js @@ -6,7 +6,7 @@ var Swarm = require('bittorrent-swarm') var test = require('tape') var infoHash = 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' -var peerId1 = '-WW0001-' + hat(48) +var peerId1 = new Buffer('-WW0001-' + hat(48)) test('Rarity map usage', function (t) { t.plan(16) |