diff options
author | Kaylee <34007889+KayleePop@users.noreply.github.com> | 2020-09-10 21:38:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-10 21:38:44 +0300 |
commit | 7aee819796c540df0b247fec1853098f9a591d4c (patch) | |
tree | 6eb6ac35de0fed83e3e2470a3e647645c8bfa240 /test | |
parent | 9ae31e5d8a44b98a768971efb7c6b7b386eb9447 (diff) | |
parent | 3393e92166d7049dc84e2d488b4769c668ee3b20 (diff) |
Merge pull request #1364 from KayleePop/destroy
Diffstat (limited to 'test')
-rw-r--r-- | test/node/basic.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/node/basic.js b/test/node/basic.js index f99e2ef..0d7dc64 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -1,4 +1,6 @@ var fixtures = require('webtorrent-fixtures') +var fs = require('fs') +var path = require('path') var http = require('http') var test = require('tape') var WebTorrent = require('../../') @@ -157,3 +159,49 @@ test('client.add: invalid torrent id: invalid filesystem path', function (t) { client.add('/invalid/filesystem/path/123') }) + +test('client.remove: opts.destroyStore', function (t) { + t.plan(2) + + 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(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) { + var torrentPath = torrent.path + client.remove(torrent, { destroyStore: true }, function (err) { + if (err) t.fail(err) + + fs.stat(path.join(torrentPath, 'alice.txt'), function (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') }) + }) + }) + }) +}) + +test('torrent.destroy: opts.destroyStore', function (t) { + t.plan(2) + + 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(fixtures.alice.content, { name: 'alice.txt', announce: [] }, function (torrent) { + var torrentPath = torrent.path + torrent.destroy({ destroyStore: true }, function (err) { + if (err) t.fail(err) + + fs.stat(path.join(torrentPath, 'alice.txt'), function (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') }) + }) + }) + }) +}) |