diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2020-10-29 07:32:23 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2020-10-29 07:32:23 +0300 |
commit | c73870ad0edd8f696f0a8e93289a34f0c536e3db (patch) | |
tree | 8adda2773b55d089660d07267b924934d782006b /test | |
parent | f6121c311b754591a737aec0d3abce299b4908c8 (diff) |
Convert the tests to use let/const instead of var
Diffstat (limited to 'test')
29 files changed, 402 insertions, 390 deletions
diff --git a/test/browser/basic.js b/test/browser/basic.js index a70f530..fcdcc80 100644 --- a/test/browser/basic.js +++ b/test/browser/basic.js @@ -1,7 +1,7 @@ -var test = require('tape') -var WebTorrent = require('../../') +const test = require('tape') +const WebTorrent = require('../../') -var img = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64') +const img = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64') img.name = 'img.png' function verifyImage (t, err, elem) { @@ -20,7 +20,7 @@ if (!(global && global.process && global.process.versions && global.process.vers test('image append w/ query selector', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -38,7 +38,7 @@ if (!(global && global.process && global.process.versions && global.process.vers test('image append w/ element', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -56,12 +56,12 @@ if (!(global && global.process && global.process.versions && global.process.vers test('image render w/ query selector', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var tag = document.createElement('img') + const tag = document.createElement('img') tag.className = 'tag' document.body.appendChild(tag) @@ -78,12 +78,12 @@ if (!(global && global.process && global.process.versions && global.process.vers test('image render w/ element', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var tag = document.createElement('img') + const tag = document.createElement('img') document.body.appendChild(tag) client.seed(img, function (torrent) { @@ -100,7 +100,7 @@ if (!(global && global.process && global.process.versions && global.process.vers test('WebTorrent.WEBRTC_SUPPORT', function (t) { t.plan(2) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/client-add-duplicate-trackers.js b/test/client-add-duplicate-trackers.js index 3c9c366..46246fd 100644 --- a/test/client-add-duplicate-trackers.js +++ b/test/client-add-duplicate-trackers.js @@ -1,16 +1,16 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('client.add: duplicate trackers', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.torrent, { + const torrent = client.add(fixtures.leaves.torrent, { announce: ['wss://example.com', 'wss://example.com', 'wss://example.com'] }) @@ -25,21 +25,21 @@ test('client.add: duplicate trackers, with multiple torrents', function (t) { t.plan(5) // Re-use this object, in case webtorrent is changing it - var opts = { + const opts = { announce: ['wss://example.com', 'wss://example.com', 'wss://example.com'] } - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent1 = client.add(fixtures.leaves.torrent, opts) + const torrent1 = client.add(fixtures.leaves.torrent, opts) torrent1.on('ready', function () { t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com')) - var torrent2 = client.add(fixtures.alice.torrent, opts) + const torrent2 = client.add(fixtures.alice.torrent, opts) torrent2.on('ready', function () { t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com')) @@ -55,28 +55,28 @@ test('client.add: duplicate trackers (including in .torrent file), multiple torr t.plan(5) // Re-use this object, in case webtorrent is changing it - var opts = { + const opts = { announce: ['wss://example.com', 'wss://example.com', 'wss://example.com'] } // Include the duplicate trackers in the .torrent files - var parsedTorrentLeaves = Object.assign({}, fixtures.leaves.parsedTorrent) + const parsedTorrentLeaves = Object.assign({}, fixtures.leaves.parsedTorrent) parsedTorrentLeaves.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com'] - var parsedTorrentAlice = Object.assign({}, fixtures.alice.parsedTorrent) + const parsedTorrentAlice = Object.assign({}, fixtures.alice.parsedTorrent) parsedTorrentAlice.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com'] - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent1 = client.add(parsedTorrentLeaves, opts) + const torrent1 = client.add(parsedTorrentLeaves, opts) torrent1.on('ready', function () { t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com')) - var torrent2 = client.add(parsedTorrentAlice, opts) + const torrent2 = client.add(parsedTorrentAlice, opts) torrent2.on('ready', function () { t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com')) diff --git a/test/client-add.js b/test/client-add.js index 07de490..a016584 100644 --- a/test/client-add.js +++ b/test/client-add.js @@ -1,16 +1,16 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('client.add: magnet uri, utf-8 string', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.magnetURI) + const torrent = client.add(fixtures.leaves.magnetURI) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { @@ -27,12 +27,12 @@ test('client.add: magnet uri, utf-8 string', function (t) { test('client.add: torrent file, buffer', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.torrent) + const torrent = client.add(fixtures.leaves.torrent) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { @@ -49,12 +49,12 @@ test('client.add: torrent file, buffer', function (t) { test('client.add: info hash, hex string', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.parsedTorrent.infoHash) + const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { @@ -71,12 +71,12 @@ test('client.add: info hash, hex string', function (t) { test('client.add: info hash, buffer', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.parsedTorrent.infoHashBuffer) + const torrent = client.add(fixtures.leaves.parsedTorrent.infoHashBuffer) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { @@ -93,12 +93,12 @@ test('client.add: info hash, buffer', function (t) { test('client.add: parsed torrent, from `parse-torrent`', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.parsedTorrent) + const torrent = client.add(fixtures.leaves.parsedTorrent) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { @@ -115,21 +115,21 @@ test('client.add: parsed torrent, from `parse-torrent`', function (t) { test('client.add: parsed torrent, with string type announce property', function (t) { t.plan(7) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) parsedTorrent.announce = 'http://tracker.local:80' - var torrent = client.add(parsedTorrent) + const torrent = client.add(parsedTorrent) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - var expectedMagnetURI = fixtures.leaves.magnetURI + + const expectedMagnetURI = fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('http://tracker.local:80') t.equal(torrent.magnetURI, expectedMagnetURI) @@ -146,21 +146,21 @@ test('client.add: parsed torrent, with string type announce property', function test('client.add: parsed torrent, with array type announce property', function (t) { t.plan(7) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) parsedTorrent.announce = ['http://tracker.local:80', 'http://tracker.local:81'] - var torrent = client.add(parsedTorrent) + const torrent = client.add(parsedTorrent) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - var expectedMagnetURI = fixtures.leaves.magnetURI + + const expectedMagnetURI = fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('http://tracker.local:80') + '&tr=' + encodeURIComponent('http://tracker.local:81') t.equal(torrent.magnetURI, expectedMagnetURI) @@ -177,7 +177,7 @@ test('client.add: parsed torrent, with array type announce property', function ( test('client.add: invalid torrent id: empty string', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.ok(err instanceof Error) @@ -193,7 +193,7 @@ test('client.add: invalid torrent id: empty string', function (t) { test('client.add: invalid torrent id: short buffer', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.ok(err instanceof Error) diff --git a/test/client-destroy.js b/test/client-destroy.js index 43992a1..eaf6c70 100644 --- a/test/client-destroy.js +++ b/test/client-destroy.js @@ -1,11 +1,11 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('after client.destroy(), throw on client.add() or client.seed()', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -23,7 +23,7 @@ test('after client.destroy(), throw on client.add() or client.seed()', function test('after client.destroy(), no "torrent" or "ready" events emitted', function (t) { t.plan(1) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/client-remove.js b/test/client-remove.js index a62f0cb..9a03c63 100644 --- a/test/client-remove.js +++ b/test/client-remove.js @@ -1,16 +1,16 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('client.remove: remove by Torrent object', function (t) { t.plan(5) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.parsedTorrent.infoHash) + const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { diff --git a/test/client-seed.js b/test/client-seed.js index a50d3cf..d95b2b8 100644 --- a/test/client-seed.js +++ b/test/client-seed.js @@ -1,13 +1,13 @@ /* global Blob */ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('client.seed: torrent file (Buffer)', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -30,12 +30,12 @@ test('client.seed: torrent file (Buffer)', function (t) { test('client.seed: torrent file (Buffer), set name on buffer', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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 = Buffer.from(fixtures.leaves.content) + const buf = Buffer.from(fixtures.leaves.content) buf.name = 'Leaves of Grass by Walt Whitman.epub' client.seed(buf, { announce: [] }, function (torrent) { @@ -55,7 +55,7 @@ test('client.seed: torrent file (Blob)', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/duplicate.js b/test/duplicate.js index a189660..e8cdef7 100644 --- a/test/duplicate.js +++ b/test/duplicate.js @@ -1,11 +1,11 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('client.seed followed by duplicate client.add (sync)', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -15,7 +15,7 @@ test('client.seed followed by duplicate client.add (sync)', function (t) { }, function (torrent1) { t.equal(client.torrents.length, 1) - var torrent2 = client.add(torrent1.infoHash) + const torrent2 = client.add(torrent1.infoHash) torrent2.once('ready', function () { t.fail('torrent ready is not called') @@ -36,7 +36,7 @@ test('client.seed followed by duplicate client.add (sync)', function (t) { test('client.seed followed by duplicate client.add (async)', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -46,7 +46,7 @@ test('client.seed followed by duplicate client.add (async)', function (t) { }, function (torrent1) { t.equal(client.torrents.length, 1) - var torrent2 = client.add(fixtures.leaves.torrentPath) + const torrent2 = client.add(fixtures.leaves.torrentPath) torrent2.once('ready', function () { t.fail('torrent ready is not called') @@ -67,7 +67,7 @@ test('client.seed followed by duplicate client.add (async)', function (t) { test('client.seed followed by two duplicate client.add calls (sync)', function (t) { t.plan(9) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -77,7 +77,7 @@ test('client.seed followed by two duplicate client.add calls (sync)', function ( }, function (torrent1) { t.equal(client.torrents.length, 1) - var torrent2 = client.add(torrent1.infoHash) + const torrent2 = client.add(torrent1.infoHash) torrent2.once('ready', function () { t.fail('torrent ready is not called') @@ -88,7 +88,7 @@ test('client.seed followed by two duplicate client.add calls (sync)', function ( t.equal(client.torrents.length, 1) t.ok(torrent2.destroyed) - var torrent3 = client.add(torrent1.infoHash) + const torrent3 = client.add(torrent1.infoHash) torrent3.once('ready', function () { t.fail('torrent ready is not called') @@ -110,7 +110,7 @@ test('client.seed followed by two duplicate client.add calls (sync)', function ( test('client.seed followed by two duplicate client.add calls (async)', function (t) { t.plan(9) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -120,7 +120,7 @@ test('client.seed followed by two duplicate client.add calls (async)', function }, function (torrent1) { t.equal(client.torrents.length, 1) - var torrent2 = client.add(fixtures.leaves.torrentPath) + const torrent2 = client.add(fixtures.leaves.torrentPath) torrent2.once('ready', function () { t.fail('torrent ready is not called') @@ -131,7 +131,7 @@ test('client.seed followed by two duplicate client.add calls (async)', function t.equal(client.torrents.length, 1) t.ok(torrent2.destroyed) - var torrent3 = client.add(fixtures.leaves.torrentPath) + const torrent3 = client.add(fixtures.leaves.torrentPath) torrent3.once('ready', function () { t.fail('torrent ready is not called') @@ -153,7 +153,7 @@ test('client.seed followed by two duplicate client.add calls (async)', function test('successive sync client.add, client.remove, client.add, client.remove (sync)', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/node/basic.js b/test/node/basic.js index 0d7dc64..a0598b8 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -1,14 +1,14 @@ -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var path = require('path') -var http = require('http') -var test = require('tape') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const path = require('path') +const http = require('http') +const test = require('tape') +const WebTorrent = require('../../') test('WebTorrent.WEBRTC_SUPPORT', function (t) { t.plan(2) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -23,15 +23,15 @@ test('WebTorrent.WEBRTC_SUPPORT', function (t) { test('client.add: http url to a torrent file, string', function (t) { t.plan(8) - var server = http.createServer(function (req, res) { + const server = http.createServer(function (req, res) { t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1) res.end(fixtures.leaves.torrent) }) server.listen(0, function () { - var port = server.address().port - var url = 'http://127.0.0.1:' + port - var client = new WebTorrent({ dht: false, tracker: false }) + const port = server.address().port + const url = 'http://127.0.0.1:' + port + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -53,7 +53,7 @@ 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(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -73,7 +73,7 @@ test('client.add: filesystem path to a torrent file, string', function (t) { test('client.seed: filesystem path to file, string', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -96,7 +96,7 @@ test('client.seed: filesystem path to file, string', function (t) { test('client.seed: filesystem path to folder with one file, string', function (t) { t.plan(6) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -116,7 +116,7 @@ test('client.seed: filesystem path to folder with one file, string', function (t test('client.seed: filesystem path to folder with multiple files, string', function (t) { t.plan(7) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) @@ -147,7 +147,7 @@ test('client.seed: filesystem path to folder with multiple files, string', funct test('client.add: invalid torrent id: invalid filesystem path', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.ok(err instanceof Error) @@ -163,13 +163,13 @@ test('client.add: invalid torrent id: invalid filesystem path', function (t) { test('client.remove: opts.destroyStore', function (t) { t.plan(2) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) { - var torrentPath = torrent.path + const torrentPath = torrent.path client.remove(torrent, { destroyStore: true }, function (err) { if (err) t.fail(err) @@ -186,13 +186,13 @@ test('client.remove: opts.destroyStore', function (t) { test('torrent.destroy: opts.destroyStore', function (t) { t.plan(2) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) { - var torrentPath = torrent.path + const torrentPath = torrent.path torrent.destroy({ destroyStore: true }, function (err) { if (err) t.fail(err) diff --git a/test/node/blocklist-dht.js b/test/node/blocklist-dht.js index fa3915a..2ecec36 100644 --- a/test/node/blocklist-dht.js +++ b/test/node/blocklist-dht.js @@ -1,14 +1,14 @@ -var DHT = require('bittorrent-dht/server') -var fixtures = require('webtorrent-fixtures') -var series = require('run-series') -var test = require('tape') -var WebTorrent = require('../../') -var common = require('../common') +const DHT = require('bittorrent-dht/server') +const fixtures = require('webtorrent-fixtures') +const series = require('run-series') +const test = require('tape') +const WebTorrent = require('../../') +const common = require('../common') test('blocklist blocks peers discovered via DHT', function (t) { t.plan(8) - var dhtServer, client1, client2 + let dhtServer, client1, client2 series([ function (cb) { @@ -19,6 +19,9 @@ test('blocklist blocks peers discovered via DHT', function (t) { }, function (cb) { + let torrentReady = false + let announced = false + client1 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port } @@ -26,7 +29,7 @@ test('blocklist blocks peers discovered via DHT', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent1 = client1.add(fixtures.leaves.parsedTorrent, { + const torrent1 = client1.add(fixtures.leaves.parsedTorrent, { path: common.getDownloadPath('client_1', fixtures.leaves.parsedTorrent.infoHash) }) @@ -50,8 +53,6 @@ test('blocklist blocks peers discovered via DHT', function (t) { maybeDone() }) - var torrentReady = false - var announced = false function maybeDone () { if (torrentReady && announced) cb(null) } @@ -66,7 +67,7 @@ test('blocklist blocks peers discovered via DHT', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var torrent2 = client2.add(fixtures.leaves.parsedTorrent, { + const torrent2 = client2.add(fixtures.leaves.parsedTorrent, { path: common.getDownloadPath('client_2', fixtures.leaves.parsedTorrent.infoHash) }) @@ -86,7 +87,7 @@ test('blocklist blocks peers discovered via DHT', function (t) { t.fail('client2 should not find any peers') }) - var blockedPeer, announced + let blockedPeer, announced function maybeDone () { if (blockedPeer && announced) cb(null) } diff --git a/test/node/blocklist-tracker.js b/test/node/blocklist-tracker.js index e877d24..74d831d 100644 --- a/test/node/blocklist-tracker.js +++ b/test/node/blocklist-tracker.js @@ -1,23 +1,23 @@ -var fixtures = require('webtorrent-fixtures') -var series = require('run-series') -var test = require('tape') -var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../../') -var common = require('../common') +const fixtures = require('webtorrent-fixtures') +const series = require('run-series') +const test = require('tape') +const TrackerServer = require('bittorrent-tracker/server') +const WebTorrent = require('../../') +const common = require('../common') test('blocklist blocks peers discovered via tracker', function (t) { t.plan(9) - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) - var tracker, client1, client2 + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + let tracker, client1, client2 series([ function (cb) { tracker = new TrackerServer({ udp: false, ws: false }) tracker.listen(function () { - var port = tracker.http.address().port - var announceUrl = 'http://127.0.0.1:' + port + '/announce' + const port = tracker.http.address().port + const announceUrl = 'http://127.0.0.1:' + port + '/announce' // Overwrite announce with our local tracker parsedTorrent.announce = announceUrl @@ -39,7 +39,7 @@ test('blocklist blocks peers discovered via tracker', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent1 = client1.add(parsedTorrent, { + const torrent1 = client1.add(parsedTorrent, { path: common.getDownloadPath('client_1', parsedTorrent.infoHash) }) @@ -61,7 +61,7 @@ test('blocklist blocks peers discovered via tracker', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var torrent2 = client2.add(parsedTorrent, { + const torrent2 = client2.add(parsedTorrent, { path: common.getDownloadPath('client_2', parsedTorrent.infoHash) }) diff --git a/test/node/blocklist.js b/test/node/blocklist.js index 87c131f..6a5af5e 100644 --- a/test/node/blocklist.js +++ b/test/node/blocklist.js @@ -1,9 +1,9 @@ -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var http = require('http') -var test = require('tape') -var WebTorrent = require('../../') -var zlib = require('zlib') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const http = require('http') +const test = require('tape') +const WebTorrent = require('../../') +const zlib = require('zlib') function assertBlocked (t, torrent, addr) { torrent.once('blockedPeer', function (_addr) { @@ -22,7 +22,7 @@ function assertReachable (t, torrent, addr) { test('blocklist (single IP)', function (t) { t.plan(9) - var client = new WebTorrent({ + const client = new WebTorrent({ dht: false, tracker: false, blocklist: ['1.2.3.4'] @@ -48,7 +48,7 @@ test('blocklist (single IP)', function (t) { test('blocklist (array of IPs)', function (t) { t.plan(13) - var client = new WebTorrent({ + const client = new WebTorrent({ dht: false, tracker: false, blocklist: ['1.2.3.4', '5.6.7.8'] @@ -112,7 +112,7 @@ function assertList (t, torrent) { test('blocklist (array of IP ranges)', function (t) { t.plan(49) - var client = new WebTorrent({ + const client = new WebTorrent({ dht: false, tracker: false, blocklist: [ @@ -134,7 +134,7 @@ test('blocklist (array of IP ranges)', function (t) { test('blocklist (http url)', function (t) { t.plan(51) - var server = http.createServer(function (req, res) { + const server = http.createServer(function (req, res) { // Check that WebTorrent declares a user agent t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1) @@ -142,9 +142,9 @@ test('blocklist (http url)', function (t) { }) server.listen(0, function () { - var port = server.address().port - var url = 'http://127.0.0.1:' + port - var client = new WebTorrent({ + const port = server.address().port + const url = 'http://127.0.0.1:' + port + const client = new WebTorrent({ dht: false, tracker: false, blocklist: url @@ -167,7 +167,7 @@ test('blocklist (http url)', function (t) { test('blocklist (http url with gzip encoding)', function (t) { t.plan(51) - var server = http.createServer(function (req, res) { + const server = http.createServer(function (req, res) { // Check that WebTorrent declares a user agent t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1) @@ -178,9 +178,9 @@ test('blocklist (http url with gzip encoding)', function (t) { }) server.listen(0, function () { - var port = server.address().port - var url = 'http://127.0.0.1:' + port - var client = new WebTorrent({ + const port = server.address().port + const url = 'http://127.0.0.1:' + port + const client = new WebTorrent({ dht: false, tracker: false, blocklist: url @@ -203,7 +203,7 @@ test('blocklist (http url with gzip encoding)', function (t) { test('blocklist (http url with deflate encoding)', function (t) { t.plan(51) - var server = http.createServer(function (req, res) { + const server = http.createServer(function (req, res) { // Check that WebTorrent declares a user agent t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1) @@ -214,9 +214,9 @@ test('blocklist (http url with deflate encoding)', function (t) { }) server.listen(0, function () { - var port = server.address().port - var url = 'http://127.0.0.1:' + port - var client = new WebTorrent({ + const port = server.address().port + const url = 'http://127.0.0.1:' + port + const client = new WebTorrent({ dht: false, tracker: false, blocklist: url @@ -239,7 +239,7 @@ test('blocklist (http url with deflate encoding)', function (t) { test('blocklist (fs path)', function (t) { t.plan(49) - var client = new WebTorrent({ + const client = new WebTorrent({ dht: false, tracker: false, blocklist: fixtures.blocklist.path @@ -258,7 +258,7 @@ test('blocklist (fs path)', function (t) { test('blocklist (fs path with gzip)', function (t) { t.plan(49) - var client = new WebTorrent({ + const client = new WebTorrent({ dht: false, tracker: false, blocklist: fixtures.blocklist.gzipPath diff --git a/test/node/conn-pool.js b/test/node/conn-pool.js index 435d951..9a53f91 100644 --- a/test/node/conn-pool.js +++ b/test/node/conn-pool.js @@ -1,14 +1,14 @@ -var test = require('tape') -var fixtures = require('webtorrent-fixtures') -var WebTorrent = require('../../') +const test = require('tape') +const fixtures = require('webtorrent-fixtures') +const WebTorrent = require('../../') const MemoryChunkStore = require('memory-chunk-store') const dgram = require('dgram') test('client.conn-pool: use TCP when uTP disabled', function (t) { t.plan(6) - var client1 = new WebTorrent({ dht: false, tracker: false, utp: false }) - var client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) + const client1 = new WebTorrent({ dht: false, tracker: false, utp: false }) + const client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -24,12 +24,12 @@ test('client.conn-pool: use TCP when uTP disabled', function (t) { client2.on('listening', function () { // Start downloading - var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers torrent.addPeer('127.0.0.1:' + client2.address().port) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) @@ -55,8 +55,8 @@ test('client.conn-pool: use TCP when uTP disabled', function (t) { test('client.conn-pool: use uTP when uTP enabled', function (t) { t.plan(6) - var client1 = new WebTorrent({ dht: false, tracker: false, utp: true }) - var client2 = new WebTorrent({ dht: false, tracker: false, utp: true }) + const client1 = new WebTorrent({ dht: false, tracker: false, utp: true }) + const client2 = new WebTorrent({ dht: false, tracker: false, utp: true }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -72,12 +72,12 @@ test('client.conn-pool: use uTP when uTP enabled', function (t) { client2.on('listening', function () { // Start downloading - var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers torrent.addPeer('127.0.0.1:' + client2.address().port) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) @@ -108,8 +108,8 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { const server = dgram.createSocket('udp4') server.bind(63000) - var client1 = new WebTorrent({ dht: false, tracker: false, utp: true, torrentPort: 63000 }) - var client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) + const client1 = new WebTorrent({ dht: false, tracker: false, utp: true, torrentPort: 63000 }) + const client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -125,12 +125,12 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { client2.on('listening', function () { // Start downloading - var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers torrent.addPeer('127.0.0.1:' + client2.address().port) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) @@ -159,8 +159,8 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { test('client.conn-pool: fallback to TCP when remote client has uTP disabled', function (t) { t.plan(6) - var client1 = new WebTorrent({ dht: false, tracker: false, utp: true }) - var client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) + const client1 = new WebTorrent({ dht: false, tracker: false, utp: true }) + const client2 = new WebTorrent({ dht: false, tracker: false, utp: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -176,12 +176,12 @@ test('client.conn-pool: fallback to TCP when remote client has uTP disabled', fu client2.on('listening', function () { // Start downloading - var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers torrent.addPeer('127.0.0.1:' + client2.address().port) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) diff --git a/test/node/download-dht-magnet.js b/test/node/download-dht-magnet.js index 3372317..5b84b11 100644 --- a/test/node/download-dht-magnet.js +++ b/test/node/download-dht-magnet.js @@ -1,21 +1,21 @@ -var DHT = require('bittorrent-dht/server') -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var MemoryChunkStore = require('memory-chunk-store') -var networkAddress = require('network-address') -var series = require('run-series') -var test = require('tape') -var WebTorrent = require('../../') +const DHT = require('bittorrent-dht/server') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const MemoryChunkStore = require('memory-chunk-store') +const networkAddress = require('network-address') +const series = require('run-series') +const test = require('tape') +const WebTorrent = require('../../') test('Download using DHT (via magnet uri)', function (t) { t.plan(12) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client1, client2 + let client1, client2 series([ function (cb) { @@ -23,6 +23,9 @@ test('Download using DHT (via magnet uri)', function (t) { }, function (cb) { + let announced = false + let loaded = false + client1 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port, host: networkAddress.ipv4() } @@ -35,7 +38,7 @@ test('Download using DHT (via magnet uri)', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) torrent.on('dhtAnnounce', function () { t.pass('finished dht announce') @@ -47,7 +50,7 @@ test('Download using DHT (via magnet uri)', function (t) { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = ['Leaves of Grass by Walt Whitman.epub'] + const names = ['Leaves of Grass by Walt Whitman.epub'] t.deepEqual(torrent.files.map(function (file) { return file.name }), names) }) @@ -57,14 +60,15 @@ test('Download using DHT (via magnet uri)', function (t) { maybeDone() }) - var announced = false - var loaded = false function maybeDone () { if (announced && loaded) cb(null) } }, function (cb) { + let gotBuffer = false + let gotDone = false + client2 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port, host: networkAddress.ipv4() } @@ -92,8 +96,6 @@ test('Download using DHT (via magnet uri)', function (t) { client2.add(fixtures.leaves.magnetURI, { store: MemoryChunkStore }) - var gotBuffer = false - var gotDone = false function maybeDone () { if (gotBuffer && gotDone) cb(null) } diff --git a/test/node/download-dht-torrent.js b/test/node/download-dht-torrent.js index 9d5a93b..c8b8219 100644 --- a/test/node/download-dht-torrent.js +++ b/test/node/download-dht-torrent.js @@ -1,20 +1,20 @@ -var DHT = require('bittorrent-dht/server') -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var test = require('tape') -var WebTorrent = require('../../') +const DHT = require('bittorrent-dht/server') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const test = require('tape') +const WebTorrent = require('../../') test('Download using DHT (via .torrent file)', function (t) { t.plan(10) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client1, client2 + let client1, client2 series([ function (cb) { @@ -22,6 +22,10 @@ test('Download using DHT (via .torrent file)', function (t) { }, function (cb) { + let announced = false + let loaded = false + let noPeersFound = false + client1 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port } @@ -34,13 +38,13 @@ test('Download using DHT (via .torrent file)', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) torrent.on('ready', function () { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = ['Leaves of Grass by Walt Whitman.epub'] + const names = ['Leaves of Grass by Walt Whitman.epub'] t.deepEqual(torrent.files.map(function (file) { return file.name }), names) }) @@ -60,9 +64,6 @@ test('Download using DHT (via .torrent file)', function (t) { maybeDone(null) }) - var announced = false - var loaded = false - var noPeersFound = false function maybeDone (err) { if ((announced && loaded && noPeersFound) || err) cb(err, client1) } @@ -78,6 +79,9 @@ test('Download using DHT (via .torrent file)', function (t) { client2.on('warning', function (err) { t.fail(err) }) client2.on('torrent', function (torrent) { + let torrentDone = false + let gotBuffer = false + torrent.files.forEach(function (file) { file.getBuffer(function (err, buf) { if (err) throw err @@ -93,8 +97,6 @@ test('Download using DHT (via .torrent file)', function (t) { maybeDone() }) - var torrentDone = false - var gotBuffer = false function maybeDone () { if (torrentDone && gotBuffer) cb(null) } diff --git a/test/node/download-from-ip.js b/test/node/download-from-ip.js index 270b774..77a1281 100644 --- a/test/node/download-from-ip.js +++ b/test/node/download-from-ip.js @@ -20,7 +20,7 @@ test('Download via torrent.addPeer()', (t) => { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = ['Leaves of Grass by Walt Whitman.epub'] + const names = ['Leaves of Grass by Walt Whitman.epub'] t.deepEqual(torrent.files.map(function (file) { return file.name }), names) }) diff --git a/test/node/download-metadata.js b/test/node/download-metadata.js index 9a185e9..4f3604f 100644 --- a/test/node/download-metadata.js +++ b/test/node/download-metadata.js @@ -1,11 +1,11 @@ -var fixtures = require('webtorrent-fixtures') -var http = require('http') -var MemoryChunkStore = require('memory-chunk-store') -var test = require('tape') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const http = require('http') +const MemoryChunkStore = require('memory-chunk-store') +const test = require('tape') +const WebTorrent = require('../../') function createServer (data, cb) { - var server = http.createServer(function (req, res) { + const server = http.createServer(function (req, res) { if (req.url !== '/') { res.statusCode = 404 res.end() @@ -15,8 +15,8 @@ function createServer (data, cb) { }) server.on('listening', function () { - var address = server.address() - var url = 'http://127.0.0.1:' + address.port + '/' + const address = server.address() + const url = 'http://127.0.0.1:' + address.port + '/' cb(url, server) }) @@ -26,13 +26,13 @@ function createServer (data, cb) { test('Download metadata for magnet URI with xs parameter', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) createServer(fixtures.leaves.torrent, function (url, server) { - var encodedUrl = encodeURIComponent(url) + const encodedUrl = encodeURIComponent(url) client.add(fixtures.leaves.magnetURI + '&xs=' + encodedUrl, { store: MemoryChunkStore }, function (torrent) { t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub') client.destroy(function (err) { t.error(err, 'client destroyed') }) @@ -44,18 +44,18 @@ test('Download metadata for magnet URI with xs parameter', function (t) { test('Download metadata for magnet URI with 2 xs parameters', function (t) { t.plan(4) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) createServer(fixtures.leaves.torrent, function (url1, server1) { - var encodedUrl1 = encodeURIComponent(url1) + const encodedUrl1 = encodeURIComponent(url1) createServer(fixtures.leaves.torrent, function (url2, server2) { - var encodedUrl2 = encodeURIComponent(url2) + const encodedUrl2 = encodeURIComponent(url2) - var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 + const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 client.add(uri, { store: MemoryChunkStore }, function (torrent) { t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub') @@ -70,15 +70,15 @@ test('Download metadata for magnet URI with 2 xs parameters', function (t) { test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid protocol', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) createServer(fixtures.leaves.torrent, function (url, server) { - var encodedUrl1 = encodeURIComponent('invalidurl:example') - var encodedUrl2 = encodeURIComponent(url) - var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 + const encodedUrl1 = encodeURIComponent('invalidurl:example') + const encodedUrl2 = encodeURIComponent(url) + const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 client.add(uri, { store: MemoryChunkStore }, function (torrent) { t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub') @@ -91,15 +91,15 @@ test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid prot test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', function (t) { t.plan(3) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) createServer(fixtures.leaves.torrent, function (url, server) { - var encodedUrl1 = encodeURIComponent(url + 'blah_404') - var encodedUrl2 = encodeURIComponent(url) - var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 + const encodedUrl1 = encodeURIComponent(url + 'blah_404') + const encodedUrl2 = encodeURIComponent(url) + const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2 client.add(uri, { store: MemoryChunkStore }, function (torrent) { t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub') @@ -112,7 +112,7 @@ test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', fu test('Download metadata magnet URI with unsupported protocol in xs parameter', function (t) { t.plan(1) - var client = new WebTorrent({ dht: false, tracker: false }) + const client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) diff --git a/test/node/download-private-dht.js b/test/node/download-private-dht.js index 0bc43c8..b13f494 100644 --- a/test/node/download-private-dht.js +++ b/test/node/download-private-dht.js @@ -1,19 +1,19 @@ -var DHT = require('bittorrent-dht/server') -var fixtures = require('webtorrent-fixtures') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var test = require('tape') -var WebTorrent = require('../../') +const DHT = require('bittorrent-dht/server') +const fixtures = require('webtorrent-fixtures') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const test = require('tape') +const WebTorrent = require('../../') test('private torrent should not use DHT', function (t) { t.plan(4) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client + let client series([ function (cb) { @@ -29,7 +29,7 @@ test('private torrent should not use DHT', function (t) { client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent = client.add(fixtures.bunny.parsedTorrent, { store: MemoryChunkStore }) + const torrent = client.add(fixtures.bunny.parsedTorrent, { store: MemoryChunkStore }) torrent.on('dhtAnnounce', function () { t.fail('client announced to dht') @@ -57,12 +57,12 @@ test('private torrent should not use DHT', function (t) { test('public torrent should use DHT', function (t) { t.plan(4) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client + let client series([ function (cb) { @@ -77,7 +77,7 @@ test('public torrent should use DHT', function (t) { client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent = client.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) + const torrent = client.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) torrent.on('dhtAnnounce', function () { t.pass('client announced to dht') @@ -105,12 +105,12 @@ test('public torrent should use DHT', function (t) { test('public torrent with forced private option should not use DHT', function (t) { t.plan(4) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client + let client series([ function (cb) { @@ -126,7 +126,7 @@ test('public torrent with forced private option should not use DHT', function (t client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent = client.add(fixtures.leaves.parsedTorrent, { + const torrent = client.add(fixtures.leaves.parsedTorrent, { private: true, store: MemoryChunkStore }) @@ -157,12 +157,12 @@ test('public torrent with forced private option should not use DHT', function (t test('private torrent with forced public option should use DHT', function (t) { t.plan(4) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client + let client series([ function (cb) { @@ -178,7 +178,7 @@ test('private torrent with forced public option should use DHT', function (t) { client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - var torrent = client.add(fixtures.bunny.parsedTorrent, { + const torrent = client.add(fixtures.bunny.parsedTorrent, { private: false, store: MemoryChunkStore }) diff --git a/test/node/download-tracker-magnet.js b/test/node/download-tracker-magnet.js index e597191..646de4a 100644 --- a/test/node/download-tracker-magnet.js +++ b/test/node/download-tracker-magnet.js @@ -1,10 +1,10 @@ -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var test = require('tape') -var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const test = require('tape') +const TrackerServer = require('bittorrent-tracker/server') +const WebTorrent = require('../../') test('Download using UDP tracker (via magnet uri)', function (t) { magnetDownloadTest(t, 'udp') @@ -17,20 +17,20 @@ test('Download using HTTP tracker (via magnet uri)', function (t) { function magnetDownloadTest (t, serverType) { t.plan(10) - var tracker = new TrackerServer( + const tracker = new TrackerServer( serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false } ) tracker.on('error', function (err) { t.fail(err) }) tracker.on('warning', function (err) { t.fail(err) }) - var trackerStartCount = 0 + let trackerStartCount = 0 tracker.on('start', function () { trackerStartCount += 1 }) - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) - var magnetURI, client1, client2 + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + let magnetURI, client1, client2 series([ function (cb) { @@ -38,8 +38,8 @@ function magnetDownloadTest (t, serverType) { }, function (cb) { - var port = tracker[serverType].address().port - var announceUrl = serverType === 'http' + const port = tracker[serverType].address().port + const announceUrl = serverType === 'http' ? 'http://127.0.0.1:' + port + '/announce' : 'udp://127.0.0.1:' + port @@ -55,7 +55,7 @@ function magnetDownloadTest (t, serverType) { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = [ + const names = [ 'Leaves of Grass by Walt Whitman.epub' ] @@ -80,6 +80,9 @@ function magnetDownloadTest (t, serverType) { client2.on('warning', function (err) { t.fail(err) }) client2.on('torrent', function (torrent) { + let gotBuffer = false + let torrentDone = false + torrent.files.forEach(function (file) { file.getBuffer(function (err, buf) { if (err) throw err @@ -95,8 +98,6 @@ function magnetDownloadTest (t, serverType) { maybeDone() }) - var gotBuffer = false - var torrentDone = false function maybeDone () { if (gotBuffer && torrentDone) cb(null) } diff --git a/test/node/download-tracker-torrent.js b/test/node/download-tracker-torrent.js index 17f9a0b..d3ff0ca 100644 --- a/test/node/download-tracker-torrent.js +++ b/test/node/download-tracker-torrent.js @@ -1,10 +1,10 @@ -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var test = require('tape') -var TrackerServer = require('bittorrent-tracker/server') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const test = require('tape') +const TrackerServer = require('bittorrent-tracker/server') +const WebTorrent = require('../../') test('Download using UDP tracker (via .torrent file)', function (t) { torrentDownloadTest(t, 'udp') @@ -17,10 +17,10 @@ test('Download using HTTP tracker (via .torrent file)', function (t) { function torrentDownloadTest (t, serverType) { t.plan(9) - var trackerStartCount = 0 - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + let trackerStartCount = 0 + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) - var tracker = new TrackerServer( + const tracker = new TrackerServer( serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false } ) @@ -31,7 +31,7 @@ function torrentDownloadTest (t, serverType) { trackerStartCount += 1 }) - var client1, client2 + let client1, client2 series([ function (cb) { @@ -43,9 +43,9 @@ function torrentDownloadTest (t, serverType) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var port = tracker[serverType].address().port + const port = tracker[serverType].address().port - var announceUrl = serverType === 'http' + const announceUrl = serverType === 'http' ? 'http://127.0.0.1:' + port + '/announce' : 'udp://127.0.0.1:' + port @@ -56,7 +56,7 @@ function torrentDownloadTest (t, serverType) { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = [ + const names = [ 'Leaves of Grass by Walt Whitman.epub' ] @@ -76,6 +76,9 @@ function torrentDownloadTest (t, serverType) { client2.add(parsedTorrent, { store: MemoryChunkStore }) client2.on('torrent', function (torrent) { + let gotBuffer = false + let torrentDone = false + torrent.files.forEach(function (file) { file.getBuffer(function (err, buf) { if (err) throw err @@ -91,8 +94,6 @@ function torrentDownloadTest (t, serverType) { maybeDone() }) - var gotBuffer = false - var torrentDone = false function maybeDone () { if (gotBuffer && torrentDone) cb(null) } diff --git a/test/node/download-webseed-magnet.js b/test/node/download-webseed-magnet.js index 9a2ed07..e73285a 100644 --- a/test/node/download-webseed-magnet.js +++ b/test/node/download-webseed-magnet.js @@ -1,22 +1,22 @@ -var finalhandler = require('finalhandler') -var fixtures = require('webtorrent-fixtures') -var http = require('http') -var path = require('path') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var serveStatic = require('serve-static') -var test = require('tape') -var WebTorrent = require('../../') +const finalhandler = require('finalhandler') +const fixtures = require('webtorrent-fixtures') +const http = require('http') +const path = require('path') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const serveStatic = require('serve-static') +const test = require('tape') +const WebTorrent = require('../../') test('Download using webseed (via magnet uri)', function (t) { t.plan(9) - var serve = serveStatic(path.dirname(fixtures.leaves.contentPath)) - var httpServer = http.createServer(function (req, res) { - var done = finalhandler(req, res) + const serve = serveStatic(path.dirname(fixtures.leaves.contentPath)) + const httpServer = http.createServer(function (req, res) { + const done = finalhandler(req, res) serve(req, res, done) }) - var client1, client2 + let client1, client2 httpServer.on('error', function (err) { t.fail(err) }) @@ -31,8 +31,8 @@ test('Download using webseed (via magnet uri)', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var gotTorrent = false - var gotListening = false + let gotTorrent = false + let gotListening = false function maybeDone () { if (gotTorrent && gotListening) cb(null) } @@ -41,7 +41,7 @@ test('Download using webseed (via magnet uri)', function (t) { // torrent metadata has been fetched -- sanity check it t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub') - var names = [ + const names = [ 'Leaves of Grass by Walt Whitman.epub' ] @@ -52,7 +52,7 @@ test('Download using webseed (via magnet uri)', function (t) { maybeDone() }) - var torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }) torrent.on('infoHash', function () { gotListening = true @@ -66,10 +66,13 @@ test('Download using webseed (via magnet uri)', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var webSeedUrl = 'http://localhost:' + httpServer.address().port + '/' + fixtures.leaves.parsedTorrent.name - var magnetURI = fixtures.leaves.magnetURI + '&ws=' + encodeURIComponent(webSeedUrl) + const webSeedUrl = 'http://localhost:' + httpServer.address().port + '/' + fixtures.leaves.parsedTorrent.name + const magnetURI = fixtures.leaves.magnetURI + '&ws=' + encodeURIComponent(webSeedUrl) client2.on('torrent', function (torrent) { + let gotBuffer = false + let torrentDone = false + torrent.files.forEach(function (file) { file.getBuffer(function (err, buf) { t.error(err) @@ -85,14 +88,12 @@ test('Download using webseed (via magnet uri)', function (t) { maybeDone() }) - var gotBuffer = false - var torrentDone = false function maybeDone () { if (gotBuffer && torrentDone) cb(null) } }) - var torrent = client2.add(magnetURI, { store: MemoryChunkStore }) + const torrent = client2.add(magnetURI, { store: MemoryChunkStore }) torrent.on('infoHash', function () { torrent.addPeer('127.0.0.1:' + client1.address().port) diff --git a/test/node/download-webseed-torrent.js b/test/node/download-webseed-torrent.js index c248857..cc0dec4 100644 --- a/test/node/download-webseed-torrent.js +++ b/test/node/download-webseed-torrent.js @@ -1,27 +1,27 @@ -var finalhandler = require('finalhandler') -var fixtures = require('webtorrent-fixtures') -var http = require('http') -var MemoryChunkStore = require('memory-chunk-store') -var path = require('path') -var series = require('run-series') -var serveStatic = require('serve-static') -var test = require('tape') -var WebTorrent = require('../../') +const finalhandler = require('finalhandler') +const fixtures = require('webtorrent-fixtures') +const http = require('http') +const MemoryChunkStore = require('memory-chunk-store') +const path = require('path') +const series = require('run-series') +const serveStatic = require('serve-static') +const test = require('tape') +const WebTorrent = require('../../') // it should be fast to download a small torrent over local HTTP -var WEB_SEED_TIMEOUT_MS = 500 +const WEB_SEED_TIMEOUT_MS = 500 test('Download using webseed (via .torrent file)', function (t) { t.plan(6) t.timeoutAfter(WEB_SEED_TIMEOUT_MS) - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) - var httpServer = http.createServer(function (req, res) { - var done = finalhandler(req, res) + const httpServer = http.createServer(function (req, res) { + const done = finalhandler(req, res) serveStatic(path.dirname(fixtures.leaves.contentPath))(req, res, done) }) - var client + let client httpServer.on('error', function (err) { t.fail(err) }) @@ -41,6 +41,9 @@ test('Download using webseed (via .torrent file)', function (t) { client.on('warning', function (err) { t.fail(err) }) client.on('torrent', function (torrent) { + let gotBuffer = false + let torrentDone = false + torrent.files.forEach(function (file) { file.getBuffer(function (err, buf) { t.error(err) @@ -56,8 +59,6 @@ test('Download using webseed (via .torrent file)', function (t) { maybeDone() }) - var gotBuffer = false - var torrentDone = false function maybeDone () { if (gotBuffer && torrentDone) cb(null) } @@ -77,12 +78,12 @@ test('Download using webseed (via .torrent file)', function (t) { }) test('Disable webseeds', function (t) { - var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) + const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent) - var httpServer = http.createServer(function (req, res) { + const httpServer = http.createServer(function (req, res) { t.fail('webseed http server should not get any requests') }) - var client + let client httpServer.on('error', function (err) { t.fail(err) }) diff --git a/test/node/extensions.js b/test/node/extensions.js index 9dccd1d..729d1c5 100644 --- a/test/node/extensions.js +++ b/test/node/extensions.js @@ -1,10 +1,10 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../../') test('extension support', function (t) { t.plan(6) - var extendedHandshakes = 0 + let extendedHandshakes = 0 function Extension (wire) { wire.extendedHandshake.test = 'Hello, World!' @@ -29,12 +29,12 @@ test('extension support', function (t) { } } - var client1 = new WebTorrent({ dht: false, tracker: false }) + const client1 = new WebTorrent({ dht: false, tracker: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var client2 = new WebTorrent({ dht: false, tracker: false }) + const client2 = new WebTorrent({ dht: false, tracker: false }) client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) @@ -44,7 +44,7 @@ test('extension support', function (t) { t.pass('client1 onWire') wire.use(Extension) }) - var torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash) + const torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash) torrent2.on('wire', function (wire) { t.pass('client2 onWire') wire.use(Extension) diff --git a/test/node/metadata.js b/test/node/metadata.js index 2b3fe56..121e858 100644 --- a/test/node/metadata.js +++ b/test/node/metadata.js @@ -1,12 +1,12 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../../') test('ut_metadata transfer', function (t) { t.plan(6) - var client1 = new WebTorrent({ dht: false, tracker: false }) - var client2 = new WebTorrent({ dht: false, tracker: false }) + const client1 = new WebTorrent({ dht: false, tracker: false }) + const client2 = new WebTorrent({ dht: false, tracker: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -26,7 +26,7 @@ test('ut_metadata transfer', function (t) { t.deepEqual(torrent1.info, fixtures.leaves.parsedTorrent.info) // client2 starts with infohash - var torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash) + const torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash) torrent2.on('infoHash', function () { // manually add the peer diff --git a/test/node/seed-stream.js b/test/node/seed-stream.js index e56964e..3e973b6 100644 --- a/test/node/seed-stream.js +++ b/test/node/seed-stream.js @@ -1,18 +1,18 @@ -var Readable = require('readable-stream').Readable -var series = require('run-series') -var test = require('tape') -var Tracker = require('bittorrent-tracker/server') -var WebTorrent = require('../../') +const Readable = require('readable-stream').Readable +const series = require('run-series') +const test = require('tape') +const Tracker = require('bittorrent-tracker/server') +const WebTorrent = require('../../') test('client.seed: stream', function (t) { t.plan(9) - var tracker = new Tracker({ udp: false, ws: false }) + const tracker = new Tracker({ udp: false, ws: false }) tracker.on('error', function (err) { t.fail(err) }) tracker.on('warning', function (err) { t.fail(err) }) - var seeder, client, announceUrl, magnetURI + let seeder, client, announceUrl, magnetURI series([ function (cb) { @@ -20,7 +20,7 @@ test('client.seed: stream', function (t) { }, function (cb) { - var port = tracker.http.address().port + const port = tracker.http.address().port announceUrl = 'http://localhost:' + port + '/announce' seeder = new WebTorrent({ dht: false }) @@ -28,12 +28,12 @@ test('client.seed: stream', function (t) { seeder.on('error', function (err) { t.fail(err) }) seeder.on('warning', function (err) { t.fail(err) }) - var stream = new Readable() + const stream = new Readable() stream._read = function () {} stream.push('HELLO WORLD\n') stream.push(null) - var seederOpts = { + const seederOpts = { name: 'hello.txt', pieceLength: 5, announce: [announceUrl] diff --git a/test/node/seed-while-download.js b/test/node/seed-while-download.js index b8f3500..961b4db 100644 --- a/test/node/seed-while-download.js +++ b/test/node/seed-while-download.js @@ -1,20 +1,20 @@ -var DHT = require('bittorrent-dht/server') -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var MemoryChunkStore = require('memory-chunk-store') -var series = require('run-series') -var test = require('tape') -var WebTorrent = require('../../') +const DHT = require('bittorrent-dht/server') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const MemoryChunkStore = require('memory-chunk-store') +const series = require('run-series') +const test = require('tape') +const WebTorrent = require('../../') test('Seed and download a file at the same time', function (t) { t.plan(14) - var dhtServer = new DHT({ bootstrap: false }) + const dhtServer = new DHT({ bootstrap: false }) dhtServer.on('error', function (err) { t.fail(err) }) dhtServer.on('warning', function (err) { t.fail(err) }) - var client1, client2 + let client1, client2 series([ function (cb) { @@ -22,6 +22,9 @@ test('Seed and download a file at the same time', function (t) { }, function (cb) { + let announced = false + let loaded = false + client1 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port } @@ -30,7 +33,7 @@ test('Seed and download a file at the same time', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent = client1.add(fixtures.leaves.torrent, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.torrent, { store: MemoryChunkStore }) torrent.on('dhtAnnounce', function () { t.pass('client1 finished dht announce') @@ -44,14 +47,15 @@ test('Seed and download a file at the same time', function (t) { maybeDone() }) - var announced = false - var loaded = false function maybeDone () { if (announced && loaded) cb(null) } }, function (cb) { + let announced = false + let loaded = false + client2 = new WebTorrent({ tracker: false, dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port } @@ -60,7 +64,7 @@ test('Seed and download a file at the same time', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var torrent = client2.add(fixtures.alice.torrent, { store: MemoryChunkStore }) + const torrent = client2.add(fixtures.alice.torrent, { store: MemoryChunkStore }) torrent.on('dhtAnnounce', function () { t.pass('client2 finished dht announce') @@ -74,14 +78,17 @@ test('Seed and download a file at the same time', function (t) { maybeDone() }) - var announced = false - var loaded = false function maybeDone () { if (announced && loaded) cb(null) } }, function (cb) { + let gotBuffer1 = false + let gotBuffer2 = false + let gotDone1 = false + let gotDone2 = false + client1.add(fixtures.alice.magnetURI, { store: MemoryChunkStore }) client1.on('torrent', function (torrent) { @@ -116,10 +123,6 @@ test('Seed and download a file at the same time', function (t) { }) }) - var gotBuffer1 = false - var gotBuffer2 = false - var gotDone1 = false - var gotDone2 = false function maybeDone () { if (gotBuffer1 && gotBuffer2 && gotDone1 && gotDone2) cb(null) } diff --git a/test/node/server.js b/test/node/server.js index 564d7b1..c40bd93 100644 --- a/test/node/server.js +++ b/test/node/server.js @@ -1,23 +1,23 @@ -var fixtures = require('webtorrent-fixtures') -var fs = require('fs') -var get = require('simple-get') -var test = require('tape') -var WebTorrent = require('../../') +const fixtures = require('webtorrent-fixtures') +const fs = require('fs') +const get = require('simple-get') +const test = require('tape') +const WebTorrent = require('../../') test('torrent.createServer: programmatic http server', function (t) { t.plan(9) - var client = new WebTorrent({ tracker: false, dht: false }) + const client = new WebTorrent({ tracker: false, dht: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) client.add(fixtures.leaves.torrent, function (torrent) { t.pass('got "torrent" event') - var server = torrent.createServer() + const server = torrent.createServer() server.listen(0, function () { - var port = server.address().port + const port = server.address().port t.pass('server is listening on ' + port) // Seeding after server is created should work @@ -25,7 +25,7 @@ test('torrent.createServer: programmatic http server', function (t) { t.error(err, 'loaded seed content into torrent') }) - var host = 'http://localhost:' + port + const host = 'http://localhost:' + port // Index page should list files in the torrent get.concat(host + '/', function (err, res, data) { diff --git a/test/node/torrent-events.js b/test/node/torrent-events.js index 916ca4e..35aabfa 100644 --- a/test/node/torrent-events.js +++ b/test/node/torrent-events.js @@ -6,8 +6,8 @@ const MemoryChunkStore = require('memory-chunk-store') test('client.add: emit torrent events in order', function (t) { t.plan(6) - var client1 = new WebTorrent({ dht: false, tracker: false }) - var client2 = new WebTorrent({ dht: false, tracker: false }) + const client1 = new WebTorrent({ dht: false, tracker: false }) + const client2 = new WebTorrent({ dht: false, tracker: false }) client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) @@ -23,12 +23,12 @@ test('client.add: emit torrent events in order', function (t) { client2.on('listening', function () { // Start downloading - var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) + const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers torrent.addPeer('127.0.0.1:' + client2.address().port) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) @@ -54,14 +54,14 @@ test('client.add: emit torrent events in order', function (t) { test('client.seed: emit torrent events in order', function (t) { t.plan(5) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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.seed(fixtures.leaves.content) + const torrent = client.seed(fixtures.leaves.content) - var order = 0 + let order = 0 torrent.on('infoHash', function () { t.equal(++order, 1) diff --git a/test/rarity-map.js b/test/rarity-map.js index cde945a..6c5ec1e 100644 --- a/test/rarity-map.js +++ b/test/rarity-map.js @@ -1,17 +1,17 @@ -var fixtures = require('webtorrent-fixtures') -var randombytes = require('randombytes') -var test = require('tape') -var Torrent = require('../lib/torrent') -var Wire = require('bittorrent-protocol') +const fixtures = require('webtorrent-fixtures') +const randombytes = require('randombytes') +const test = require('tape') +const Torrent = require('../lib/torrent') +const Wire = require('bittorrent-protocol') test('Rarity map usage', function (t) { t.plan(16) - var numPieces = 4 - var torrentId = Object.assign({}, fixtures.numbers.parsedTorrent, { + const numPieces = 4 + const torrentId = Object.assign({}, fixtures.numbers.parsedTorrent, { pieces: Array(numPieces) }) - var client = { + const client = { listening: true, peerId: randombytes(20).toString('hex'), torrentPort: 6889, @@ -19,13 +19,13 @@ test('Rarity map usage', function (t) { tracker: false, _remove: function () {} } - var opts = {} - var torrent = new Torrent(torrentId, client, opts) + const opts = {} + const torrent = new Torrent(torrentId, client, opts) torrent.on('metadata', function () { torrent._onWire(new Wire()) torrent._onWire(new Wire()) - var rarityMap = torrent._rarityMap + const rarityMap = torrent._rarityMap // test initial / empty case validateInitial() @@ -42,7 +42,7 @@ test('Rarity map usage', function (t) { setPiece(torrent.wires[1], 3) // test rarest piece after setting pieces and handling 'have' events - var piece = rarityMap.getRarestPiece() + let piece = rarityMap.getRarestPiece() t.equal(piece, 2) rarityMap.recalculate() @@ -87,7 +87,7 @@ test('Rarity map usage', function (t) { function validateInitial () { // note that getRarestPiece will return a random piece since they're all equal // so repeat the test several times to reasonably ensure its correctness. - var piece = rarityMap.getRarestPiece() + let piece = rarityMap.getRarestPiece() t.ok(piece >= 0 && piece < numPieces) piece = rarityMap.getRarestPiece() @@ -106,14 +106,14 @@ test('Rarity map usage', function (t) { } function addWire () { - var wire = new Wire() + const wire = new Wire() wire.peerPieces.set(1) wire.peerPieces.set(2) torrent._onWire(wire) } function removeWire (index) { - var wire = torrent.wires.splice(index, 1)[0] + const wire = torrent.wires.splice(index, 1)[0] wire.destroy() } }) diff --git a/test/torrent-destroy.js b/test/torrent-destroy.js index ceae205..5894627 100644 --- a/test/torrent-destroy.js +++ b/test/torrent-destroy.js @@ -1,16 +1,16 @@ -var fixtures = require('webtorrent-fixtures') -var test = require('tape') -var WebTorrent = require('../') +const fixtures = require('webtorrent-fixtures') +const test = require('tape') +const WebTorrent = require('../') test('torrent.destroy: destroy and remove torrent', function (t) { t.plan(5) - var client = new WebTorrent({ dht: false, tracker: false }) + const 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(fixtures.leaves.parsedTorrent.infoHash) + const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash) t.equal(client.torrents.length, 1) torrent.on('infoHash', function () { |