diff options
author | Kaylee <34007889+KayleePop@users.noreply.github.com> | 2018-04-24 22:03:29 +0300 |
---|---|---|
committer | KayleePop <34007889+KayleePop@users.noreply.github.com> | 2020-04-15 06:01:46 +0300 |
commit | 349afeb831c4709c0878346d64c58bf7387e90f2 (patch) | |
tree | 7c4cec6128a1321a4c74aac75f78f863c31f6a39 /test | |
parent | fb8392d9f3a60fd0d5727a1d71967c06186844da (diff) |
Docs and tests for store destruction
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') }) + }) + }) + }) +}) |