diff --git a/src/bitswap/wantlist.js b/src/bitswap/wantlist.js index 7d97c6c1..3afc10f7 100644 --- a/src/bitswap/wantlist.js +++ b/src/bitswap/wantlist.js @@ -3,6 +3,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { waitForWantlistKey } = require('./utils') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -15,15 +16,18 @@ module.exports = (common, options) => { describe('.bitswap.wantlist', function () { this.timeout(60 * 1000) + let ipfsA let ipfsB const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api // Add key to the wantlist for ipfsB ipfsB.block.get(key).catch(() => { /* is ok, expected on teardown */ }) + await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 27bb397b..21dac8de 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -7,6 +7,7 @@ const hat = require('hat') const multibase = require('multibase') const { getDescribe, getIt, expect } = require('../utils/mocha') const all = require('it-all') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -82,7 +83,8 @@ module.exports = (common, options) => { it('should resolve IPNS link recursively', async function () { this.timeout(20 * 1000) - const node = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + const node = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await ipfs.swarm.connect(node.peerId.addresses[0]) const [{ path }] = await all(ipfs.add(Buffer.from('should resolve a record recursive === true'))) const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 }) diff --git a/src/ping/ping.js b/src/ping/ping.js index 905b511e..22c0e09e 100644 --- a/src/ping/ping.js +++ b/src/ping/ping.js @@ -4,6 +4,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { expectIsPingResponse, isPong } = require('./utils') const all = require('it-all') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -22,7 +23,8 @@ module.exports = (common, options) => { before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) diff --git a/src/pubsub/peers.js b/src/pubsub/peers.js index eb75d914..d417b53e 100644 --- a/src/pubsub/peers.js +++ b/src/pubsub/peers.js @@ -4,6 +4,7 @@ const { waitForPeers, getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -23,8 +24,9 @@ module.exports = (common, options) => { let subscribedTopics = [] before(async () => { ipfs1 = (await common.spawn()).api - ipfs2 = (await common.spawn()).api - ipfs3 = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfs2 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api + ipfs3 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api const ipfs2Addr = ipfs2.peerId.addresses .find(ma => ma.nodeAddress().address === '127.0.0.1') diff --git a/src/pubsub/subscribe.js b/src/pubsub/subscribe.js index 6dad3bbe..497ae45e 100644 --- a/src/pubsub/subscribe.js +++ b/src/pubsub/subscribe.js @@ -6,6 +6,7 @@ const all = require('it-all') const { waitForPeers, getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -28,7 +29,9 @@ module.exports = (common, options) => { ipfs1 = (await common.spawn()).api // TODO 'multiple connected nodes' tests fails with go in Firefox // and JS is flaky everywhere - ipfs2 = (await common.spawn()).api + + // webworkers are not dialable because webrtc is not available + ipfs2 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api }) beforeEach(() => { diff --git a/src/swarm/addrs.js b/src/swarm/addrs.js index a9aea724..d5e21e60 100644 --- a/src/swarm/addrs.js +++ b/src/swarm/addrs.js @@ -4,6 +4,7 @@ const CID = require('cids') const Multiaddr = require('multiaddr') const { getDescribe, getIt, expect } = require('../utils/mocha') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -22,7 +23,8 @@ module.exports = (common, options) => { before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) diff --git a/src/swarm/connect.js b/src/swarm/connect.js index 4701c695..ac341ddc 100644 --- a/src/swarm/connect.js +++ b/src/swarm/connect.js @@ -2,6 +2,7 @@ 'use strict' const { getDescribe, getIt, expect } = require('../utils/mocha') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -19,7 +20,8 @@ module.exports = (common, options) => { before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api }) after(() => common.clean()) diff --git a/src/swarm/disconnect.js b/src/swarm/disconnect.js index 214b0d9e..3d0667d7 100644 --- a/src/swarm/disconnect.js +++ b/src/swarm/disconnect.js @@ -2,6 +2,7 @@ 'use strict' const { getDescribe, getIt, expect } = require('../utils/mocha') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -20,7 +21,8 @@ module.exports = (common, options) => { before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + // webworkers are not dialable because webrtc is not available + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) diff --git a/src/swarm/local-addrs.js b/src/swarm/local-addrs.js index 3a484fce..e8aa0d9e 100644 --- a/src/swarm/local-addrs.js +++ b/src/swarm/local-addrs.js @@ -2,6 +2,7 @@ 'use strict' const { getDescribe, getIt, expect } = require('../utils/mocha') +const { isWebWorker } = require('ipfs-utils/src/env') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -25,8 +26,14 @@ module.exports = (common, options) => { it('should list local addresses the node is listening on', async () => { const multiaddrs = await ipfs.swarm.localAddrs() - // js-ipfs in the browser will have zero - expect(Array.isArray(multiaddrs)).to.be.true() + + expect(multiaddrs).to.be.an.instanceOf(Array) + + if (isWebWorker) { + expect(multiaddrs).to.have.lengthOf(0) + } else { + expect(multiaddrs).to.not.be.empty() + } }) }) } diff --git a/src/swarm/peers.js b/src/swarm/peers.js index d7ffaa60..5b29de10 100644 --- a/src/swarm/peers.js +++ b/src/swarm/peers.js @@ -4,7 +4,7 @@ const multiaddr = require('multiaddr') const CID = require('cids') const delay = require('delay') -const { isNode, isBrowser, isElectron } = require('ipfs-utils/src/env') +const { isBrowser, isWebWorker } = require('ipfs-utils/src/env') const { getDescribe, getIt, expect } = require('../utils/mocha') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ @@ -24,7 +24,7 @@ module.exports = (common, options) => { before(async () => { ipfsA = (await common.spawn()).api - ipfsB = (await common.spawn()).api + ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) /* TODO: Seen if we still need this after this is fixed https://github.com/ipfs/js-ipfs/issues/2601 gets resolved */ @@ -88,7 +88,7 @@ module.exports = (common, options) => { it('should list peers only once', async () => { const nodeA = (await common.spawn()).api - const nodeB = (await common.spawn()).api + const nodeB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api await nodeA.swarm.connect(nodeB.peerId.addresses[0]) await delay(1000) const peersA = await nodeA.swarm.peers() @@ -99,22 +99,40 @@ module.exports = (common, options) => { it('should list peers only once even if they have multiple addresses', async () => { // TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152 - const configA = getConfig(isNode || isElectron || (common.opts && common.opts.type === 'go') ? [ - '/ip4/127.0.0.1/tcp/16543', - '/ip4/127.0.0.1/tcp/16544' - ] : [ + let addresses + + if (isBrowser) { + addresses = [ + '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star', + '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' + ] + } else if (isWebWorker) { + // webworkers are not dialable (no webrtc available) until stardust is async/await + // https://github.com/libp2p/js-libp2p-stardust/pull/14 + addresses = [] + } else { + addresses = [ + '/ip4/127.0.0.1/tcp/26543/ws', + '/ip4/127.0.0.1/tcp/26544/ws' + ] + } + + const configA = getConfig(addresses) + const configB = getConfig(isBrowser ? [ '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star', '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' - ]) - const configB = getConfig(isNode || isElectron || (common.opts && common.opts.type === 'go') ? [ + ] : [ '/ip4/127.0.0.1/tcp/26545/ws', '/ip4/127.0.0.1/tcp/26546/ws' - ] : [ - '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star', - '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' ]) + const nodeA = (await common.spawn({ ipfsOptions: { config: configA } })).api - const nodeB = (await common.spawn({ ipfsOptions: { config: configB } })).api + const nodeB = (await common.spawn({ + type: isWebWorker ? 'go' : undefined, + ipfsOptions: { + config: configB + } + })).api // TODO: the webrtc-star transport only keeps the last listened on address around // so the browser has to use 1 as the array index