fix: tests

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
This commit is contained in:
Alan Shaw 2019-04-17 12:34:56 +01:00
parent f674122b6f
commit 24d0a6132a
No known key found for this signature in database
GPG Key ID: AFC4442246B75B6F
6 changed files with 14 additions and 17 deletions

View File

@ -2,13 +2,11 @@
const multiaddr = require('multiaddr') const multiaddr = require('multiaddr')
const pipe = require('it-pipe') const pipe = require('it-pipe')
const WS = require('./src') const WS = require('./src')
let listener let listener
function boot (done) { function boot (done) {
console.log('boot!')
const ws = new WS() const ws = new WS()
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws') const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
listener = ws.createListener(conn => pipe(conn, conn)) listener = ws.createListener(conn => pipe(conn, conn))
@ -17,7 +15,6 @@ function boot (done) {
} }
function shutdown (done) { function shutdown (done) {
console.log('shutdown')
listener.close().then(done).catch(done) listener.close().then(done).catch(done)
} }

View File

@ -53,7 +53,7 @@
"chai": "^4.1.2", "chai": "^4.1.2",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1",
"interface-transport": "github:libp2p/interface-transport#feat/async-await", "interface-transport": "github:libp2p/interface-transport#feat/async-await",
"it-goodbye": "^1.0.0", "it-goodbye": "^2.0.0",
"it-pipe": "^1.0.0", "it-pipe": "^1.0.0",
"multiaddr": "^6.0.3", "multiaddr": "^6.0.3",
"pull-goodbye": "0.0.2", "pull-goodbye": "0.0.2",

View File

@ -11,7 +11,7 @@ const createListener = require('./listener')
class WebSockets { class WebSockets {
async dial (ma, options) { async dial (ma, options) {
log('dialing %s', ma) log('dialing %s', ma)
const socket = connect(toUri(ma), { binary: true }) const socket = connect(toUri(ma), Object.assign({ binary: true }, options))
await socket.connected() await socket.connected()
socket.getObservedAddrs = () => [ma] socket.getObservedAddrs = () => [ma]
log('connected %s', ma) log('connected %s', ma)

View File

@ -74,8 +74,8 @@ describe('adapter libp2p-websockets', () => {
pull(s, conn, s) pull(s, conn, s)
}) })
}) })
})
it('.createServer throws in browser', () => { it('.createServer throws in browser', () => {
expect(new WS().createListener).to.throw() expect(new WS().createListener).to.throw()
})
}) })

View File

@ -13,7 +13,7 @@ const { collect, take } = require('streaming-iterables')
const WS = require('../src') const WS = require('../src')
// require('./adapter/browser') require('./adapter/browser')
describe('libp2p-websockets', () => { describe('libp2p-websockets', () => {
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws') const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
@ -26,7 +26,7 @@ describe('libp2p-websockets', () => {
}) })
it('echo', async () => { it('echo', async () => {
const message = 'Hello World!' const message = Buffer.from('Hello World!')
const s = goodbye({ source: [message], sink: collect }) const s = goodbye({ source: [message], sink: collect })
const results = await pipe(s, conn, s) const results = await pipe(s, conn, s)
@ -60,8 +60,8 @@ describe('libp2p-websockets', () => {
expect(result).to.have.length(20000) expect(result).to.have.length(20000)
}) })
}) })
})
it('.createServer throws in browser', () => { it('.createServer throws in browser', () => {
expect(new WS().createListener).to.throw() expect(new WS().createListener).to.throw()
})
}) })

View File

@ -195,7 +195,7 @@ describe('dial', () => {
const result = await pipe(s, conn, s) const result = await pipe(s, conn, s)
expect(result).to.be.eql(['hey']) expect(result).to.be.eql([Buffer.from('hey')])
}) })
it('dial with IPFS Id', async () => { it('dial with IPFS Id', async () => {
@ -205,7 +205,7 @@ describe('dial', () => {
const result = await pipe(s, conn, s) const result = await pipe(s, conn, s)
expect(result).to.be.eql(['hey']) expect(result).to.be.eql([Buffer.from('hey')])
}) })
}) })
@ -228,7 +228,7 @@ describe('dial', () => {
const result = await pipe(s, conn, s) const result = await pipe(s, conn, s)
expect(result).to.be.eql(['hey']) expect(result).to.be.eql([Buffer.from('hey')])
}) })
it('dial with IPFS Id', async () => { it('dial with IPFS Id', async () => {
@ -241,7 +241,7 @@ describe('dial', () => {
}) })
const result = await pipe(s, conn, s) const result = await pipe(s, conn, s)
expect(result).to.be.eql(['hey']) expect(result).to.be.eql([Buffer.from('hey')])
}) })
}) })
}) })