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

Commit

Permalink
fix: start webrtc sigserve during tests so browsers can dial things
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jan 30, 2020
1 parent 684b873 commit 2b6f0e9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
const IPFSFactory = require('ipfsd-ctl')
const MockPreloadNode = require('./test/utils/mock-preload-node')
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server')

const ipfsdServer = IPFSFactory.createServer()
const preloadNode = MockPreloadNode.createNode()
const echoServer = EchoServer.createServer()
let sigServer

module.exports = {
bundlesize: { maxSize: '652kB' },
Expand Down Expand Up @@ -42,11 +44,16 @@ module.exports = {
await ipfsdServer.start()
await preloadNode.start()
await echoServer.start()
sigServer = await webRTCStarSigServer.start({
host: '127.0.0.1',
port: 14579
})
},
post: async () => {
await ipfsdServer.stop()
await preloadNode.stop()
await echoServer.stop()
await sigServer.stop()
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/components/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ module.exports = ({ peerInfo }) => {
publicKey: peerInfo.id.pubKey.bytes.toString('base64'),
addresses: peerInfo.multiaddrs
.toArray()
.map(ma => `${ma}/p2p/${id}`)
.map(ma => {
const str = ma.toString()

// some relay-style transports add our peer id to the ma for us
// so don't double-add
if (str.endsWith(`/p2p/${id}`)) {
return str
}

return `${str}/p2p/${id}`
})
.sort()
.map(ma => multiaddr(ma)),
agentVersion: `js-ipfs/${pkgversion}`,
Expand Down
13 changes: 11 additions & 2 deletions test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const tests = require('interface-ipfs-core')
const merge = require('merge-options')
const { createFactory } = require('ipfsd-ctl')
const { isNode } = require('ipfs-utils/src/env')
const { isNode, isBrowser } = require('ipfs-utils/src/env')
const IPFS = require('../../src')

/** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */
Expand All @@ -23,7 +23,16 @@ describe('interface-ipfs-core tests', function () {
ref: require('ipfs-http-client')
},
ipfsOptions: {
pass: 'ipfs-is-awesome-software'
pass: 'ipfs-is-awesome-software',
...(isBrowser ? {
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star'
]
}
}
} : {})
}
}
const overrides = {
Expand Down
14 changes: 14 additions & 0 deletions test/utils/factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const { createFactory } = require('ipfsd-ctl')
const merge = require('merge-options')
const { isBrowser } = require('ipfs-utils/src/env')

const factory = (options, overrides) => createFactory(
merge({
Expand All @@ -18,6 +19,19 @@ const factory = (options, overrides) => createFactory(
merge({
js: {
ipfsBin: './src/cli/bin.js'
},
proc: {
...(isBrowser ? {
ipfsOptions: {
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star'
]
}
}
}
} : {})
}
}, overrides)
)
Expand Down

0 comments on commit 2b6f0e9

Please sign in to comment.