diff options
Diffstat (limited to 'test/node/download-dht-torrent.js')
-rw-r--r-- | test/node/download-dht-torrent.js | 34 |
1 files changed, 18 insertions, 16 deletions
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) } |