How to use the webtorrent-fixtures.leaves function in webtorrent-fixtures

To help you get started, we’ve selected a few webtorrent-fixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webtorrent / webtorrent / test / node / download-metadata.js View on Github external
test('Download metadata magnet URI with unsupported protocol in xs parameter', function (t) {
  t.plan(1)

  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.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'), { store: MemoryChunkStore })

  setTimeout(function () {
    // no crash by now
    client.destroy(function (err) { t.error(err, 'client destroyed') })
  }, 100)
})
github webtorrent / create-torrent / test / stream.js View on Github external
test('create single file torrent from a stream', t => {
  t.plan(11)

  const stream = fs.createReadStream(fixtures.leaves.contentPath)
  stream.name = 'Leaves of Grass by Walt Whitman.epub'

  const startTime = Date.now()
  createTorrent(stream, { pieceLength: 16384 }, (err, torrent) => {
    t.error(err)

    const parsedTorrent = parseTorrent(torrent)

    t.equals(parsedTorrent.name, 'Leaves of Grass by Walt Whitman.epub')

    t.notOk(parsedTorrent.private)

    t.ok(parsedTorrent.created.getTime() >= startTime, 'created time is after start time')

    t.ok(Array.isArray(parsedTorrent.announce))
github webtorrent / parse-torrent / test / encode.js View on Github external
test('parseTorrent.toTorrentFile', t => {
  const parsedTorrent = parseTorrent(fixtures.leaves.torrent)
  const buf = parseTorrent.toTorrentFile(parsedTorrent)
  const doubleParsedTorrent = parseTorrent(buf)

  t.deepEqual(doubleParsedTorrent, parsedTorrent)
  t.end()
})
github webtorrent / webtorrent / test / torrent-destroy.js View on Github external
test('torrent.destroy: destroy and remove torrent', function (t) {
  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) })

  var torrent = client.add(fixtures.leaves.parsedTorrent.infoHash)
  t.equal(client.torrents.length, 1)

  torrent.on('infoHash', function () {
    t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)

    torrent.destroy(function (err) { t.error(err, 'torrent destroyed') })
    t.equal(client.torrents.length, 0)

    client.destroy(function (err) { t.error(err, 'client destroyed') })
  })
})
github webtorrent / webtorrent-cli / test / basic.js View on Github external
test('Command line: webtorrent download  (with local content)', t => {
  t.plan(2)

  const fixturesPath = path.join(path.dirname(require.resolve('webtorrent-fixtures')), 'fixtures')

  cp.exec(`${CMD} download ${fixtures.leaves.torrentPath} --out ${fixturesPath}`, (err, data) => {
    t.error(err)
    t.ok(data.includes('successfully'))
  })
})
github webtorrent / webtorrent / test / node / download-dht-torrent.js View on Github external
file.getBuffer(function (err, buf) {
            if (err) throw err
            t.deepEqual(buf, fixtures.leaves.content, 'downloaded correct content')
            gotBuffer = true
            maybeDone()
          })
        })
github webtorrent / webtorrent / test / node / download-tracker-magnet.js View on Github external
function magnetDownloadTest (t, serverType) {
  t.plan(10)

  var tracker = new TrackerServer(
    serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false }
  )

  tracker.on('error', function (err) { t.fail(err) })
  tracker.on('warning', function (err) { t.fail(err) })

  var trackerStartCount = 0
  tracker.on('start', function () {
    trackerStartCount += 1
  })

  var parsedTorrent = Object.assign({}, fixtures.leaves.parsedTorrent)
  var magnetURI, client1, client2

  series([
    function (cb) {
      tracker.listen(cb)
    },

    function (cb) {
      var port = tracker[serverType].address().port
      var announceUrl = serverType === 'http'
        ? 'http://127.0.0.1:' + port + '/announce'
        : 'udp://127.0.0.1:' + port

      parsedTorrent.announce = [announceUrl]
      magnetURI = 'magnet:?xt=urn:btih:' + parsedTorrent.infoHash + '&tr=' + encodeURIComponent(announceUrl)
github webtorrent / bittorrent-tracker / test / client-magnet.js View on Github external
function testMagnet (t, serverType) {
  t.plan(9)

  var parsedTorrent = magnet(fixtures.leaves.magnetURI)

  common.createServer(t, serverType, function (server, announceUrl) {
    var client = new Client({
      infoHash: parsedTorrent.infoHash,
      announce: announceUrl,
      peerId: peerId,
      port: 6881,
      wrtc: {}
    })

    if (serverType === 'ws') common.mockWebsocketTracker(client)
    client.on('error', function (err) { t.error(err) })
    client.on('warning', function (err) { t.error(err) })

    client.once('update', function (data) {
      t.equal(data.announce, announceUrl)
github webtorrent / bittorrent-tracker / test / client.js View on Github external
common.createServer(t, serverType, function (server, announceUrl) {
    var client = new Client({
      infoHash: fixtures.leaves.parsedTorrent.infoHash,
      announce: announceUrl,
      peerId: peerId1,
      port: port,
      wrtc: {}
    })

    if (serverType === 'ws') common.mockWebsocketTracker(client)
    client.on('error', function (err) { t.error(err) })
    client.on('warning', function (err) { t.error(err) })

    client.setInterval(500)

    client.start()

    client.once('update', function () {
      client.setInterval(500)
github webtorrent / webtorrent / test / client-remove.js View on Github external
torrent.on('infoHash', function () {
    t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)

    client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
    t.equal(client.torrents.length, 0)

    client.destroy(function (err) { t.error(err, 'client destroyed') })
  })
})