mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-26 11:42:19 +00:00
Add echo tests
This commit is contained in:
parent
19bbe473d9
commit
3b81221566
@ -17,10 +17,10 @@ function WebSockets () {
|
|||||||
options = {}
|
options = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ready = options.ready || function noop () {}
|
options.connect = options.connect || function noop () {}
|
||||||
const maOpts = multiaddr.toOptions()
|
const maOpts = multiaddr.toOptions()
|
||||||
const conn = new SWS('ws://' + maOpts.host + ':' + maOpts.port)
|
const conn = new SWS('ws://' + maOpts.host + ':' + maOpts.port)
|
||||||
conn.on('ready', options.ready)
|
conn.on('connect', options.connect)
|
||||||
conn.getObservedAddrs = () => {
|
conn.getObservedAddrs = () => {
|
||||||
return [multiaddr]
|
return [multiaddr]
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,45 @@ describe('libp2p-websockets', function () {
|
|||||||
expect(valid[0]).to.deep.equal(mh3)
|
expect(valid[0]).to.deep.equal(mh3)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('echo', (done) => {
|
||||||
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||||||
|
ws.createListener(mh, (conn) => {
|
||||||
|
conn.pipe(conn)
|
||||||
|
}, () => {
|
||||||
|
const conn = ws.dial(mh)
|
||||||
|
const message = 'Hello World!'
|
||||||
|
conn.write(message)
|
||||||
|
conn.on('data', (data) => {
|
||||||
|
expect(data.toString()).to.equal(message)
|
||||||
|
conn.end()
|
||||||
|
ws.close(() => {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('echo with connect event and send', (done) => {
|
||||||
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||||||
|
ws.createListener(mh, (conn) => {
|
||||||
|
conn.pipe(conn)
|
||||||
|
}, () => {
|
||||||
|
const message = 'Hello World!'
|
||||||
|
|
||||||
|
const conn = ws.dial(mh, {
|
||||||
|
connect: () => {
|
||||||
|
conn.send(message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
conn.on('data', (data) => {
|
||||||
|
expect(data.toString()).to.equal(message)
|
||||||
|
conn.end()
|
||||||
|
ws.close(() => {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user