From 46033ae52eca6e22301bb8ed9566c498d3494711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Sat, 10 Jul 2021 20:27:48 -0500 Subject: fix: modernize code (#2134) * fix: modernize code * standard fix --- test/node/basic.js | 116 ++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'test/node/basic.js') 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') }) }) }) }) -- cgit v1.2.3