Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
cleanup and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 1, 2016
1 parent b1f59fa commit 3ce7409
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"multiaddr": "^2.0.0",
"pre-commit": "^1.1.2",
"pull-file": "^0.5.0",
"pull-goodbye": "0.0.1",
"pull-pair": "^1.1.0",
"pull-stream": "^3.4.3",
"run-parallel": "^1.1.6",
Expand Down
28 changes: 12 additions & 16 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ const expect = require('chai').expect
const WSlibp2p = require('libp2p-websockets')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')
const goodbye = require('pull-goodbye')

const spdy = require('../src')

require('./compliance.node')

describe('browser-server', () => {
let ws

Expand All @@ -24,22 +21,21 @@ describe('browser-server', () => {
const muxedConn = spdy.dial(transportSocket)

muxedConn.on('stream', (conn) => {
const s = goodbye({
source: pull.empty(),
sink: pull.collect((err, chunks) => {
pull(
conn,
pull.collect((err, chunks) => {
console.log('collect', err, chunks)
expect(err).to.not.exist
expect(chunks).to.be.eql(['hey'])
expect(chunks).to.be.eql([Buffer('hey')])
pull(pull.empty(), conn)
})
})
pull(s, conn, s)
)
})

const conn = muxedConn.newStream()

const s = goodbye({
source: pull.values(['hey']),
sink: pull.onEnd(done)
})
pull(s, conn, s)
pull(
pull.values([Buffer('hey')]),
muxedConn.newStream(),
pull.onEnd(done)
)
})
})
4 changes: 2 additions & 2 deletions test/spdy-over-tcp.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('spdy-over-tcp', () => {
tcp = new Tcp()
})

it('attach to a websocket, as listener', (done) => {
it('attach to a tcp socket, as listener', (done) => {
const tcpListener = tcp.createListener((socket) => {
expect(socket).to.exist
listener = spdy.listen(socket)
Expand All @@ -32,7 +32,7 @@ describe('spdy-over-tcp', () => {
tcpListener.listen(mh, done)
})

it('attach to a websocket, as dialer', (done) => {
it('attach to a tcp socket, as dialer', (done) => {
const socket = tcp.dial(mh)
expect(socket).to.exist
dialer = spdy.dial(socket)
Expand Down
29 changes: 16 additions & 13 deletions test/spdy-over-ws.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ const file = require('pull-file')
const spdy = require('../src')

describe('spdy-over-ws', () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9091/ws')

let listener
let dialer

let ws
let mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')

before(() => {
before((done) => {
ws = new WSlibp2p()
})

it('attach to a websocket, as listener', (done) => {
let i = 0
const finish = () => {
i++
return i === 2 ? done() : null
}

const wsListener = ws.createListener((socket) => {
expect(socket).to.exist
listener = spdy.listen(socket)
expect(listener).to.exist
finish()
})

wsListener.listen(mh, done)
})

it('attach to a websocket, as dialer', (done) => {
const socket = ws.dial(mh)
expect(socket).to.exist
dialer = spdy.dial(socket)
expect(dialer).to.exist
done()

wsListener.listen(mh, () => {
dialer = spdy.dial(socket)
expect(dialer).to.exist
finish()
})
})

it('open a multiplex stream from dialer', (done) => {
Expand Down

0 comments on commit 3ce7409

Please sign in to comment.