test: add circuit browser test (#326)

This commit is contained in:
Jacob Heun
2019-02-25 13:44:56 +01:00
committed by GitHub
parent 5f92acd5bb
commit 9f5f07269e
6 changed files with 164 additions and 16 deletions

40
test/utils/constants.js Normal file
View File

@ -0,0 +1,40 @@
'use strict'
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const nextTick = require('async/nextTick')
const peerJSON = require('../fixtures/test-peer')
const multiaddr = require('multiaddr')
let peerRelay = null
/**
* Creates a `PeerInfo` that can be used across testing. Once the
* relay `PeerInfo` has been requested, it will be reused for each
* additional request.
*
* This is currently being used to create a relay on test bootstrapping
* so that it can be used by browser nodes during their test suite. This
* is necessary for running a TCP node during browser tests.
* @private
* @param {function(error, PeerInfo)} callback
* @returns {void}
*/
module.exports.getPeerRelay = (callback) => {
if (peerRelay) return nextTick(callback, null, peerRelay)
PeerId.createFromJSON(peerJSON, (err, peerId) => {
if (err) {
return callback(err)
}
peerRelay = new PeerInfo(peerId)
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9245')
callback(null, peerRelay)
})
}
module.exports.WS_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/wss')
module.exports.WRTC_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/15555/wss')

View File

@ -8,3 +8,4 @@ function echo (protocol, conn) {
}
module.exports = echo
module.exports.multicodec = '/echo/1.0.0'