mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-03 16:31:03 +00:00
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
|
/* eslint-env mocha */
|
||
|
|
||
|
const expect = require('chai').expect
|
||
|
const WSlibp2p = require('../src')
|
||
|
const multiaddr = require('multiaddr')
|
||
|
|
||
|
describe('libp2p-websockets', function () {
|
||
|
this.timeout(10000)
|
||
|
var ws
|
||
|
|
||
|
it('create', (done) => {
|
||
|
ws = new WSlibp2p()
|
||
|
expect(ws).to.exist
|
||
|
done()
|
||
|
})
|
||
|
|
||
|
it('listen and dial', (done) => {
|
||
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||
|
ws.createListener(mh, (socket) => {
|
||
|
expect(socket).to.exist
|
||
|
socket.end()
|
||
|
ws.close(() => {
|
||
|
done()
|
||
|
})
|
||
|
}, () => {
|
||
|
const conn = ws.dial(mh)
|
||
|
conn.end()
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('listen on several', (done) => {
|
||
|
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||
|
const mh2 = multiaddr('/ip4/127.0.0.1/tcp/9091/websockets')
|
||
|
const ws = new WSlibp2p()
|
||
|
|
||
|
ws.createListener([mh1, mh2], (socket) => {}, () => {
|
||
|
ws.close(done)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('get observed addrs', (done) => {
|
||
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||
|
ws.createListener(mh, (socket) => {
|
||
|
expect(socket).to.exist
|
||
|
socket.end()
|
||
|
expect(socket.getObservedAddrs()).to.deep.equal([])
|
||
|
ws.close(() => {
|
||
|
done()
|
||
|
})
|
||
|
}, () => {
|
||
|
const conn = ws.dial(mh)
|
||
|
conn.end()
|
||
|
})
|
||
|
})
|
||
|
})
|