diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-06-28 13:49:23 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-06-28 13:49:23 +0300 |
commit | ebbffb27127b0856d4a9a59994bbf11ba9269171 (patch) | |
tree | e1d8b77c946fe1d4a252e662e13c427adaa47d84 /test/extensions.js | |
parent | a71f9a19445c026b6cea320890853ec1e58085bf (diff) |
feross's fixes to devTristan pr
explained here:
https://github.com/feross/webtorrent/pull/363#issuecomment-116253169
Diffstat (limited to 'test/extensions.js')
-rw-r--r-- | test/extensions.js | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/test/extensions.js b/test/extensions.js index f553743..ade5b9d 100644 --- a/test/extensions.js +++ b/test/extensions.js @@ -6,7 +6,7 @@ var WebTorrent = require('../') var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent') var leavesTorrent = parseTorrent(leaves) -test('onWire option', {timeout: 500}, function (t) { +test('extension support', function (t) { t.plan(6) var extendedHandshakes = 0 @@ -15,39 +15,38 @@ test('onWire option', {timeout: 500}, function (t) { } Extension.prototype.name = 'wt_test' - Extension.prototype.onExtendedHandshake = function (handshake) { - t.equal(handshake.test.toString(), 'Hello, World!', 'handshake.test === Hello, World!') - extendedHandshakes++ + Extension.prototype.onExtendedHandshake = function (extendedHandshake) { + extendedHandshakes += 1 + + t.equal( + extendedHandshake.test.toString(), 'Hello, World!', + 'handshake.test === Hello, World!' + ) + if (extendedHandshakes === 2) { client1.destroy(function () { t.pass('client1 destroyed') }) client2.destroy(function () { - t.pass('client1 destroyed') + t.pass('client2 destroyed') }) } } - var client1 = new WebTorrent({ - dht: false, - tracker: false, - onWire: function (wire) { + var client1 = new WebTorrent({ dht: false, tracker: false }) + var client2 = new WebTorrent({ dht: false, tracker: false }) + + client1.add(leavesTorrent, function (torrent1) { + torrent1.on('wire', function (wire) { t.pass('client1 onWire') wire.use(Extension) - } - }) - var client2 = new WebTorrent({ - dht: false, - tracker: false, - onWire: function (wire) { + }) + var torrent2 = client2.add(leavesTorrent.infoHash) + torrent2.on('wire', function (wire) { t.pass('client2 onWire') wire.use(Extension) - } - }) - - client1.add(leavesTorrent, function (torrent1) { - client2.add(leavesTorrent.infoHash) - client2.on('listening', function (port, torrent2) { + }) + client2.on('listening', function () { torrent2.addPeer('127.0.0.1:' + client1.torrentPort) }) }) |