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
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/client-add.js
parentfeb719d5426df7ad45d00ffadecb931780763134 (diff)
fix: modernize code (#2134)
* fix: modernize code * standard fix
Diffstat (limited to 'test/client-add.js')
-rw-r--r--test/client-add.js127
1 files changed, 62 insertions, 65 deletions
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') })
})
})