diff options
Diffstat (limited to 'test/duplicates.js')
-rw-r--r-- | test/duplicates.js | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/test/duplicates.js b/test/duplicates.js index a89f649..b19355e 100644 --- a/test/duplicates.js +++ b/test/duplicates.js @@ -1,52 +1,54 @@ -var fs = require('fs') -var path = require('path') +var common = require('./common') var test = require('tape') var WebTorrent = require('../') -var leavesBook = fs.readFileSync(path.resolve(__dirname, 'content', 'Leaves of Grass by Walt Whitman.epub')) - test('client.seed followed by duplicate client.add', function (t) { - t.plan(3) - - var opts = { - name: 'Leaves of Grass by Walt Whitman.epub' - } + t.plan(5) var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - client.seed(leavesBook, opts, function (torrent1) { + client.seed(common.leaves.content, { + name: 'Leaves of Grass by Walt Whitman.epub' + }, function (torrent1) { + t.equal(client.torrents.length, 1) + client.add(torrent1.infoHash, function (torrent2) { t.equal(torrent1.infoHash, torrent2.infoHash) t.equal(client.torrents.length, 1) - client.destroy(function () { - t.pass('destroyed client') + + client.destroy(function (err) { + t.error(err, 'destroyed client') + t.equal(client.torrents.length, 0) }) }) }) }) -test('client.seed followed by duplicate client.add, twice', function (t) { - t.plan(5) - - var opts = { - name: 'Leaves of Grass by Walt Whitman.epub' - } +test('client.seed followed by two duplicate client.add calls', function (t) { + t.plan(7) var client = new WebTorrent({ dht: false, tracker: false }) client.on('error', function (err) { t.fail(err) }) client.on('warning', function (err) { t.fail(err) }) - client.seed(leavesBook, opts, function (torrent1) { + client.seed(common.leaves.content, { + name: 'Leaves of Grass by Walt Whitman.epub' + }, function (torrent1) { + t.equal(client.torrents.length, 1) + client.add(torrent1.infoHash, function (torrent2) { t.equal(torrent1.infoHash, torrent2.infoHash) t.equal(client.torrents.length, 1) + client.add(torrent1.infoHash, function (torrent2) { t.equal(torrent1.infoHash, torrent2.infoHash) t.equal(client.torrents.length, 1) - client.destroy(function () { - t.pass('destroyed client') + + client.destroy(function (err) { + t.error(err, 'destroyed client') + t.equal(client.torrents.length, 0) }) }) }) |