Skip to content

Commit

Permalink
move node-only tests out of basic.js
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Oct 6, 2014
1 parent d721534 commit aecf706
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
44 changes: 44 additions & 0 deletions test/basic-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var WebTorrent = require('../')
var fs = require('fs')
var http = require('http')
var parseTorrent = require('parse-torrent')
var portfinder = require('portfinder')
var test = require('tape')

var leavesPath = __dirname + '/torrents/leaves.torrent'
var leaves = fs.readFileSync(leavesPath)
var leavesTorrent = parseTorrent(leaves)

function verify (t, client, torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
client.destroy()
}

test('client.add (http url to a torrent file (string))', function (t) {
t.plan(1)

var server = http.createServer(function (req, res) {
res.end(leaves)
})

portfinder.getPort(function (err, port) {
if (err) throw err
server.listen(port, function () {
var url = 'http://127.0.0.1:' + port
var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(url, function (torrent) {
verify(t, client1, torrent)
server.close()
})
})
})
})

test('client.add (filesystem path to a torrent file (string))', function (t) {
t.plan(1)

var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(leavesPath, function (torrent) {
verify(t, client1, torrent)
})
})
34 changes: 1 addition & 33 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
var WebTorrent = require('../')
var fs = require('fs')
var http = require('http')
var parseTorrent = require('parse-torrent')
var portfinder = require('portfinder')
var test = require('tape')

var leavesPath = __dirname + '/torrents/leaves.torrent'
var leaves = fs.readFileSync(leavesPath)
var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesTorrent = parseTorrent(leaves)

function verify (t, client, torrent) {
Expand Down Expand Up @@ -38,32 +35,3 @@ test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', fun
verify(t, client5, client5.add(leavesTorrent))

})

test('client.add (http url to a torrent file (string))', function (t) {
t.plan(1)

var server = http.createServer(function (req, res) {
res.end(leaves)
})

portfinder.getPort(function (err, port) {
if (err) throw err
server.listen(port, function () {
var url = 'http://127.0.0.1:' + port
var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(url, function (torrent) {
verify(t, client1, torrent)
server.close()
})
})
})
})

test('client.add (filesystem path to a torrent file (string))', function (t) {
t.plan(1)

var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(leavesPath, function (torrent) {
verify(t, client1, torrent)
})
})

0 comments on commit aecf706

Please sign in to comment.