diff --git a/package.json b/package.json index 4f19e6e..9f37352 100644 --- a/package.json +++ b/package.json @@ -40,13 +40,13 @@ "bl": "^1.1.2", "buffer-loader": "0.0.1", "chai": "^3.5.0", - "aegir": "^3.0.0", + "aegir": "^3.0.1", "gulp": "^3.9.1", "istanbul": "^0.4.3", "libp2p-multiplex": "^0.2.1", "libp2p-spdy": "^0.3.1", "libp2p-tcp": "^0.5.1", - "libp2p-websockets": "^0.4.3", + "libp2p-websockets": "^0.4.4", "pre-commit": "^1.1.2", "stream-pair": "^1.0.3" }, @@ -55,7 +55,7 @@ "duplex-passthrough": "github:diasdavid/duplex-passthrough", "ip-address": "^5.8.0", "lodash.contains": "^2.4.3", - "multiaddr": "^1.4.0", + "multiaddr": "^1.4.1", "multistream-select": "^0.6.5", "peer-id": "^0.6.6", "peer-info": "^0.6.2", diff --git a/test/00-basic.node.js b/test/00-basic.node.js index 4c94654..10b4a05 100644 --- a/test/00-basic.node.js +++ b/test/00-basic.node.js @@ -6,8 +6,7 @@ const expect = require('chai').expect const Swarm = require('../src') describe('basics', () => { - it('throws on missing peerInfo', (done) => { - expect(Swarm).to.throw(Error) - done() + it('throws on missing peerInfo', () => { + expect(() => Swarm()).to.throw(Error) }) }) diff --git a/test/03-transport-websockets.node.js b/test/03-transport-websockets.node.js index a1a06e1..f20ffef 100644 --- a/test/03-transport-websockets.node.js +++ b/test/03-transport-websockets.node.js @@ -18,12 +18,11 @@ describe('transport - websockets', function () { var peerA = new Peer() var peerB = new Peer() - before((done) => { + before(() => { peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets')) peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets')) swarmA = new Swarm(peerA) swarmB = new Swarm(peerB) - done() }) it('add', (done) => { @@ -36,31 +35,28 @@ describe('transport - websockets', function () { }) it('listen', (done) => { - var count = 0 - swarmA.transport.listen('ws', {}, (conn) => { - conn.pipe(conn) - }, ready) - swarmB.transport.listen('ws', {}, (conn) => { - conn.pipe(conn) - }, ready) - - function ready () { - if (++count === 2) { - expect(peerA.multiaddrs.length).to.equal(1) - expect( - peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets')) - ).to.be.equal( - true - ) - expect(peerB.multiaddrs.length).to.equal(1) - expect( - peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets')) - ).to.equal( - true - ) - done() - } - } + parallel([ + (cb) => swarmA.transport.listen('ws', {}, (conn) => { + conn.pipe(conn) + }, cb), + (cb) => swarmB.transport.listen('ws', {}, (conn) => { + conn.pipe(conn) + }, cb) + ], () => { + expect(peerA.multiaddrs.length).to.equal(1) + expect( + peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets')) + ).to.be.equal( + true + ) + expect(peerB.multiaddrs.length).to.equal(1) + expect( + peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets')) + ).to.equal( + true + ) + done() + }) }) it('dial', (done) => { diff --git a/test/05-muxing-spdy.node.js b/test/05-muxing-spdy.node.js index 9ed39a4..e6d8c6c 100644 --- a/test/05-muxing-spdy.node.js +++ b/test/05-muxing-spdy.node.js @@ -51,16 +51,15 @@ describe('stream muxing with spdy (on TCP)', function () { after((done) => { parallel([ (cb) => swarmA.close(cb), - (cb) => swarmB.close(cb), - (cb) => swarmC.close(cb) + (cb) => swarmB.close(cb) + // (cb) => swarmC.close(cb) ], done) }) - it('add', (done) => { + it('add', () => { swarmA.connection.addStreamMuxer(spdy) swarmB.connection.addStreamMuxer(spdy) swarmC.connection.addStreamMuxer(spdy) - done() }) it('handle + dial on protocol', (done) => { diff --git a/test/06-conn-upgrade-secio.node.js b/test/06-conn-upgrade-secio.node.js index 1f33224..2e661f9 100644 --- a/test/06-conn-upgrade-secio.node.js +++ b/test/06-conn-upgrade-secio.node.js @@ -4,9 +4,6 @@ describe('secio conn upgrade (on TCP)', function () { this.timeout(20000) - before((done) => { done() }) - after((done) => { done() }) - it.skip('add', (done) => {}) it.skip('dial', (done) => {}) it.skip('tls on a muxed stream (not the full conn)', (done) => {}) diff --git a/test/07-conn-upgrade-tls.node.js b/test/07-conn-upgrade-tls.node.js index b3be730..425d0f2 100644 --- a/test/07-conn-upgrade-tls.node.js +++ b/test/07-conn-upgrade-tls.node.js @@ -2,9 +2,6 @@ 'use strict' describe('tls conn upgrade (on TCP)', function () { - before((done) => { done() }) - after((done) => { done() }) - it.skip('add', (done) => {}) it.skip('dial', (done) => {}) it.skip('tls on a muxed stream (not the full conn)', (done) => {}) diff --git a/test/08-swarm-without-muxing.node.js b/test/08-swarm-without-muxing.node.js index 7463eb0..0fc1b57 100644 --- a/test/08-swarm-without-muxing.node.js +++ b/test/08-swarm-without-muxing.node.js @@ -28,18 +28,12 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function ( swarmB = new Swarm(peerB) swarmA.transport.add('tcp', new TCP()) - swarmA.transport.listen('tcp', {}, null, ready) - swarmB.transport.add('tcp', new TCP()) - swarmB.transport.listen('tcp', {}, null, ready) - - var counter = 0 - function ready () { - if (++counter === 2) { - done() - } - } + parallel([ + (cb) => swarmA.transport.listen('tcp', {}, null, cb), + (cb) => swarmB.transport.listen('tcp', {}, null, cb) + ], done) }) after((done) => { diff --git a/test/09-swarm-with-muxing.node.js b/test/09-swarm-with-muxing.node.js index 4af0c6b..90b1a45 100644 --- a/test/09-swarm-with-muxing.node.js +++ b/test/09-swarm-with-muxing.node.js @@ -61,21 +61,14 @@ describe('high level API - with everything mixed all together!', function () { peerC.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/0')) swarmA.transport.add('tcp', new TCP()) - swarmA.transport.listen('tcp', {}, null, ready) - swarmB.transport.add('tcp', new TCP()) - swarmB.transport.listen('tcp', {}, null, ready) - swarmC.transport.add('tcp', new TCP()) - swarmC.transport.listen('tcp', {}, null, ready) - var counter = 0 - - function ready () { - if (++counter === 3) { - done() - } - } + parallel([ + (cb) => swarmA.transport.listen('tcp', {}, null, cb), + (cb) => swarmB.transport.listen('tcp', {}, null, cb), + (cb) => swarmC.transport.listen('tcp', {}, null, cb) + ], done) }) it.skip('add utp', (done) => {}) @@ -87,27 +80,19 @@ describe('high level API - with everything mixed all together!', function () { peerE.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9042/websockets')) swarmB.transport.add('ws', new WebSockets()) - swarmB.transport.listen('ws', {}, null, ready) - swarmC.transport.add('ws', new WebSockets()) - swarmC.transport.listen('ws', {}, null, ready) - swarmD.transport.add('ws', new WebSockets()) - swarmD.transport.listen('ws', {}, null, ready) - swarmE.transport.add('ws', new WebSockets()) - swarmE.transport.listen('ws', {}, null, ready) - var counter = 0 - - function ready () { - if (++counter === 4) { - done() - } - } + parallel([ + (cb) => swarmB.transport.listen('ws', {}, null, cb), + (cb) => swarmC.transport.listen('ws', {}, null, cb), + (cb) => swarmD.transport.listen('ws', {}, null, cb), + (cb) => swarmE.transport.listen('ws', {}, null, cb) + ], done) }) - it('add spdy', (done) => { + it('add spdy', () => { swarmA.connection.addStreamMuxer(spdy) swarmB.connection.addStreamMuxer(spdy) swarmC.connection.addStreamMuxer(spdy) @@ -119,26 +104,26 @@ describe('high level API - with everything mixed all together!', function () { swarmC.connection.reuse() swarmD.connection.reuse() swarmE.connection.reuse() - - done() }) - it.skip('add multiplex', (done) => {}) + it.skip('add multiplex', () => {}) it('warm up from A to B on tcp to tcp+ws', (done) => { - swarmB.once('peer-mux-established', (peerInfo) => { - expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String()) - }) - - swarmA.once('peer-mux-established', (peerInfo) => { - expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String()) - }) - - swarmA.dial(peerB, (err) => { - expect(err).to.not.exist - expect(Object.keys(swarmA.muxedConns).length).to.equal(1) - done() - }) + parallel([ + (cb) => swarmB.once('peer-mux-established', (peerInfo) => { + expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String()) + cb() + }), + (cb) => swarmA.once('peer-mux-established', (peerInfo) => { + expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String()) + cb() + }), + (cb) => swarmA.dial(peerB, (err) => { + expect(err).to.not.exist + expect(Object.keys(swarmA.muxedConns).length).to.equal(1) + cb() + }) + ], done) }) it('warm up a warmed up, from B to A', (done) => { @@ -225,11 +210,9 @@ describe('high level API - with everything mixed all together!', function () { }) it('close a muxer emits event', (done) => { - swarmC.close((err) => { - if (err) throw err - }) - swarmA.once('peer-mux-closed', (peerInfo) => { - done() - }) + parallel([ + (cb) => swarmC.close(cb), + (cb) => swarmA.once('peer-mux-closed', () => cb()) + ], done) }) }) diff --git a/test/browser.js b/test/browser.js index dc3ea2b..39384b3 100644 --- a/test/browser.js +++ b/test/browser.js @@ -22,14 +22,12 @@ describe('transport - websockets', function () { var swarm - before((done) => { + before(() => { const b58IdSrc = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb' // use a pre generated Id to save time const idSrc = Id.createFromB58String(b58IdSrc) const peerSrc = new Peer(idSrc) swarm = new Swarm(peerSrc) - - done() }) it('add', (done) => { @@ -62,27 +60,24 @@ describe('high level API - 1st without stream multiplexing (on websockets)', fun var swarm var peerDst - before((done) => { + before(() => { const b58IdSrc = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb' // use a pre generated Id to save time const idSrc = Id.createFromB58String(b58IdSrc) const peerSrc = new Peer(idSrc) swarm = new Swarm(peerSrc) - - done() }) after((done) => { swarm.close(done) }) - it('add ws', (done) => { + it('add ws', () => { swarm.transport.add('ws', new WebSockets()) expect(Object.keys(swarm.transports).length).to.equal(1) - done() }) - it('create Dst peer info', (done) => { + it('create Dst peer info', () => { const b58IdDst = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb' // use a pre generated Id to save time const idDst = Id.createFromB58String(b58IdDst) @@ -90,7 +85,6 @@ describe('high level API - 1st without stream multiplexing (on websockets)', fun const ma = multiaddr('/ip4/127.0.0.1/tcp/9200/websockets') peerDst.multiaddr.add(ma) - done() }) it('dial on protocol', (done) => {