Welcome to mirror list, hosted at ThFree Co, Russian Federation.

duplicates.js « test - github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c033d2a0dc7bab16445206a5b76176c5b6394869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var fs = require('fs')
var test = require('tape')
var WebTorrent = require('../')

var leavesBook = fs.readFileSync(__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'
  }

  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.add(torrent1.infoHash, function (torrent2) {
      t.equal(torrent1.infoHash, torrent2.infoHash)
      t.equal(client.torrents.length, 1)
      client.destroy(function () {
        t.pass('destroyed client')
      })
    })
  })
})

test('client.seed followed by duplicate client.add, twice', function (t) {
  t.plan(5)

  var opts = {
    name: 'Leaves of Grass by Walt Whitman.epub'
  }

  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.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')
        })
      })
    })
  })
})