-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move node-only tests out of basic.js
- Loading branch information
Showing
2 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters