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

Commit 2b6f0e9

Browse files
committed
fix: start webrtc sigserve during tests so browsers can dial things
1 parent 684b873 commit 2b6f0e9

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

.aegir.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
const IPFSFactory = require('ipfsd-ctl')
44
const MockPreloadNode = require('./test/utils/mock-preload-node')
55
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
6+
const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server')
67

78
const ipfsdServer = IPFSFactory.createServer()
89
const preloadNode = MockPreloadNode.createNode()
910
const echoServer = EchoServer.createServer()
11+
let sigServer
1012

1113
module.exports = {
1214
bundlesize: { maxSize: '652kB' },
@@ -42,11 +44,16 @@ module.exports = {
4244
await ipfsdServer.start()
4345
await preloadNode.start()
4446
await echoServer.start()
47+
sigServer = await webRTCStarSigServer.start({
48+
host: '127.0.0.1',
49+
port: 14579
50+
})
4551
},
4652
post: async () => {
4753
await ipfsdServer.stop()
4854
await preloadNode.stop()
4955
await echoServer.stop()
56+
await sigServer.stop()
5057
}
5158
}
5259
}

src/core/components/id.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ module.exports = ({ peerInfo }) => {
1212
publicKey: peerInfo.id.pubKey.bytes.toString('base64'),
1313
addresses: peerInfo.multiaddrs
1414
.toArray()
15-
.map(ma => `${ma}/p2p/${id}`)
15+
.map(ma => {
16+
const str = ma.toString()
17+
18+
// some relay-style transports add our peer id to the ma for us
19+
// so don't double-add
20+
if (str.endsWith(`/p2p/${id}`)) {
21+
return str
22+
}
23+
24+
return `${str}/p2p/${id}`
25+
})
1626
.sort()
1727
.map(ma => multiaddr(ma)),
1828
agentVersion: `js-ipfs/${pkgversion}`,

test/core/interface.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const tests = require('interface-ipfs-core')
55
const merge = require('merge-options')
66
const { createFactory } = require('ipfsd-ctl')
7-
const { isNode } = require('ipfs-utils/src/env')
7+
const { isNode, isBrowser } = require('ipfs-utils/src/env')
88
const IPFS = require('../../src')
99

1010
/** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */
@@ -23,7 +23,16 @@ describe('interface-ipfs-core tests', function () {
2323
ref: require('ipfs-http-client')
2424
},
2525
ipfsOptions: {
26-
pass: 'ipfs-is-awesome-software'
26+
pass: 'ipfs-is-awesome-software',
27+
...(isBrowser ? {
28+
config: {
29+
Addresses: {
30+
Swarm: [
31+
'/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star'
32+
]
33+
}
34+
}
35+
} : {})
2736
}
2837
}
2938
const overrides = {

test/utils/factory.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
const { createFactory } = require('ipfsd-ctl')
33
const merge = require('merge-options')
4+
const { isBrowser } = require('ipfs-utils/src/env')
45

56
const factory = (options, overrides) => createFactory(
67
merge({
@@ -18,6 +19,19 @@ const factory = (options, overrides) => createFactory(
1819
merge({
1920
js: {
2021
ipfsBin: './src/cli/bin.js'
22+
},
23+
proc: {
24+
...(isBrowser ? {
25+
ipfsOptions: {
26+
config: {
27+
Addresses: {
28+
Swarm: [
29+
'/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star'
30+
]
31+
}
32+
}
33+
}
34+
} : {})
2135
}
2236
}, overrides)
2337
)

0 commit comments

Comments
 (0)