Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Rodríguez Baquero <github@diegorbaquero.com>2021-07-11 04:27:48 +0300
committerGitHub <noreply@github.com>2021-07-11 04:27:48 +0300
commit46033ae52eca6e22301bb8ed9566c498d3494711 (patch)
tree93cf4583fc9471dbe8e0b050c55b643638768f40 /test
parentfeb719d5426df7ad45d00ffadecb931780763134 (diff)
fix: modernize code (#2134)
* fix: modernize code * standard fix
Diffstat (limited to 'test')
-rw-r--r--test/browser/basic.js58
-rw-r--r--test/client-add-duplicate-trackers.js54
-rw-r--r--test/client-add.js127
-rw-r--r--test/client-destroy.js28
-rw-r--r--test/client-remove.js12
-rw-r--r--test/client-seed.js36
-rw-r--r--test/common.js2
-rw-r--r--test/duplicate.js76
-rw-r--r--test/node/basic.js116
-rw-r--r--test/node/blocklist-dht.js48
-rw-r--r--test/node/blocklist-tracker.js42
-rw-r--r--test/node/blocklist.js130
-rw-r--r--test/node/conn-pool.js130
-rw-r--r--test/node/download-dht-magnet.js48
-rw-r--r--test/node/download-dht-torrent.js52
-rw-r--r--test/node/download-from-ip.js20
-rw-r--r--test/node/download-lsd-magnet.js16
-rw-r--r--test/node/download-lsd-torrent.js18
-rw-r--r--test/node/download-metadata.js86
-rw-r--r--test/node/download-private-dht.js104
-rw-r--r--test/node/download-tracker-magnet.js54
-rw-r--r--test/node/download-tracker-torrent.js48
-rw-r--r--test/node/download-webseed-magnet.js50
-rw-r--r--test/node/download-webseed-torrent.js52
-rw-r--r--test/node/extensions.js61
-rw-r--r--test/node/metadata.js24
-rw-r--r--test/node/seed-stream.js38
-rw-r--r--test/node/seed-while-download.js54
-rw-r--r--test/node/server.js26
-rw-r--r--test/node/torrent-events.js42
-rw-r--r--test/rarity-map.js14
-rw-r--r--test/torrent-destroy.js12
32 files changed, 839 insertions, 839 deletions
diff --git a/test/browser/basic.js b/test/browser/basic.js
index b17b0a1..7b93761 100644
--- a/test/browser/basic.js
+++ b/test/browser/basic.js
@@ -7,7 +7,7 @@ img.name = 'img.png'
function verifyImage (t, err, elem) {
t.error(err)
t.ok(typeof elem.src === 'string')
- t.ok(elem.src.indexOf('blob') !== -1)
+ t.ok(elem.src.includes('blob'))
t.equal(elem.parentElement.nodeName, 'BODY')
t.ok(elem.alt, 'file.name')
elem.remove()
@@ -17,79 +17,79 @@ function verifyImage (t, err, elem) {
// TODO get these working
// logic taken from https://github.com/atom/electron/issues/2288#issuecomment-123147993
if (!(global && global.process && global.process.versions && global.process.versions.electron)) {
- test('image append w/ query selector', function (t) {
+ test('image append w/ query selector', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(img, function (torrent) {
- torrent.files[0].appendTo('body', function (err, elem) {
+ client.seed(img, torrent => {
+ torrent.files[0].appendTo('body', (err, elem) => {
verifyImage(t, err, elem)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
- test('image append w/ element', function (t) {
+ test('image append w/ element', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(img, function (torrent) {
- torrent.files[0].appendTo(document.body, function (err, elem) {
+ client.seed(img, torrent => {
+ torrent.files[0].appendTo(document.body, (err, elem) => {
verifyImage(t, err, elem)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
- test('image render w/ query selector', function (t) {
+ test('image render w/ query selector', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const tag = document.createElement('img')
tag.className = 'tag'
document.body.appendChild(tag)
- client.seed(img, function (torrent) {
- torrent.files[0].renderTo('img.tag', function (err, elem) {
+ client.seed(img, torrent => {
+ torrent.files[0].renderTo('img.tag', (err, elem) => {
verifyImage(t, err, elem)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
- test('image render w/ element', function (t) {
+ test('image render w/ element', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const tag = document.createElement('img')
document.body.appendChild(tag)
- client.seed(img, function (torrent) {
- torrent.files[0].renderTo(tag, function (err, elem) {
+ client.seed(img, torrent => {
+ torrent.files[0].renderTo(tag, (err, elem) => {
verifyImage(t, err, elem)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
@@ -97,17 +97,17 @@ if (!(global && global.process && global.process.versions && global.process.vers
})
}
-test('WebTorrent.WEBRTC_SUPPORT', function (t) {
+test('WebTorrent.WEBRTC_SUPPORT', t => {
t.plan(2)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
t.equal(WebTorrent.WEBRTC_SUPPORT, true)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
diff --git a/test/client-add-duplicate-trackers.js b/test/client-add-duplicate-trackers.js
index 4c32714..90eda00 100644
--- a/test/client-add-duplicate-trackers.js
+++ b/test/client-add-duplicate-trackers.js
@@ -2,26 +2,26 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('client.add: duplicate trackers', function (t) {
+test('client.add: duplicate trackers', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.torrent, {
announce: ['wss://example.com', 'wss://example.com', 'wss://example.com']
})
- torrent.on('ready', function () {
- t.equal(torrent.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
- client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ torrent.on('ready', () => {
+ t.equal(torrent.magnetURI, `${fixtures.leaves.magnetURI}&tr=${encodeURIComponent('wss://example.com')}`)
+ client.remove(fixtures.leaves.magnetURI, err => { t.error(err, 'torrent destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: duplicate trackers, with multiple torrents', function (t) {
+test('client.add: duplicate trackers, with multiple torrents', t => {
t.plan(5)
// Re-use this object, in case webtorrent is changing it
@@ -31,27 +31,27 @@ test('client.add: duplicate trackers, with multiple torrents', function (t) {
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent1 = client.add(fixtures.leaves.torrent, opts)
- torrent1.on('ready', function () {
- t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
+ torrent1.on('ready', () => {
+ t.equal(torrent1.magnetURI, `${fixtures.leaves.magnetURI}&tr=${encodeURIComponent('wss://example.com')}`)
const torrent2 = client.add(fixtures.alice.torrent, opts)
- torrent2.on('ready', function () {
- t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
+ torrent2.on('ready', () => {
+ t.equal(torrent2.magnetURI, `${fixtures.alice.magnetURI}&tr=${encodeURIComponent('wss://example.com')}`)
- torrent1.destroy(function (err) { t.error(err, 'torrent1 destroyed') })
- torrent2.destroy(function (err) { t.error(err, 'torrent2 destroyed') })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ torrent1.destroy(err => { t.error(err, 'torrent1 destroyed') })
+ torrent2.destroy(err => { t.error(err, 'torrent2 destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
})
-test('client.add: duplicate trackers (including in .torrent file), multiple torrents', function (t) {
+test('client.add: duplicate trackers (including in .torrent file), multiple torrents', t => {
t.plan(5)
// Re-use this object, in case webtorrent is changing it
@@ -68,22 +68,22 @@ test('client.add: duplicate trackers (including in .torrent file), multiple torr
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent1 = client.add(parsedTorrentLeaves, opts)
- torrent1.on('ready', function () {
- t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
+ torrent1.on('ready', () => {
+ t.equal(torrent1.magnetURI, `${fixtures.leaves.magnetURI}&tr=${encodeURIComponent('wss://example.com')}`)
const torrent2 = client.add(parsedTorrentAlice, opts)
- torrent2.on('ready', function () {
- t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
+ torrent2.on('ready', () => {
+ t.equal(torrent2.magnetURI, `${fixtures.alice.magnetURI}&tr=${encodeURIComponent('wss://example.com')}`)
- torrent1.destroy(function (err) { t.error(err, 'torrent1 destroyed') })
- torrent2.destroy(function (err) { t.error(err, 'torrent2 destroyed') })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ torrent1.destroy(err => { t.error(err, 'torrent1 destroyed') })
+ torrent2.destroy(err => { t.error(err, 'torrent2 destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
})
diff --git a/test/client-add.js b/test/client-add.js
index 90231fc..84c8fd6 100644
--- a/test/client-add.js
+++ b/test/client-add.js
@@ -2,123 +2,123 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('client.add: magnet uri, utf-8 string', function (t) {
+test('client.add: magnet uri, utf-8 string', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.magnetURI)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.magnetURI, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: torrent file, buffer', function (t) {
+test('client.add: torrent file, buffer', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.torrent)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(fixtures.leaves.torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: info hash, hex string', function (t) {
+test('client.add: info hash, hex string', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- t.equal(torrent.magnetURI, 'magnet:?xt=urn:btih:' + fixtures.leaves.parsedTorrent.infoHash)
+ t.equal(torrent.magnetURI, `magnet:?xt=urn:btih:${fixtures.leaves.parsedTorrent.infoHash}`)
- client.remove(fixtures.leaves.parsedTorrent.infoHash, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.parsedTorrent.infoHash, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: info hash, buffer', function (t) {
+test('client.add: info hash, buffer', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent.infoHashBuffer)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- t.ok(torrent.magnetURI.indexOf('magnet:?xt=urn:btih:' + fixtures.leaves.parsedTorrent.infoHash) === 0)
+ t.ok(torrent.magnetURI.indexOf(`magnet:?xt=urn:btih:${fixtures.leaves.parsedTorrent.infoHash}`) === 0)
- client.remove(Buffer.from(fixtures.leaves.parsedTorrent.infoHash, 'hex'), function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(Buffer.from(fixtures.leaves.parsedTorrent.infoHash, 'hex'), err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: parsed torrent, from `parse-torrent`', function (t) {
+test('client.add: parsed torrent, from `parse-torrent`', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(fixtures.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.parsedTorrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: parsed torrent, with string type announce property', function (t) {
+test('client.add: parsed torrent, with string type announce property', t => {
t.plan(7)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
parsedTorrent.announce = 'http://tracker.local:80'
@@ -126,30 +126,29 @@ test('client.add: parsed torrent, with string type announce property', function
const torrent = client.add(parsedTorrent)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- const expectedMagnetURI = fixtures.leaves.magnetURI +
- '&tr=' + encodeURIComponent('http://tracker.local:80')
+ const expectedMagnetURI = `${fixtures.leaves.magnetURI}&tr=${encodeURIComponent('http://tracker.local:80')}`
t.equal(torrent.magnetURI, expectedMagnetURI)
// `torrent.announce` must always be an array
t.deepEqual(torrent.announce, ['http://tracker.local:80'])
- client.remove(fixtures.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.parsedTorrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: parsed torrent, with array type announce property', function (t) {
+test('client.add: parsed torrent, with array type announce property', t => {
t.plan(7)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
parsedTorrent.announce = ['http://tracker.local:80', 'http://tracker.local:81']
@@ -157,72 +156,70 @@ test('client.add: parsed torrent, with array type announce property', function (
const torrent = client.add(parsedTorrent)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- const expectedMagnetURI = fixtures.leaves.magnetURI +
- '&tr=' + encodeURIComponent('http://tracker.local:80') +
- '&tr=' + encodeURIComponent('http://tracker.local:81')
+ const expectedMagnetURI = `${fixtures.leaves.magnetURI}&tr=${encodeURIComponent('http://tracker.local:80')}&tr=${encodeURIComponent('http://tracker.local:81')}`
t.equal(torrent.magnetURI, expectedMagnetURI)
t.deepEqual(torrent.announce, ['http://tracker.local:80', 'http://tracker.local:81'])
- client.remove(fixtures.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.parsedTorrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: invalid torrent id: empty string', function (t) {
+test('client.add: invalid torrent id: empty string', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) {
+ client.on('error', err => {
t.ok(err instanceof Error)
- t.ok(err.message.indexOf('Invalid torrent identifier') >= 0)
+ t.ok(err.message.includes('Invalid torrent identifier'))
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
- client.on('warning', function (err) { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.add('')
})
-test('client.add: invalid torrent id: short buffer', function (t) {
+test('client.add: invalid torrent id: short buffer', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) {
+ client.on('error', err => {
t.ok(err instanceof Error)
- t.ok(err.message.indexOf('Invalid torrent identifier') >= 0)
+ t.ok(err.message.includes('Invalid torrent identifier'))
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
- client.on('warning', function (err) { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.add(Buffer.from('abc'))
})
-test('client.add: paused torrent', function (t) {
+test('client.add: paused torrent', t => {
t.plan(5)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', (err) => t.fail(err))
- client.on('warning', (err) => t.fail(err))
+ client.on('error', (err) => { t.fail(err) })
+ client.on('warning', (err) => { t.fail(err) })
const torrent = client.add(fixtures.leaves.magnetURI, { paused: true })
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.paused, true)
- client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(fixtures.leaves.magnetURI, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
diff --git a/test/client-destroy.js b/test/client-destroy.js
index b42a25e..9117b8f 100644
--- a/test/client-destroy.js
+++ b/test/client-destroy.js
@@ -2,41 +2,41 @@ 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) {
+test('after client.destroy(), throw on client.add() or client.seed()', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
- t.throws(function () {
- client.add('magnet:?xt=urn:btih:' + fixtures.leaves.parsedTorrent.infoHash)
+ t.throws(() => {
+ client.add(`magnet:?xt=urn:btih:${fixtures.leaves.parsedTorrent.infoHash}`)
})
- t.throws(function () {
+ t.throws(() => {
client.seed(Buffer.from('sup'))
})
})
-test('after client.destroy(), no "torrent" or "ready" events emitted', function (t) {
+test('after client.destroy(), no "torrent" or "ready" events emitted', t => {
t.plan(1)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(fixtures.leaves.torrent, { name: 'leaves' }, function () {
+ client.add(fixtures.leaves.torrent, { name: 'leaves' }, () => {
t.fail('unexpected "torrent" event (from add)')
})
- client.seed(fixtures.leaves.content, { name: 'leaves' }, function () {
+ client.seed(fixtures.leaves.content, { name: 'leaves' }, () => {
t.fail('unexpected "torrent" event (from seed)')
})
- client.on('ready', function () {
+ client.on('ready', () => {
t.fail('unexpected "ready" event')
})
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
diff --git a/test/client-remove.js b/test/client-remove.js
index 6653ec1..659523d 100644
--- a/test/client-remove.js
+++ b/test/client-remove.js
@@ -2,23 +2,23 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('client.remove: remove by Torrent object', function (t) {
+test('client.remove: remove by Torrent object', t => {
t.plan(5)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
diff --git a/test/client-seed.js b/test/client-seed.js
index 3d77b56..d7cf90c 100644
--- a/test/client-seed.js
+++ b/test/client-seed.js
@@ -4,73 +4,73 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('client.seed: torrent file (Buffer)', function (t) {
+test('client.seed: torrent file (Buffer)', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent) {
+ }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent removed') })
+ client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.seed: torrent file (Buffer), set name on buffer', function (t) {
+test('client.seed: torrent file (Buffer), set name on buffer', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const buf = Buffer.from(fixtures.leaves.content)
buf.name = 'Leaves of Grass by Walt Whitman.epub'
- client.seed(buf, { announce: [] }, function (torrent) {
+ client.seed(buf, { announce: [] }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent removed') })
+ client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.seed: torrent file (Blob)', function (t) {
+test('client.seed: torrent file (Blob)', t => {
if (typeof Blob === 'undefined') return t.end()
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(new Blob([fixtures.leaves.content]), {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent) {
+ }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent removed') })
+ client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
diff --git a/test/common.js b/test/common.js
index 6f2ce1e..f11fcb2 100644
--- a/test/common.js
+++ b/test/common.js
@@ -2,7 +2,7 @@ const os = require('os')
const fs = require('fs')
const path = require('path')
-exports.getDownloadPath = function (infix, infoHash) {
+exports.getDownloadPath = (infix, infoHash) => {
let tmpPath
try {
tmpPath = path.join(fs.statSync('/tmp') && '/tmp')
diff --git a/test/duplicate.js b/test/duplicate.js
index 3a9d795..c39102a 100644
--- a/test/duplicate.js
+++ b/test/duplicate.js
@@ -2,30 +2,30 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('client.seed followed by duplicate client.add (sync)', function (t) {
+test('client.seed followed by duplicate client.add (sync)', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent1) {
+ }, torrent1 => {
t.equal(client.torrents.length, 1)
const torrent2 = client.add(torrent1.infoHash)
- torrent2.once('ready', function () {
+ torrent2.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent2.once('error', function (err) {
+ torrent2.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent2.destroyed)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'destroyed client')
t.equal(client.torrents.length, 0)
})
@@ -33,30 +33,30 @@ test('client.seed followed by duplicate client.add (sync)', function (t) {
})
})
-test('client.seed followed by duplicate client.add (async)', function (t) {
+test('client.seed followed by duplicate client.add (async)', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent1) {
+ }, torrent1 => {
t.equal(client.torrents.length, 1)
const torrent2 = client.add(fixtures.leaves.torrentPath)
- torrent2.once('ready', function () {
+ torrent2.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent2.once('error', function (err) {
+ torrent2.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent2.destroyed)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'destroyed client')
t.equal(client.torrents.length, 0)
})
@@ -64,41 +64,41 @@ test('client.seed followed by duplicate client.add (async)', function (t) {
})
})
-test('client.seed followed by two duplicate client.add calls (sync)', function (t) {
+test('client.seed followed by two duplicate client.add calls (sync)', t => {
t.plan(9)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent1) {
+ }, torrent1 => {
t.equal(client.torrents.length, 1)
const torrent2 = client.add(torrent1.infoHash)
- torrent2.once('ready', function () {
+ torrent2.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent2.once('error', function (err) {
+ torrent2.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent2.destroyed)
const torrent3 = client.add(torrent1.infoHash)
- torrent3.once('ready', function () {
+ torrent3.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent3.once('error', function (err) {
+ torrent3.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent3.destroyed)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'destroyed client')
t.equal(client.torrents.length, 0)
})
@@ -107,41 +107,41 @@ 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) {
+test('client.seed followed by two duplicate client.add calls (async)', t => {
t.plan(9)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent1) {
+ }, torrent1 => {
t.equal(client.torrents.length, 1)
const torrent2 = client.add(fixtures.leaves.torrentPath)
- torrent2.once('ready', function () {
+ torrent2.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent2.once('error', function (err) {
+ torrent2.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent2.destroyed)
const torrent3 = client.add(fixtures.leaves.torrentPath)
- torrent3.once('ready', function () {
+ torrent3.once('ready', () => {
t.fail('torrent ready is not called')
})
- torrent3.once('error', function (err) {
+ torrent3.once('error', err => {
t.ok(err, 'got expected error on duplicate add')
t.equal(client.torrents.length, 1)
t.ok(torrent3.destroyed)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'destroyed client')
t.equal(client.torrents.length, 0)
})
@@ -150,24 +150,24 @@ 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) {
+test('successive sync client.add, client.remove, client.add, client.remove (sync)', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent1) {
+ }, torrent1 => {
t.equal(client.torrents.length, 1)
client.add(torrent1.infoHash)
client.remove(torrent1.infoHash)
client.add(torrent1.infoHash)
- client.remove(torrent1.infoHash, function () {
- client.destroy(function (err) {
+ client.remove(torrent1.infoHash, () => {
+ client.destroy(err => {
t.error(err, 'destroyed client')
t.equal(client.torrents.length, 0)
})
diff --git a/test/node/basic.js b/test/node/basic.js
index 963a05c..0dd08ad 100644
--- a/test/node/basic.js
+++ b/test/node/basic.js
@@ -5,123 +5,123 @@ const http = require('http')
const test = require('tape')
const WebTorrent = require('../../')
-test('WebTorrent.WEBRTC_SUPPORT', function (t) {
+test('WebTorrent.WEBRTC_SUPPORT', t => {
t.plan(2)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
t.equal(WebTorrent.WEBRTC_SUPPORT, false)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
-test('client.add: http url to a torrent file, string', function (t) {
+test('client.add: http url to a torrent file, string', t => {
t.plan(8)
- const server = http.createServer(function (req, res) {
- t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
+ const server = http.createServer((req, res) => {
+ t.ok(req.headers['user-agent'].includes('WebTorrent'))
res.end(fixtures.leaves.torrent)
})
- server.listen(0, function () {
+ server.listen(0, () => {
const port = server.address().port
- const url = 'http://127.0.0.1:' + port
+ const url = `http://127.0.0.1:${port}`
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(url, function (torrent) {
+ client.add(url, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- server.close(function () { t.pass('http server closed') })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ server.close(() => { t.pass('http server closed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
})
-test('client.add: filesystem path to a torrent file, string', function (t) {
+test('client.add: filesystem path to a torrent file, string', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(fixtures.leaves.torrentPath, function (torrent) {
+ client.add(fixtures.leaves.torrentPath, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.seed: filesystem path to file, string', function (t) {
+test('client.seed: filesystem path to file, string', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.contentPath, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
- }, function (torrent) {
+ }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.seed: filesystem path to folder with one file, string', function (t) {
+test('client.seed: filesystem path to folder with one file, string', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(fixtures.folder.contentPath, { announce: [] }, function (torrent) {
+ client.seed(fixtures.folder.contentPath, { announce: [] }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.folder.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.folder.magnetURI)
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.seed: filesystem path to folder with multiple files, string', function (t) {
+test('client.seed: filesystem path to folder with multiple files, string', t => {
t.plan(7)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(fixtures.numbers.contentPath, { announce: [] }, function (torrent) {
+ client.seed(fixtures.numbers.contentPath, { announce: [] }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.numbers.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.numbers.magnetURI)
@@ -137,70 +137,70 @@ test('client.seed: filesystem path to folder with multiple files, string', funct
{ length: 3, downloaded: 3 }
], 'expected downloaded to be calculated correctly')
- client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
+ client.remove(torrent, err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
-test('client.add: invalid torrent id: invalid filesystem path', function (t) {
+test('client.add: invalid torrent id: invalid filesystem path', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) {
+ client.on('error', err => {
t.ok(err instanceof Error)
- t.ok(err.message.indexOf('Invalid torrent identifier') >= 0)
+ t.ok(err.message.includes('Invalid torrent identifier'))
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
- client.on('warning', function (err) { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.add('/invalid/filesystem/path/123')
})
-test('client.remove: opts.destroyStore', function (t) {
+test('client.remove: opts.destroyStore', t => {
t.plan(2)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) {
+ client.seed(fixtures.alice.content, { name: 'alice.txt', announce: [] }, torrent => {
const torrentPath = torrent.path
- client.remove(torrent, { destroyStore: true }, function (err) {
+ client.remove(torrent, { destroyStore: true }, err => {
if (err) t.fail(err)
- fs.stat(path.join(torrentPath, 'alice.txt'), function (err) {
+ fs.stat(path.join(torrentPath, 'alice.txt'), err => {
if (err && err.code === 'ENOENT') t.pass('file deleted')
else t.fail('file still exists')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
})
})
-test('torrent.destroy: opts.destroyStore', function (t) {
+test('torrent.destroy: opts.destroyStore', t => {
t.plan(2)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.seed(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) {
+ client.seed(fixtures.alice.content, { name: 'alice.txt', announce: [] }, torrent => {
const torrentPath = torrent.path
- torrent.destroy({ destroyStore: true }, function (err) {
+ torrent.destroy({ destroyStore: true }, err => {
if (err) t.fail(err)
- fs.stat(path.join(torrentPath, 'alice.txt'), function (err) {
+ fs.stat(path.join(torrentPath, 'alice.txt'), err => {
if (err && err.code === 'ENOENT') t.pass('file deleted')
else t.fail('file still exists')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
})
diff --git a/test/node/blocklist-dht.js b/test/node/blocklist-dht.js
index d718d6e..0324b1c 100644
--- a/test/node/blocklist-dht.js
+++ b/test/node/blocklist-dht.js
@@ -5,50 +5,50 @@ const test = require('tape')
const WebTorrent = require('../../')
const common = require('../common')
-test('blocklist blocks peers discovered via DHT', function (t) {
+test('blocklist blocks peers discovered via DHT', t => {
t.plan(8)
let dhtServer, client1, client2
series([
- function (cb) {
+ cb => {
dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
let torrentReady = false
let announced = false
client1 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const torrent1 = client1.add(fixtures.leaves.parsedTorrent, {
path: common.getDownloadPath('client_1', fixtures.leaves.parsedTorrent.infoHash)
})
- torrent1.on('peer', function () {
+ torrent1.on('peer', () => {
t.fail('client1 should not find any peers')
})
- torrent1.on('blockedPeer', function () {
+ torrent1.on('blockedPeer', () => {
t.fail('client1 should not block any peers')
})
- torrent1.on('ready', function () {
+ torrent1.on('ready', () => {
t.pass('torrent1 ready')
torrentReady = true
maybeDone()
})
- torrent1.on('dhtAnnounce', function () {
+ torrent1.on('dhtAnnounce', () => {
t.pass('client1 announced to dht')
announced = true
maybeDone()
@@ -59,33 +59,33 @@ test('blocklist blocks peers discovered via DHT', function (t) {
}
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port },
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` },
blocklist: ['127.0.0.1']
})
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
const torrent2 = client2.add(fixtures.leaves.parsedTorrent, {
path: common.getDownloadPath('client_2', fixtures.leaves.parsedTorrent.infoHash)
})
- torrent2.on('blockedPeer', function (addr) {
- t.pass('client2 blocked connection to client1: ' + addr)
+ torrent2.on('blockedPeer', addr => {
+ t.pass(`client2 blocked connection to client1: ${addr}`)
blockedPeer = true
maybeDone()
})
- torrent2.on('dhtAnnounce', function () {
+ torrent2.on('dhtAnnounce', () => {
t.pass('client2 announced to dht')
announced = true
maybeDone()
})
- torrent2.on('peer', function (addr) {
+ torrent2.on('peer', addr => {
t.fail('client2 should not find any peers')
})
@@ -95,15 +95,15 @@ test('blocklist blocks peers discovered via DHT', function (t) {
}
}
- ], function (err) {
+ ], err => {
t.error(err)
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
})
diff --git a/test/node/blocklist-tracker.js b/test/node/blocklist-tracker.js
index 8633685..ee93d94 100644
--- a/test/node/blocklist-tracker.js
+++ b/test/node/blocklist-tracker.js
@@ -5,19 +5,19 @@ const TrackerServer = require('bittorrent-tracker/server')
const WebTorrent = require('../../')
const common = require('../common')
-test('blocklist blocks peers discovered via tracker', function (t) {
+test('blocklist blocks peers discovered via tracker', t => {
t.plan(9)
const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
let tracker, client1, client2
series([
- function (cb) {
+ cb => {
tracker = new TrackerServer({ udp: false, ws: false })
- tracker.listen(function () {
+ tracker.listen(() => {
const port = tracker.http.address().port
- const announceUrl = 'http://127.0.0.1:' + port + '/announce'
+ const announceUrl = `http://127.0.0.1:${port}/announce`
// Overwrite announce with our local tracker
parsedTorrent.announce = announceUrl
@@ -25,70 +25,70 @@ test('blocklist blocks peers discovered via tracker', function (t) {
cb(null)
})
- tracker.once('start', function () {
+ tracker.once('start', () => {
t.pass('client1 connected to tracker')
- tracker.once('start', function () {
+ tracker.once('start', () => {
t.pass('client2 connected to tracker')
})
})
},
- function (cb) {
+ cb => {
client1 = new WebTorrent({ dht: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const torrent1 = client1.add(parsedTorrent, {
path: common.getDownloadPath('client_1', parsedTorrent.infoHash)
})
- torrent1.on('invalidPeer', function () {
+ torrent1.on('invalidPeer', () => {
t.pass('client1 found itself')
cb(null)
})
- torrent1.on('blockedPeer', function () {
+ torrent1.on('blockedPeer', () => {
t.fail('client1 should not block any peers')
})
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({
dht: false,
lsd: false,
blocklist: ['127.0.0.1']
})
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
const torrent2 = client2.add(parsedTorrent, {
path: common.getDownloadPath('client_2', parsedTorrent.infoHash)
})
- torrent2.once('blockedPeer', function () {
+ torrent2.once('blockedPeer', () => {
t.pass('client2 blocked first peer')
- torrent2.once('blockedPeer', function () {
+ torrent2.once('blockedPeer', () => {
t.pass('client2 blocked second peer')
cb(null)
})
})
- torrent2.on('peer', function () {
+ torrent2.on('peer', () => {
t.fail('client2 should not find any peers')
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- tracker.close(function () {
+ tracker.close(() => {
t.pass('tracker closed')
})
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
})
diff --git a/test/node/blocklist.js b/test/node/blocklist.js
index 4ff686a..8b3ebb0 100644
--- a/test/node/blocklist.js
+++ b/test/node/blocklist.js
@@ -6,20 +6,20 @@ const WebTorrent = require('../../')
const zlib = require('zlib')
function assertBlocked (t, torrent, addr) {
- torrent.once('blockedPeer', function (_addr) {
+ torrent.once('blockedPeer', _addr => {
t.equal(addr, _addr)
})
t.notOk(torrent.addPeer(addr))
}
function assertReachable (t, torrent, addr) {
- torrent.once('peer', function (_addr) {
+ torrent.once('peer', _addr => {
t.equal(addr, _addr)
})
t.ok(torrent.addPeer(addr))
}
-test('blocklist (single IP)', function (t) {
+test('blocklist (single IP)', t => {
t.plan(9)
const client = new WebTorrent({
@@ -28,25 +28,25 @@ test('blocklist (single IP)', function (t) {
lsd: false,
blocklist: ['1.2.3.4']
})
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
// blocklist isn't fully loaded until `ready` event
- client.on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ client.on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, 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')
assertReachable(t, torrent, '1.1.1.1:6969')
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
-test('blocklist (array of IPs)', function (t) {
+test('blocklist (array of IPs)', t => {
t.plan(13)
const client = new WebTorrent({
@@ -55,10 +55,10 @@ test('blocklist (array of IPs)', function (t) {
lsd: false,
blocklist: ['1.2.3.4', '5.6.7.8']
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, 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')
@@ -66,7 +66,7 @@ test('blocklist (array of IPs)', function (t) {
assertReachable(t, torrent, '1.1.1.1:1234')
assertReachable(t, torrent, '1.1.1.1:6969')
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
@@ -112,7 +112,7 @@ function assertList (t, torrent) {
assertReachable(t, torrent, '1.2.2.0:6969')
}
-test('blocklist (array of IP ranges)', function (t) {
+test('blocklist (array of IP ranges)', t => {
t.plan(49)
const client = new WebTorrent({
dht: false,
@@ -123,45 +123,45 @@ test('blocklist (array of IP ranges)', function (t) {
{ start: '5.6.7.0', end: '5.6.7.255' }
]
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
-test('blocklist (http url)', function (t) {
+test('blocklist (http url)', t => {
t.plan(51)
- const server = http.createServer(function (req, res) {
+ const server = http.createServer((req, res) => {
// Check that WebTorrent declares a user agent
- t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
+ t.ok(req.headers['user-agent'].includes('WebTorrent'))
fs.createReadStream(fixtures.blocklist.path).pipe(res)
})
- server.listen(0, function () {
+ server.listen(0, () => {
const port = server.address().port
- const url = 'http://127.0.0.1:' + port
+ const url = `http://127.0.0.1:${port}`
const client = new WebTorrent({
dht: false,
tracker: false,
lsd: false,
blocklist: url
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
- server.close(function () {
+ server.close(() => {
t.pass('server closed')
})
})
@@ -169,11 +169,11 @@ test('blocklist (http url)', function (t) {
})
})
-test('blocklist (http url with gzip encoding)', function (t) {
+test('blocklist (http url with gzip encoding)', t => {
t.plan(51)
- const server = http.createServer(function (req, res) {
+ const server = http.createServer((req, res) => {
// Check that WebTorrent declares a user agent
- t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
+ t.ok(req.headers['user-agent'].includes('WebTorrent'))
res.setHeader('content-encoding', 'gzip')
fs.createReadStream(fixtures.blocklist.path)
@@ -181,24 +181,24 @@ test('blocklist (http url with gzip encoding)', function (t) {
.pipe(res)
})
- server.listen(0, function () {
+ server.listen(0, () => {
const port = server.address().port
- const url = 'http://127.0.0.1:' + port
+ const url = `http://127.0.0.1:${port}`
const client = new WebTorrent({
dht: false,
tracker: false,
lsd: false,
blocklist: url
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
- server.close(function () {
+ server.close(() => {
t.pass('server closed')
})
})
@@ -206,11 +206,11 @@ test('blocklist (http url with gzip encoding)', function (t) {
})
})
-test('blocklist (http url with deflate encoding)', function (t) {
+test('blocklist (http url with deflate encoding)', t => {
t.plan(51)
- const server = http.createServer(function (req, res) {
+ const server = http.createServer((req, res) => {
// Check that WebTorrent declares a user agent
- t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
+ t.ok(req.headers['user-agent'].includes('WebTorrent'))
res.setHeader('content-encoding', 'deflate')
fs.createReadStream(fixtures.blocklist.path)
@@ -218,24 +218,24 @@ test('blocklist (http url with deflate encoding)', function (t) {
.pipe(res)
})
- server.listen(0, function () {
+ server.listen(0, () => {
const port = server.address().port
- const url = 'http://127.0.0.1:' + port
+ const url = `http://127.0.0.1:${port}`
const client = new WebTorrent({
dht: false,
tracker: false,
lsd: false,
blocklist: url
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
- server.close(function () {
+ server.close(() => {
t.pass('server closed')
})
})
@@ -243,7 +243,7 @@ test('blocklist (http url with deflate encoding)', function (t) {
})
})
-test('blocklist (fs path)', function (t) {
+test('blocklist (fs path)', t => {
t.plan(49)
const client = new WebTorrent({
dht: false,
@@ -251,19 +251,19 @@ test('blocklist (fs path)', function (t) {
lsd: false,
blocklist: fixtures.blocklist.path
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
})
-test('blocklist (fs path with gzip)', function (t) {
+test('blocklist (fs path with gzip)', t => {
t.plan(49)
const client = new WebTorrent({
dht: false,
@@ -271,12 +271,12 @@ test('blocklist (fs path with gzip)', function (t) {
lsd: false,
blocklist: fixtures.blocklist.gzipPath
})
- .on('error', function (err) { t.fail(err) })
- .on('warning', function (err) { t.fail(err) })
- .on('ready', function () {
- client.add(fixtures.leaves.parsedTorrent, function (torrent) {
+ .on('error', err => { t.fail(err) })
+ .on('warning', err => { t.fail(err) })
+ .on('ready', () => {
+ client.add(fixtures.leaves.parsedTorrent, torrent => {
assertList(t, torrent)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
diff --git a/test/node/conn-pool.js b/test/node/conn-pool.js
index b77a917..1127501 100644
--- a/test/node/conn-pool.js
+++ b/test/node/conn-pool.js
@@ -4,17 +4,17 @@ const WebTorrent = require('../../')
const MemoryChunkStore = require('memory-chunk-store')
const dgram = require('dgram')
-test('client.conn-pool: use TCP when uTP disabled', function (t) {
+test('client.conn-pool: use TCP when uTP disabled', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -22,47 +22,47 @@ test('client.conn-pool: use TCP when uTP disabled', function (t) {
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('127.0.0.1:' + client2.address().port)
+ torrent.addPeer(`127.0.0.1:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
})
-test('client.conn-pool: use uTP when uTP enabled', function (t) {
+test('client.conn-pool: use uTP when uTP enabled', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -70,47 +70,47 @@ test('client.conn-pool: use uTP when uTP enabled', function (t) {
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('127.0.0.1:' + client2.address().port)
+ torrent.addPeer(`127.0.0.1:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
})
-test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP', function (t) {
+test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -118,38 +118,38 @@ test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('[::1]:' + client2.address().port)
+ torrent.addPeer(`[::1]:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
})
// Warning: slow test as we need to rely on connection timeouts
-test('client.conn-pool: fallback to TCP when uTP server failed', function (t) {
+test('client.conn-pool: fallback to TCP when uTP server failed', t => {
t.plan(6)
// force uTP server failure
@@ -159,11 +159,11 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) {
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true, torrentPort: 63000 })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -171,32 +171,32 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) {
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('127.0.0.1:' + client2.address().port)
+ torrent.addPeer(`127.0.0.1:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
server.close()
})
@@ -204,17 +204,17 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) {
})
// Warning: slow test as we need to rely on connection timeouts
-test('client.conn-pool: fallback to TCP when remote client has uTP disabled', function (t) {
+test('client.conn-pool: fallback to TCP when remote client has uTP disabled', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -222,32 +222,32 @@ test('client.conn-pool: fallback to TCP when remote client has uTP disabled', fu
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('127.0.0.1:' + client2.address().port)
+ torrent.addPeer(`127.0.0.1:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
})
diff --git a/test/node/download-dht-magnet.js b/test/node/download-dht-magnet.js
index 199d5bc..874b68a 100644
--- a/test/node/download-dht-magnet.js
+++ b/test/node/download-dht-magnet.js
@@ -7,55 +7,55 @@ const series = require('run-series')
const test = require('tape')
const WebTorrent = require('../../')
-test('Download using DHT (via magnet uri)', function (t) {
+test('Download using DHT (via magnet uri)', t => {
t.plan(12)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client1, client2
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
let announced = false
let loaded = false
client1 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port, host: networkAddress.ipv4() }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}`, host: networkAddress.ipv4() }
})
- client1.dht.on('listening', function () {
+ client1.dht.on('listening', () => {
t.equal(client1.dhtPort, client1.dht.address().port)
})
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.pass('finished dht announce')
announced = true
maybeDone()
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, '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)
+ t.deepEqual(torrent.files.map(file => file.name), names)
})
- torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.leaves.contentPath), err => {
t.error(err)
loaded = true
maybeDone()
@@ -66,21 +66,21 @@ test('Download using DHT (via magnet uri)', function (t) {
}
},
- function (cb) {
+ cb => {
let gotBuffer = false
let gotDone = false
client2 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port, host: networkAddress.ipv4() }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}`, host: networkAddress.ipv4() }
})
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- client2.on('torrent', function (torrent) {
- torrent.files[0].getBuffer(function (err, buf) {
+ client2.on('torrent', torrent => {
+ torrent.files[0].getBuffer((err, buf) => {
t.error(err)
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
@@ -88,7 +88,7 @@ test('Download using DHT (via magnet uri)', function (t) {
maybeDone()
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
gotDone = true
@@ -102,16 +102,16 @@ test('Download using DHT (via magnet uri)', function (t) {
if (gotBuffer && gotDone) cb(null)
}
}
- ], function (err) {
+ ], err => {
t.error(err)
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
})
diff --git a/test/node/download-dht-torrent.js b/test/node/download-dht-torrent.js
index 8ecbbed..9392f52 100644
--- a/test/node/download-dht-torrent.js
+++ b/test/node/download-dht-torrent.js
@@ -6,22 +6,22 @@ const series = require('run-series')
const test = require('tape')
const WebTorrent = require('../../')
-test('Download using DHT (via .torrent file)', function (t) {
+test('Download using DHT (via .torrent file)', t => {
t.plan(10)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client1, client2
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
let announced = false
let loaded = false
let noPeersFound = false
@@ -29,37 +29,37 @@ test('Download using DHT (via .torrent file)', function (t) {
client1 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client1.dht.on('listening', function () {
+ client1.dht.on('listening', () => {
t.equal(client1.dhtPort, client1.dht.address().port)
})
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, '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)
+ t.deepEqual(torrent.files.map(file => file.name), names)
})
- torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.leaves.contentPath), err => {
loaded = true
maybeDone(err)
})
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
announced = true
maybeDone(null)
})
- torrent.on('noPeers', function (announceType) {
+ torrent.on('noPeers', announceType => {
t.equal(announceType, 'dht', 'noPeers event seen with correct announceType')
noPeersFound = true
maybeDone(null)
@@ -70,22 +70,22 @@ test('Download using DHT (via .torrent file)', function (t) {
}
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- client2.on('torrent', function (torrent) {
+ client2.on('torrent', torrent => {
let torrentDone = false
let gotBuffer = false
- torrent.files.forEach(function (file) {
- file.getBuffer(function (err, buf) {
+ torrent.files.forEach(file => {
+ file.getBuffer((err, buf) => {
if (err) throw err
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
gotBuffer = true
@@ -93,7 +93,7 @@ test('Download using DHT (via .torrent file)', function (t) {
})
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
torrentDone = true
maybeDone()
@@ -106,16 +106,16 @@ test('Download using DHT (via .torrent file)', function (t) {
client2.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
}
- ], function (err) {
+ ], err => {
t.error(err)
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
})
diff --git a/test/node/download-from-ip.js b/test/node/download-from-ip.js
index 5905473..84669a9 100644
--- a/test/node/download-from-ip.js
+++ b/test/node/download-from-ip.js
@@ -16,12 +16,12 @@ test('Download via torrent.addPeer()', (t) => {
const torrent = seeder.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, '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)
+ t.deepEqual(torrent.files.map(file => file.name), names)
})
torrent.load(fs.createReadStream(fixtures.leaves.contentPath), (err) => {
@@ -31,13 +31,13 @@ test('Download via torrent.addPeer()', (t) => {
const downloader = new WebTorrent({ tracker: false, dht: false, lsd: false })
- downloader.on('error', function (err) { t.fail(err) })
- downloader.on('warning', function (err) { t.fail(err) })
+ downloader.on('error', err => { t.fail(err) })
+ downloader.on('warning', err => { t.fail(err) })
downloader.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore }, (torrent) => {
torrent.addPeer(`localhost:${seeder.torrentPort}`)
- torrent.once('done', function () {
+ torrent.once('done', () => {
torrent.files.forEach((file) => {
file.getBuffer((err, buf) => {
t.error(err)
@@ -65,12 +65,12 @@ test('Download via magnet x.pe (BEP09)', (t) => {
const torrent = seeder.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, '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)
+ t.deepEqual(torrent.files.map(file => file.name), names)
})
torrent.load(fs.createReadStream(fixtures.leaves.contentPath), (err) => {
@@ -80,15 +80,15 @@ test('Download via magnet x.pe (BEP09)', (t) => {
const downloader = new WebTorrent({ tracker: false, dht: false, lsd: false })
- downloader.on('error', function (err) { t.fail(err) })
- downloader.on('warning', function (err) { t.fail(err) })
+ downloader.on('error', err => { t.fail(err) })
+ downloader.on('warning', err => { t.fail(err) })
// add x.pe to the magnet
const peerAddress = '127.0.0.1:63000'
const magnetURI = fixtures.leaves.magnetURI + `&x.pe=${peerAddress}`
downloader.add(magnetURI, { store: MemoryChunkStore }, (torrent) => {
- torrent.once('done', function () {
+ torrent.once('done', () => {
torrent.files.forEach((file) => {
file.getBuffer((err, buf) => {
t.error(err)
diff --git a/test/node/download-lsd-magnet.js b/test/node/download-lsd-magnet.js
index a3b956e..f7dac6b 100644
--- a/test/node/download-lsd-magnet.js
+++ b/test/node/download-lsd-magnet.js
@@ -3,17 +3,17 @@ const MemoryChunkStore = require('memory-chunk-store')
const test = require('tape')
const WebTorrent = require('../../')
-test('Download using LSD (via magnet uri)', function (t) {
+test('Download using LSD (via magnet uri)', t => {
t.plan(3)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: true })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: true })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
const torrent = client1.add(fixtures.leaves.magnetURI, { store: MemoryChunkStore })
@@ -22,10 +22,10 @@ test('Download using LSD (via magnet uri)', function (t) {
announce: []
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.pass()
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
diff --git a/test/node/download-lsd-torrent.js b/test/node/download-lsd-torrent.js
index 719a491..8837140 100644
--- a/test/node/download-lsd-torrent.js
+++ b/test/node/download-lsd-torrent.js
@@ -3,31 +3,31 @@ const MemoryChunkStore = require('memory-chunk-store')
const test = require('tape')
const WebTorrent = require('../../')
-test('Download using LSD (via .torrent file)', function (t) {
+test('Download using LSD (via .torrent file)', t => {
t.plan(3)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: true })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: true })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- client1.on('torrent', function () {
+ client1.on('torrent', () => {
client2.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
})
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.pass()
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
diff --git a/test/node/download-metadata.js b/test/node/download-metadata.js
index 4932a53..4d7e698 100644
--- a/test/node/download-metadata.js
+++ b/test/node/download-metadata.js
@@ -5,7 +5,7 @@ const test = require('tape')
const WebTorrent = require('../../')
function createServer (data, cb) {
- const server = http.createServer(function (req, res) {
+ const server = http.createServer((req, res) => {
if (req.url !== '/') {
res.statusCode = 404
res.end()
@@ -14,113 +14,113 @@ function createServer (data, cb) {
}
})
- server.on('listening', function () {
+ server.on('listening', () => {
const address = server.address()
- const url = 'http://127.0.0.1:' + address.port + '/'
+ const url = `http://127.0.0.1:${address.port}/`
cb(url, server)
})
server.listen()
}
-test('Download metadata for magnet URI with xs parameter', function (t) {
+test('Download metadata for magnet URI with xs parameter', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url, server) {
+ createServer(fixtures.leaves.torrent, (url, server) => {
const encodedUrl = encodeURIComponent(url)
- client.add(fixtures.leaves.magnetURI + '&xs=' + encodedUrl, { store: MemoryChunkStore }, function (torrent) {
+ client.add(`${fixtures.leaves.magnetURI}&xs=${encodedUrl}`, { store: MemoryChunkStore }, torrent => {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
- server.close(function () { t.pass('server closed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
+ server.close(() => { t.pass('server closed') })
})
})
})
-test('Download metadata for magnet URI with 2 xs parameters', function (t) {
+test('Download metadata for magnet URI with 2 xs parameters', t => {
t.plan(4)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url1, server1) {
+ createServer(fixtures.leaves.torrent, (url1, server1) => {
const encodedUrl1 = encodeURIComponent(url1)
- createServer(fixtures.leaves.torrent, function (url2, server2) {
+ createServer(fixtures.leaves.torrent, (url2, server2) => {
const encodedUrl2 = encodeURIComponent(url2)
- const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
+ const uri = `${fixtures.leaves.magnetURI}&xs=${encodedUrl1}&xs=${encodedUrl2}`
- client.add(uri, { store: MemoryChunkStore }, function (torrent) {
+ client.add(uri, { store: MemoryChunkStore }, torrent => {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
- server1.close(function () { t.pass('server closed') })
- server2.close(function () { t.pass('server closed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
+ server1.close(() => { t.pass('server closed') })
+ server2.close(() => { t.pass('server closed') })
})
})
})
})
-test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid protocol', function (t) {
+test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid protocol', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url, server) {
+ createServer(fixtures.leaves.torrent, (url, server) => {
const encodedUrl1 = encodeURIComponent('invalidurl:example')
const encodedUrl2 = encodeURIComponent(url)
- const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
+ const uri = `${fixtures.leaves.magnetURI}&xs=${encodedUrl1}&xs=${encodedUrl2}`
- client.add(uri, { store: MemoryChunkStore }, function (torrent) {
+ client.add(uri, { store: MemoryChunkStore }, torrent => {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
- server.close(function () { t.pass('server closed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
+ server.close(() => { t.pass('server closed') })
})
})
})
-test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', function (t) {
+test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', t => {
t.plan(3)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url, server) {
- const encodedUrl1 = encodeURIComponent(url + 'blah_404')
+ createServer(fixtures.leaves.torrent, (url, server) => {
+ const encodedUrl1 = encodeURIComponent(`${url}blah_404`)
const encodedUrl2 = encodeURIComponent(url)
- const uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
+ const uri = `${fixtures.leaves.magnetURI}&xs=${encodedUrl1}&xs=${encodedUrl2}`
- client.add(uri, { store: MemoryChunkStore }, function (torrent) {
+ client.add(uri, { store: MemoryChunkStore }, torrent => {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
- client.destroy(function (err) { t.error(err, 'client destroyed') })
- server.close(function () { t.pass('server closed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
+ server.close(() => { t.pass('server closed') })
})
})
})
-test('Download metadata magnet URI with unsupported protocol in xs parameter', function (t) {
+test('Download metadata magnet URI with unsupported protocol in xs parameter', t => {
t.plan(1)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'), { store: MemoryChunkStore })
+ client.add(`${fixtures.leaves.magnetURI}&xs=${encodeURIComponent('invalidurl:example')}`, { store: MemoryChunkStore })
- setTimeout(function () {
+ setTimeout(() => {
// no crash by now
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
}, 100)
})
diff --git a/test/node/download-private-dht.js b/test/node/download-private-dht.js
index 036c889..04a2c7d 100644
--- a/test/node/download-private-dht.js
+++ b/test/node/download-private-dht.js
@@ -5,207 +5,207 @@ const series = require('run-series')
const test = require('tape')
const WebTorrent = require('../../')
-test('private torrent should not use DHT', function (t) {
+test('private torrent should not use DHT', t => {
t.plan(4)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
client = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.bunny.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.fail('client announced to dht')
})
- client.on('torrent', function () {
+ client.on('torrent', () => {
if (!torrent.discovery.dht) {
t.pass('dht is disabled for this torrent')
cb(null)
}
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
-test('public torrent should use DHT', function (t) {
+test('public torrent should use DHT', t => {
t.plan(4)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
client = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.pass('client announced to dht')
cb(null)
})
- client.on('torrent', function () {
+ client.on('torrent', () => {
if (!torrent.client.dht) {
t.fail('dht server is null')
}
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
-test('public torrent with forced private option should not use DHT', function (t) {
+test('public torrent with forced private option should not use DHT', t => {
t.plan(4)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
client = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent, {
private: true,
store: MemoryChunkStore
})
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.fail('client announced to dht')
})
- client.on('torrent', function () {
+ client.on('torrent', () => {
if (!torrent.discovery.dht) {
t.pass('dht is disabled for this torrent')
cb(null)
}
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
})
-test('private torrent with forced public option should use DHT', function (t) {
+test('private torrent with forced public option should use DHT', t => {
t.plan(4)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
client = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.bunny.parsedTorrent, {
private: false,
store: MemoryChunkStore
})
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.pass('client announced to dht')
cb(null)
})
- client.on('torrent', function () {
+ client.on('torrent', () => {
if (!torrent.client.dht) {
t.fail('dht server is null')
}
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
diff --git a/test/node/download-tracker-magnet.js b/test/node/download-tracker-magnet.js
index 4e13e6a..f4d750a 100644
--- a/test/node/download-tracker-magnet.js
+++ b/test/node/download-tracker-magnet.js
@@ -6,11 +6,11 @@ const test = require('tape')
const TrackerServer = require('bittorrent-tracker/server')
const WebTorrent = require('../../')
-test('Download using UDP tracker (via magnet uri)', function (t) {
+test('Download using UDP tracker (via magnet uri)', t => {
magnetDownloadTest(t, 'udp')
})
-test('Download using HTTP tracker (via magnet uri)', function (t) {
+test('Download using HTTP tracker (via magnet uri)', t => {
magnetDownloadTest(t, 'http')
})
@@ -21,11 +21,11 @@ function magnetDownloadTest (t, serverType) {
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) })
+ tracker.on('error', err => { t.fail(err) })
+ tracker.on('warning', err => { t.fail(err) })
let trackerStartCount = 0
- tracker.on('start', function () {
+ tracker.on('start', () => {
trackerStartCount += 1
})
@@ -33,25 +33,25 @@ function magnetDownloadTest (t, serverType) {
let magnetURI, client1, client2
series([
- function (cb) {
+ cb => {
tracker.listen(cb)
},
- function (cb) {
+ cb => {
const port = tracker[serverType].address().port
const announceUrl = serverType === 'http'
- ? 'http://127.0.0.1:' + port + '/announce'
- : 'udp://127.0.0.1:' + port
+ ? `http://127.0.0.1:${port}/announce`
+ : `udp://127.0.0.1:${port}`
parsedTorrent.announce = [announceUrl]
- magnetURI = 'magnet:?xt=urn:btih:' + parsedTorrent.infoHash + '&tr=' + encodeURIComponent(announceUrl)
+ magnetURI = `magnet:?xt=urn:btih:${parsedTorrent.infoHash}&tr=${encodeURIComponent(announceUrl)}`
client1 = new WebTorrent({ dht: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client1.on('torrent', function (torrent) {
+ client1.on('torrent', torrent => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')
@@ -59,13 +59,13 @@ function magnetDownloadTest (t, serverType) {
'Leaves of Grass by Walt Whitman.epub'
]
- torrent.once('noPeers', function (announceType) {
+ torrent.once('noPeers', announceType => {
t.equal(announceType, 'tracker', 'noPeers event seen with correct announceType')
})
- t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
+ t.deepEqual(torrent.files.map(file => file.name), names)
- torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.leaves.contentPath), err => {
cb(err)
})
})
@@ -73,18 +73,18 @@ function magnetDownloadTest (t, serverType) {
client1.add(parsedTorrent, { store: MemoryChunkStore })
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({ dht: false, lsd: false })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- client2.on('torrent', function (torrent) {
+ client2.on('torrent', torrent => {
let gotBuffer = false
let torrentDone = false
- torrent.files.forEach(function (file) {
- file.getBuffer(function (err, buf) {
+ torrent.files.forEach(file => {
+ file.getBuffer((err, buf) => {
if (err) throw err
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
gotBuffer = true
@@ -92,7 +92,7 @@ function magnetDownloadTest (t, serverType) {
})
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
torrentDone = true
maybeDone()
@@ -106,18 +106,18 @@ function magnetDownloadTest (t, serverType) {
client2.add(magnetURI, { store: MemoryChunkStore })
}
- ], function (err) {
+ ], err => {
t.error(err)
t.equal(trackerStartCount, 2)
- tracker.close(function () {
+ tracker.close(() => {
t.pass('tracker closed')
})
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
})
diff --git a/test/node/download-tracker-torrent.js b/test/node/download-tracker-torrent.js
index c1d3bcd..9ba0760 100644
--- a/test/node/download-tracker-torrent.js
+++ b/test/node/download-tracker-torrent.js
@@ -6,11 +6,11 @@ const test = require('tape')
const TrackerServer = require('bittorrent-tracker/server')
const WebTorrent = require('../../')
-test('Download using UDP tracker (via .torrent file)', function (t) {
+test('Download using UDP tracker (via .torrent file)', t => {
torrentDownloadTest(t, 'udp')
})
-test('Download using HTTP tracker (via .torrent file)', function (t) {
+test('Download using HTTP tracker (via .torrent file)', t => {
torrentDownloadTest(t, 'http')
})
@@ -24,35 +24,35 @@ function torrentDownloadTest (t, serverType) {
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) })
+ tracker.on('error', err => { t.fail(err) })
+ tracker.on('warning', err => { t.fail(err) })
- tracker.on('start', function () {
+ tracker.on('start', () => {
trackerStartCount += 1
})
let client1, client2
series([
- function (cb) {
+ cb => {
tracker.listen(cb)
},
- function (cb) {
+ cb => {
client1 = new WebTorrent({ dht: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const port = tracker[serverType].address().port
const announceUrl = serverType === 'http'
- ? 'http://127.0.0.1:' + port + '/announce'
- : 'udp://127.0.0.1:' + port
+ ? `http://127.0.0.1:${port}/announce`
+ : `udp://127.0.0.1:${port}`
// Overwrite announce with our local tracker
parsedTorrent.announce = [announceUrl]
- client1.on('torrent', function (torrent) {
+ client1.on('torrent', torrent => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')
@@ -60,7 +60,7 @@ function torrentDownloadTest (t, serverType) {
'Leaves of Grass by Walt Whitman.epub'
]
- t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
+ t.deepEqual(torrent.files.map(file => file.name), names)
torrent.load(fs.createReadStream(fixtures.leaves.contentPath), cb)
})
@@ -68,19 +68,19 @@ function torrentDownloadTest (t, serverType) {
client1.add(parsedTorrent, { store: MemoryChunkStore })
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({ dht: false, lsd: false })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
client2.add(parsedTorrent, { store: MemoryChunkStore })
- client2.on('torrent', function (torrent) {
+ client2.on('torrent', torrent => {
let gotBuffer = false
let torrentDone = false
- torrent.files.forEach(function (file) {
- file.getBuffer(function (err, buf) {
+ torrent.files.forEach(file => {
+ file.getBuffer((err, buf) => {
if (err) throw err
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
gotBuffer = true
@@ -88,7 +88,7 @@ function torrentDownloadTest (t, serverType) {
})
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
torrentDone = true
maybeDone()
@@ -100,17 +100,17 @@ function torrentDownloadTest (t, serverType) {
})
}
- ], function (err) {
+ ], err => {
t.error(err)
t.equal(trackerStartCount, 2)
- tracker.close(function () {
+ tracker.close(() => {
t.pass('tracker closed')
})
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
})
diff --git a/test/node/download-webseed-magnet.js b/test/node/download-webseed-magnet.js
index 4963cf2..8e7503b 100644
--- a/test/node/download-webseed-magnet.js
+++ b/test/node/download-webseed-magnet.js
@@ -8,28 +8,28 @@ const serveStatic = require('serve-static')
const test = require('tape')
const WebTorrent = require('../../')
-test('Download using webseed (via magnet uri)', function (t) {
+test('Download using webseed (via magnet uri)', t => {
t.plan(9)
const serve = serveStatic(path.dirname(fixtures.leaves.contentPath))
- const httpServer = http.createServer(function (req, res) {
+ const httpServer = http.createServer((req, res) => {
const done = finalhandler(req, res)
serve(req, res, done)
})
let client1, client2
- httpServer.on('error', function (err) { t.fail(err) })
+ httpServer.on('error', err => { t.fail(err) })
series([
- function (cb) {
+ cb => {
httpServer.listen(cb)
},
- function (cb) {
+ cb => {
client1 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
let gotTorrent = false
let gotListening = false
@@ -37,7 +37,7 @@ test('Download using webseed (via magnet uri)', function (t) {
if (gotTorrent && gotListening) cb(null)
}
- client1.on('torrent', function (torrent) {
+ client1.on('torrent', torrent => {
// torrent metadata has been fetched -- sanity check it
t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')
@@ -45,7 +45,7 @@ test('Download using webseed (via magnet uri)', function (t) {
'Leaves of Grass by Walt Whitman.epub'
]
- t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
+ t.deepEqual(torrent.files.map(file => file.name), names)
// NOTE: client1 is *NOT* a seeder. Just has the metadata.
gotTorrent = true
@@ -54,27 +54,27 @@ test('Download using webseed (via magnet uri)', function (t) {
const torrent = client1.add(fixtures.leaves.parsedTorrent, { store: MemoryChunkStore })
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
gotListening = true
maybeDone()
})
},
- function (cb) {
+ cb => {
client2 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- const webSeedUrl = 'http://localhost:' + httpServer.address().port + '/' + fixtures.leaves.parsedTorrent.name
- const 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) {
+ client2.on('torrent', torrent => {
let gotBuffer = false
let torrentDone = false
- torrent.files.forEach(function (file) {
- file.getBuffer(function (err, buf) {
+ torrent.files.forEach(file => {
+ file.getBuffer((err, buf) => {
t.error(err)
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
gotBuffer = true
@@ -82,7 +82,7 @@ test('Download using webseed (via magnet uri)', function (t) {
})
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
torrentDone = true
maybeDone()
@@ -95,19 +95,19 @@ test('Download using webseed (via magnet uri)', function (t) {
const torrent = client2.add(magnetURI, { store: MemoryChunkStore })
- torrent.on('infoHash', function () {
- torrent.addPeer('127.0.0.1:' + client1.address().port)
+ torrent.on('infoHash', () => {
+ torrent.addPeer(`127.0.0.1:${client1.address().port}`)
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client destroyed')
})
- httpServer.close(function () {
+ httpServer.close(() => {
t.pass('http server closed')
})
})
diff --git a/test/node/download-webseed-torrent.js b/test/node/download-webseed-torrent.js
index 0fafed0..43bff79 100644
--- a/test/node/download-webseed-torrent.js
+++ b/test/node/download-webseed-torrent.js
@@ -11,41 +11,41 @@ const WebTorrent = require('../../')
// it should be fast to download a small torrent over local HTTP
const WEB_SEED_TIMEOUT_MS = 500
-test('Download using webseed (via .torrent file)', function (t) {
+test('Download using webseed (via .torrent file)', t => {
t.plan(6)
t.timeoutAfter(WEB_SEED_TIMEOUT_MS)
const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
- const httpServer = http.createServer(function (req, res) {
+ const httpServer = http.createServer((req, res) => {
const done = finalhandler(req, res)
serveStatic(path.dirname(fixtures.leaves.contentPath))(req, res, done)
})
let client
- httpServer.on('error', function (err) { t.fail(err) })
+ httpServer.on('error', err => { t.fail(err) })
series([
- function (cb) {
+ cb => {
httpServer.listen(cb)
},
- function (cb) {
+ cb => {
parsedTorrent.urlList = [
- 'http://localhost:' + httpServer.address().port + '/' + fixtures.leaves.parsedTorrent.name
+ `http://localhost:${httpServer.address().port}/${fixtures.leaves.parsedTorrent.name}`
]
client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.on('torrent', function (torrent) {
+ client.on('torrent', torrent => {
let gotBuffer = false
let torrentDone = false
- torrent.files.forEach(function (file) {
- file.getBuffer(function (err, buf) {
+ torrent.files.forEach(file => {
+ file.getBuffer((err, buf) => {
t.error(err)
t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
gotBuffer = true
@@ -53,7 +53,7 @@ test('Download using webseed (via .torrent file)', function (t) {
})
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client downloaded torrent from webseed')
torrentDone = true
maybeDone()
@@ -66,42 +66,42 @@ test('Download using webseed (via .torrent file)', function (t) {
client.add(parsedTorrent, { store: MemoryChunkStore })
}
- ], function (err) {
+ ], err => {
t.error(err)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
- httpServer.close(function () {
+ httpServer.close(() => {
t.pass('http server closed')
})
})
})
-test('Disable webseeds', function (t) {
+test('Disable webseeds', t => {
t.plan(3)
const parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
- const httpServer = http.createServer(function (req, res) {
+ const httpServer = http.createServer((req, res) => {
t.fail('webseed http server should not get any requests')
})
let client
- httpServer.on('error', function (err) { t.fail(err) })
+ httpServer.on('error', err => { t.fail(err) })
series([
- function (cb) {
+ cb => {
httpServer.listen(cb)
},
- function (cb) {
+ cb => {
parsedTorrent.urlList = [
- 'http://localhost:' + httpServer.address().port + '/' + fixtures.leaves.parsedTorrent.name
+ `http://localhost:${httpServer.address().port}/${fixtures.leaves.parsedTorrent.name}`
]
client = new WebTorrent({ dht: false, tracker: false, lsd: false, webSeeds: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
client.add(parsedTorrent, { store: MemoryChunkStore })
@@ -109,12 +109,12 @@ test('Disable webseeds', function (t) {
// short time. Here, we wait the same amount of time and make sure no HTTP requests happen.
setTimeout(cb, WEB_SEED_TIMEOUT_MS)
}
- ], function (err) {
+ ], err => {
t.error(err)
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
- httpServer.close(function () {
+ httpServer.close(() => {
t.pass('http server closed')
})
})
diff --git a/test/node/extensions.js b/test/node/extensions.js
index 35b4ac9..48b1dfd 100644
--- a/test/node/extensions.js
+++ b/test/node/extensions.js
@@ -2,55 +2,58 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../../')
-test('extension support', function (t) {
+test('extension support', t => {
t.plan(6)
let extendedHandshakes = 0
- function Extension (wire) {
- wire.extendedHandshake.test = 'Hello, World!'
- }
+ class Extension {
+ constructor (wire) {
+ wire.extendedHandshake.test = 'Hello, World!'
+ }
- Extension.prototype.name = 'wt_test'
- Extension.prototype.onExtendedHandshake = function (extendedHandshake) {
- extendedHandshakes += 1
-
- t.equal(
- extendedHandshake.test.toString(), 'Hello, World!',
- 'handshake.test === Hello, World!'
- )
-
- if (extendedHandshakes === 2) {
- client1.destroy(function (err) {
- t.error(err, 'client1 destroyed')
- })
- client2.destroy(function (err) {
- t.error(err, 'client2 destroyed')
- })
+ onExtendedHandshake (extendedHandshake) {
+ extendedHandshakes += 1
+
+ t.equal(
+ extendedHandshake.test.toString(), 'Hello, World!',
+ 'handshake.test === Hello, World!'
+ )
+
+ if (extendedHandshakes === 2) {
+ client1.destroy(err => {
+ t.error(err, 'client1 destroyed')
+ })
+ client2.destroy(err => {
+ t.error(err, 'client2 destroyed')
+ })
+ }
}
}
+ Extension.prototype.name = 'wt_test'
+
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- client1.add(fixtures.leaves.parsedTorrent, function (torrent1) {
- torrent1.on('wire', function (wire) {
+ client1.add(fixtures.leaves.parsedTorrent, torrent1 => {
+ torrent1.on('wire', wire => {
t.pass('client1 onWire')
wire.use(Extension)
})
const torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash)
- torrent2.on('wire', function (wire) {
+ torrent2.on('wire', wire => {
t.pass('client2 onWire')
wire.use(Extension)
})
- torrent2.on('infoHash', function () {
- torrent2.addPeer('127.0.0.1:' + client1.address().port)
+ torrent2.on('infoHash', () => {
+ torrent2.addPeer(`127.0.0.1:${client1.address().port}`)
})
})
})
diff --git a/test/node/metadata.js b/test/node/metadata.js
index 106586d..3048f8b 100644
--- a/test/node/metadata.js
+++ b/test/node/metadata.js
@@ -2,19 +2,19 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../../')
-test('ut_metadata transfer', function (t) {
+test('ut_metadata transfer', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
- client1.on('torrent', function (torrent) {
+ client1.on('torrent', torrent => {
t.pass('client1 emits torrent event') // even though it started with metadata
t.ok(torrent.metadata, 'metadata exists')
})
@@ -22,23 +22,23 @@ test('ut_metadata transfer', function (t) {
// client1 starts with metadata from torrent file
client1.add(fixtures.leaves.torrent)
- client1.on('torrent', function (torrent1) {
+ client1.on('torrent', torrent1 => {
t.deepEqual(torrent1.info, fixtures.leaves.parsedTorrent.info)
// client2 starts with infohash
const torrent2 = client2.add(fixtures.leaves.parsedTorrent.infoHash)
- torrent2.on('infoHash', function () {
+ torrent2.on('infoHash', () => {
// manually add the peer
- torrent2.addPeer('127.0.0.1:' + client1.address().port)
+ torrent2.addPeer(`127.0.0.1:${client1.address().port}`)
- client2.on('torrent', function () {
+ client2.on('torrent', () => {
t.deepEqual(torrent1.info, torrent2.info)
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
})
diff --git a/test/node/seed-stream.js b/test/node/seed-stream.js
index fda91d7..0e0db73 100644
--- a/test/node/seed-stream.js
+++ b/test/node/seed-stream.js
@@ -4,32 +4,32 @@ const test = require('tape')
const Tracker = require('bittorrent-tracker/server')
const WebTorrent = require('../../')
-test('client.seed: stream', function (t) {
+test('client.seed: stream', t => {
t.plan(9)
const tracker = new Tracker({ udp: false, ws: false })
- tracker.on('error', function (err) { t.fail(err) })
- tracker.on('warning', function (err) { t.fail(err) })
+ tracker.on('error', err => { t.fail(err) })
+ tracker.on('warning', err => { t.fail(err) })
let seeder, client, announceUrl, magnetURI
series([
- function (cb) {
+ cb => {
tracker.listen(cb)
},
- function (cb) {
+ cb => {
const port = tracker.http.address().port
- announceUrl = 'http://localhost:' + port + '/announce'
+ announceUrl = `http://localhost:${port}/announce`
seeder = new WebTorrent({ dht: false, lsd: false })
- seeder.on('error', function (err) { t.fail(err) })
- seeder.on('warning', function (err) { t.fail(err) })
+ seeder.on('error', err => { t.fail(err) })
+ seeder.on('warning', err => { t.fail(err) })
const stream = new Readable()
- stream._read = function () {}
+ stream._read = () => {}
stream.push('HELLO WORLD\n')
stream.push(null)
@@ -38,23 +38,23 @@ test('client.seed: stream', function (t) {
pieceLength: 5,
announce: [announceUrl]
}
- seeder.seed([stream], seederOpts, function (torrent) {
+ seeder.seed([stream], seederOpts, torrent => {
magnetURI = torrent.magnetURI
cb(null)
})
},
- function (cb) {
+ cb => {
client = new WebTorrent({ dht: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(magnetURI, function (dl) {
+ client.add(magnetURI, dl => {
t.equal(dl.files.length, 1)
t.equal(dl.files[0].name, 'hello.txt')
t.equal(dl.files[0].length, 12)
- dl.files[0].getBuffer(function (err, buf) {
+ dl.files[0].getBuffer((err, buf) => {
t.error(err)
t.equal(buf.toString('utf8'), 'HELLO WORLD\n', 'content')
@@ -62,10 +62,10 @@ test('client.seed: stream', function (t) {
})
})
}
- ], function (err) {
+ ], err => {
t.error(err)
- seeder.destroy(function (err) { t.error(err, 'seeder destroyed') })
- client.destroy(function (err) { t.error(err, 'client destroyed') })
- tracker.close(function () { t.pass('tracker closed') })
+ seeder.destroy(err => { t.error(err, 'seeder destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
+ tracker.close(() => { t.pass('tracker closed') })
})
})
diff --git a/test/node/seed-while-download.js b/test/node/seed-while-download.js
index cfbb36f..3606805 100644
--- a/test/node/seed-while-download.js
+++ b/test/node/seed-while-download.js
@@ -6,43 +6,43 @@ const series = require('run-series')
const test = require('tape')
const WebTorrent = require('../../')
-test('Seed and download a file at the same time', function (t) {
+test('Seed and download a file at the same time', t => {
t.plan(14)
const dhtServer = new DHT({ bootstrap: false })
- dhtServer.on('error', function (err) { t.fail(err) })
- dhtServer.on('warning', function (err) { t.fail(err) })
+ dhtServer.on('error', err => { t.fail(err) })
+ dhtServer.on('warning', err => { t.fail(err) })
let client1, client2
series([
- function (cb) {
+ cb => {
dhtServer.listen(cb)
},
- function (cb) {
+ cb => {
let announced = false
let loaded = false
client1 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
const torrent = client1.add(fixtures.leaves.torrent, { store: MemoryChunkStore })
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.pass('client1 finished dht announce')
announced = true
maybeDone()
})
- torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.leaves.contentPath), err => {
t.error(err, 'client1 started seeding')
loaded = true
maybeDone()
@@ -53,28 +53,28 @@ test('Seed and download a file at the same time', function (t) {
}
},
- function (cb) {
+ cb => {
let announced = false
let loaded = false
client2 = new WebTorrent({
tracker: false,
lsd: false,
- dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ dht: { bootstrap: `127.0.0.1:${dhtServer.address().port}` }
})
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
const torrent = client2.add(fixtures.alice.torrent, { store: MemoryChunkStore })
- torrent.on('dhtAnnounce', function () {
+ torrent.on('dhtAnnounce', () => {
t.pass('client2 finished dht announce')
announced = true
maybeDone()
})
- torrent.load(fs.createReadStream(fixtures.alice.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.alice.contentPath), err => {
t.error(err, 'client2 started seeding')
loaded = true
maybeDone()
@@ -85,7 +85,7 @@ test('Seed and download a file at the same time', function (t) {
}
},
- function (cb) {
+ cb => {
let gotBuffer1 = false
let gotBuffer2 = false
let gotDone1 = false
@@ -93,15 +93,15 @@ test('Seed and download a file at the same time', function (t) {
client1.add(fixtures.alice.magnetURI, { store: MemoryChunkStore })
- client1.on('torrent', function (torrent) {
- torrent.files[0].getBuffer(function (err, buf) {
+ client1.on('torrent', torrent => {
+ torrent.files[0].getBuffer((err, buf) => {
t.error(err)
t.deepEqual(buf, fixtures.alice.content, 'client1 downloaded correct content')
gotBuffer1 = true
maybeDone()
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client1 downloaded torrent from client2')
gotDone1 = true
maybeDone()
@@ -110,15 +110,15 @@ test('Seed and download a file at the same time', function (t) {
client2.add(fixtures.leaves.magnetURI, { store: MemoryChunkStore })
- client2.on('torrent', function (torrent) {
- torrent.files[0].getBuffer(function (err, buf) {
+ client2.on('torrent', torrent => {
+ torrent.files[0].getBuffer((err, buf) => {
t.error(err)
t.deepEqual(buf, fixtures.leaves.content, 'client2 downloaded correct content')
gotBuffer2 = true
maybeDone()
})
- torrent.once('done', function () {
+ torrent.once('done', () => {
t.pass('client2 downloaded torrent from client1')
gotDone2 = true
maybeDone()
@@ -130,16 +130,16 @@ test('Seed and download a file at the same time', function (t) {
}
}
- ], function (err) {
+ ], err => {
t.error(err)
- client1.destroy(function (err) {
+ client1.destroy(err => {
t.error(err, 'client1 destroyed')
})
- client2.destroy(function (err) {
+ client2.destroy(err => {
t.error(err, 'client2 destroyed')
})
- dhtServer.destroy(function (err) {
+ dhtServer.destroy(err => {
t.error(err, 'dht server destroyed')
})
})
diff --git a/test/node/server.js b/test/node/server.js
index 2da0f60..1aaff7c 100644
--- a/test/node/server.js
+++ b/test/node/server.js
@@ -4,44 +4,44 @@ const get = require('simple-get')
const test = require('tape')
const WebTorrent = require('../../')
-test('torrent.createServer: programmatic http server', function (t) {
+test('torrent.createServer: programmatic http server', t => {
t.plan(9)
const client = new WebTorrent({ tracker: false, dht: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
- client.add(fixtures.leaves.torrent, function (torrent) {
+ client.add(fixtures.leaves.torrent, torrent => {
t.pass('got "torrent" event')
const server = torrent.createServer()
- server.listen(0, function () {
+ server.listen(0, () => {
const port = server.address().port
- t.pass('server is listening on ' + port)
+ t.pass(`server is listening on ${port}`)
// Seeding after server is created should work
- torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
+ torrent.load(fs.createReadStream(fixtures.leaves.contentPath), err => {
t.error(err, 'loaded seed content into torrent')
})
- const host = 'http://localhost:' + port
+ const host = `http://localhost:${port}`
// Index page should list files in the torrent
- get.concat(host + '/', function (err, res, data) {
+ get.concat(`${host}/`, (err, res, data) => {
t.error(err, 'got http response for /')
data = data.toString()
- t.ok(data.indexOf('Leaves of Grass by Walt Whitman.epub') !== -1)
+ t.ok(data.includes('Leaves of Grass by Walt Whitman.epub'))
// Verify file content for first (and only) file
- get.concat(host + '/0', function (err, res, data) {
+ get.concat(`${host}/0`, (err, res, data) => {
t.error(err, 'got http response for /0')
t.deepEqual(data, fixtures.leaves.content)
- server.close(function () {
+ server.close(() => {
t.pass('server closed')
})
- client.destroy(function (err) {
+ client.destroy(err => {
t.error(err, 'client destroyed')
})
})
diff --git a/test/node/torrent-events.js b/test/node/torrent-events.js
index be2adbc..138fd19 100644
--- a/test/node/torrent-events.js
+++ b/test/node/torrent-events.js
@@ -3,17 +3,17 @@ const test = require('tape')
const WebTorrent = require('../../')
const MemoryChunkStore = require('memory-chunk-store')
-test('client.add: emit torrent events in order', function (t) {
+test('client.add: emit torrent events in order', t => {
t.plan(6)
const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false })
const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client1.on('error', function (err) { t.fail(err) })
- client1.on('warning', function (err) { t.fail(err) })
+ client1.on('error', err => { t.fail(err) })
+ client1.on('warning', err => { t.fail(err) })
- client2.on('error', function (err) { t.fail(err) })
- client2.on('warning', function (err) { t.fail(err) })
+ client2.on('error', err => { t.fail(err) })
+ client2.on('warning', err => { t.fail(err) })
// Start seeding
client2.seed(fixtures.leaves.content, {
@@ -21,63 +21,63 @@ test('client.add: emit torrent events in order', function (t) {
announce: []
})
- client2.on('listening', function () {
+ client2.on('listening', () => {
// Start downloading
const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
// Manually connect peers
- torrent.addPeer('127.0.0.1:' + client2.address().port)
+ torrent.addPeer(`127.0.0.1:${client2.address().port}`)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
- client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ client1.destroy(err => { t.error(err, 'client 1 destroyed') })
+ client2.destroy(err => { t.error(err, 'client 2 destroyed') })
})
})
})
-test('client.seed: emit torrent events in order', function (t) {
+test('client.seed: emit torrent events in order', t => {
t.plan(5)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.seed(fixtures.leaves.content)
let order = 0
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(++order, 1)
})
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
t.equal(++order, 2)
})
- torrent.on('ready', function () {
+ torrent.on('ready', () => {
t.equal(++order, 3)
})
- torrent.on('done', function () {
+ torrent.on('done', () => {
t.equal(++order, 4)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})
diff --git a/test/rarity-map.js b/test/rarity-map.js
index 03a9985..77773c4 100644
--- a/test/rarity-map.js
+++ b/test/rarity-map.js
@@ -4,7 +4,7 @@ const test = require('tape')
const Torrent = require('../lib/torrent')
const Wire = require('bittorrent-protocol')
-test('Rarity map usage', function (t) {
+test('Rarity map usage', t => {
t.plan(16)
const numPieces = 4
@@ -18,11 +18,11 @@ test('Rarity map usage', function (t) {
dht: false,
tracker: false,
lsd: false,
- _remove: function () {}
+ _remove () {}
}
const opts = {}
const torrent = new Torrent(torrentId, client, opts)
- torrent.on('metadata', function () {
+ torrent.on('metadata', () => {
torrent._onWire(new Wire())
torrent._onWire(new Wire())
@@ -79,10 +79,10 @@ test('Rarity map usage', function (t) {
t.equal(piece, 3)
// test piece filter func
- piece = rarityMap.getRarestPiece(function (i) { return i <= 1 })
+ piece = rarityMap.getRarestPiece(i => i <= 1)
t.equal(piece, 0)
- piece = rarityMap.getRarestPiece(function (i) { return i === 1 || i === 2 })
+ piece = rarityMap.getRarestPiece(i => i === 1 || i === 2)
t.equal(piece, 2)
function validateInitial () {
@@ -119,8 +119,8 @@ test('Rarity map usage', function (t) {
}
})
- t.on('end', function () {
- torrent.wires.forEach(function (wire) {
+ t.on('end', () => {
+ torrent.wires.forEach(wire => {
wire.destroy()
})
torrent.destroy()
diff --git a/test/torrent-destroy.js b/test/torrent-destroy.js
index 5795405..f220cf2 100644
--- a/test/torrent-destroy.js
+++ b/test/torrent-destroy.js
@@ -2,23 +2,23 @@ const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../')
-test('torrent.destroy: destroy and remove torrent', function (t) {
+test('torrent.destroy: destroy and remove torrent', t => {
t.plan(5)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
- client.on('error', function (err) { t.fail(err) })
- client.on('warning', function (err) { t.fail(err) })
+ client.on('error', err => { t.fail(err) })
+ client.on('warning', err => { t.fail(err) })
const torrent = client.add(fixtures.leaves.parsedTorrent.infoHash)
t.equal(client.torrents.length, 1)
- torrent.on('infoHash', function () {
+ torrent.on('infoHash', () => {
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
- torrent.destroy(function (err) { t.error(err, 'torrent destroyed') })
+ torrent.destroy(err => { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
- client.destroy(function (err) { t.error(err, 'client destroyed') })
+ client.destroy(err => { t.error(err, 'client destroyed') })
})
})