diff --git a/package.json b/package.json index a563b6b7..3ef42401 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "ipld-dag-pb": "^0.18.1", "is-ipfs": "~0.6.1", "is-plain-object": "^3.0.0", - "it-pushable": "^1.2.1", + "it-pushable": "^1.3.1", "libp2p-crypto": "~0.16.0", "multiaddr": "^6.0.0", "multibase": "~0.6.0", @@ -75,7 +75,8 @@ "through2": "^3.0.0" }, "devDependencies": { - "aegir": "^20.0.0" + "aegir": "^20.3.2", + "ipfsd-ctl": "^1.0.0" }, "contributors": [ "Alan Shaw ", diff --git a/src/bitswap/stat.js b/src/bitswap/stat.js index de99bc4a..7dd12642 100644 --- a/src/bitswap/stat.js +++ b/src/bitswap/stat.js @@ -4,36 +4,35 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { expectIsBitswap } = require('../stats/utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() - describe('.bitswap.stat', () => { + describe('.bitswap.stat', function () { + this.timeout(60 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get bitswap stats', async () => { const res = await ipfs.bitswap.stat() expectIsBitswap(null, res) }) - it('should not get bitswap stats when offline', async function () { - this.timeout(60 * 1000) - - const node = await createCommon().setup() + it('should not get bitswap stats when offline', async () => { + const node = await common.spawn() await node.stop() - return expect(node.bitswap.stat()).to.eventually.be.rejected() + return expect(node.api.bitswap.stat()).to.eventually.be.rejected() }) }) } diff --git a/src/bitswap/wantlist.js b/src/bitswap/wantlist.js index 63ca125d..7a79ebf1 100644 --- a/src/bitswap/wantlist.js +++ b/src/bitswap/wantlist.js @@ -4,56 +4,47 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { waitForWantlistKey } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() - describe('.bitswap.wantlist', () => { + describe('.bitswap.wantlist', function () { + this.timeout(60 * 1000) let ipfsA let ipfsB const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfsA = await common.setup() - ipfsB = await common.setup() - + before(async () => { + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'go' })).api // Add key to the wantlist for ipfsB ipfsB.block.get(key).catch(() => {}) - await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(function () { - this.timeout(30 * 1000) - - return common.teardown() - }) + after(() => common.clean()) it('should get the wantlist', function () { - this.timeout(60 * 1000) return waitForWantlistKey(ipfsB, key) }) it('should get the wantlist by peer ID for a different node', function () { - this.timeout(60 * 1000) return waitForWantlistKey(ipfsA, key, { peerId: ipfsB.peerId.id, timeout: 60 * 1000 }) }) - it('should not get the wantlist when offline', async function () { - this.timeout(60 * 1000) - - const node = await createCommon().setup() + it('should not get the wantlist when offline', async () => { + const node = await common.spawn() await node.stop() - return expect(node.bitswap.wantlist()).to.eventually.be.rejected() + return expect(node.api.bitswap.stat()).to.eventually.be.rejected() }) }) } diff --git a/src/block/get.js b/src/block/get.js index e07e68d5..413654a1 100644 --- a/src/block/get.js +++ b/src/block/get.js @@ -5,26 +5,26 @@ const multihash = require('multihashes') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.block.get', () => { const data = Buffer.from('blorb') let ipfs, hash - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api const block = await ipfs.block.put(data) hash = block.cid.multihash }) - after(() => common.teardown()) + after(() => common.clean()) it('should get by CID object', async () => { const cid = new CID(hash) diff --git a/src/block/put.js b/src/block/put.js index ec8d3ffb..87745733 100644 --- a/src/block/put.js +++ b/src/block/put.js @@ -6,23 +6,23 @@ const multihash = require('multihashes') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.block.put', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should put a buffer, using defaults', async () => { const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' diff --git a/src/block/rm.js b/src/block/rm.js index e5fe1fe0..72665a5b 100644 --- a/src/block/rm.js +++ b/src/block/rm.js @@ -4,23 +4,21 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const hat = require('hat') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.block.rm', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should remove by CID object', async () => { const cid = await ipfs.dag.put(Buffer.from(hat()), { diff --git a/src/block/stat.js b/src/block/stat.js index baa7a66f..e2354b7e 100644 --- a/src/block/stat.js +++ b/src/block/stat.js @@ -4,26 +4,26 @@ const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.block.stat', () => { const data = Buffer.from('blorb') let ipfs, hash - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api const block = await ipfs.block.put(data) hash = block.cid.multihash }) - after(() => common.teardown()) + after(() => common.clean()) it('should stat by CID', async () => { const cid = new CID(hash) diff --git a/src/bootstrap/add.js b/src/bootstrap/add.js index c4a8440d..510888f6 100644 --- a/src/bootstrap/add.js +++ b/src/bootstrap/add.js @@ -6,25 +6,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.bootstrap.add', function () { this.timeout(100 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should return an error when called with an invalid arg', () => { return expect(ipfs.bootstrap.add(invalidArg)).to.eventually.be.rejected diff --git a/src/bootstrap/list.js b/src/bootstrap/list.js index 03392057..9dd335ef 100644 --- a/src/bootstrap/list.js +++ b/src/bootstrap/list.js @@ -3,25 +3,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.bootstrap.list', function () { this.timeout(100 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should return a list of peers', async () => { const res = await ipfs.bootstrap.list() diff --git a/src/bootstrap/rm.js b/src/bootstrap/rm.js index f8e20040..839eb499 100644 --- a/src/bootstrap/rm.js +++ b/src/bootstrap/rm.js @@ -3,10 +3,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -16,15 +20,9 @@ module.exports = (createCommon, options) => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should return an error when called with an invalid arg', () => { return expect(ipfs.bootstrap.rm(invalidArg)).to.eventually.be.rejected diff --git a/src/config/get.js b/src/config/get.js index 9470c1b6..7f8efeca 100644 --- a/src/config/get.js +++ b/src/config/get.js @@ -4,24 +4,22 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const isPlainObject = require('is-plain-object') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.config.get', function () { this.timeout(30 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should retrieve the whole config', async () => { const config = await ipfs.config.get() diff --git a/src/config/profiles/apply.js b/src/config/profiles/apply.js index ca0b9126..3466a716 100644 --- a/src/config/profiles/apply.js +++ b/src/config/profiles/apply.js @@ -2,25 +2,24 @@ 'use strict' const { getDescribe, getIt, expect } = require('../../utils/mocha') - -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.config.profiles.apply', function () { this.timeout(30 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should apply a config profile', async () => { const diff = await ipfs.config.profiles.apply('lowpower') diff --git a/src/config/profiles/list.js b/src/config/profiles/list.js index ffe57238..ca6187fb 100644 --- a/src/config/profiles/list.js +++ b/src/config/profiles/list.js @@ -2,25 +2,24 @@ 'use strict' const { getDescribe, getIt, expect } = require('../../utils/mocha') - -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.config.profiles.list', function () { this.timeout(30 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should list config profiles', async () => { const profiles = await ipfs.config.profiles.list() diff --git a/src/config/replace.js b/src/config/replace.js index 67496a7d..5fe2e4d5 100644 --- a/src/config/replace.js +++ b/src/config/replace.js @@ -2,25 +2,24 @@ 'use strict' const { getDescribe, getIt, expect } = require('../utils/mocha') - -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.config.replace', function () { this.timeout(30 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) const config = { Fruit: 'Bananas' diff --git a/src/config/set.js b/src/config/set.js index 1e29d923..fbb8ff35 100644 --- a/src/config/set.js +++ b/src/config/set.js @@ -2,25 +2,24 @@ 'use strict' const { getDescribe, getIt, expect } = require('../utils/mocha') - -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.config.set', function () { this.timeout(30 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should set a new key', async () => { await ipfs.config.set('Fruit', 'banana') diff --git a/src/dag/get.js b/src/dag/get.js index dc8ee9ee..67a25cda 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -9,23 +9,20 @@ const Unixfs = require('ipfs-unixfs') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dag.get', () => { let ipfs + before(async () => { ipfs = (await common.spawn()).api }) - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) let pbNode let cborNode diff --git a/src/dag/put.js b/src/dag/put.js index eb52106c..1dd03108 100644 --- a/src/dag/put.js +++ b/src/dag/put.js @@ -8,23 +8,21 @@ const CID = require('cids') const multihash = require('multihashes') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dag.put', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) let pbNode let cborNode diff --git a/src/dag/tree.js b/src/dag/tree.js index fe982620..36a20673 100644 --- a/src/dag/tree.js +++ b/src/dag/tree.js @@ -7,23 +7,21 @@ const DAGNode = dagPB.DAGNode const dagCBOR = require('ipld-dag-cbor') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dag.tree', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) + before(async () => { ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) let nodePb let nodeCbor diff --git a/src/dht/find-peer.js b/src/dht/find-peer.js index 5c6c3b4e..4237b0d4 100644 --- a/src/dht/find-peer.js +++ b/src/dht/find-peer.js @@ -3,10 +3,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dht.findPeer', function () { this.timeout(80 * 1000) @@ -14,21 +18,13 @@ module.exports = (createCommon, options) => { let nodeA let nodeB - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - nodeA = await common.setup() - nodeB = await common.setup() + before(async () => { + nodeA = (await common.spawn()).api + nodeB = (await common.spawn()).api await nodeB.swarm.connect(nodeA.peerId.addresses[0]) }) - after(function () { - this.timeout(50 * 1000) - - return common.teardown() - }) + after(() => common.clean()) it('should find other peers', async () => { const res = await nodeA.dht.findPeer(nodeB.peerId.id) diff --git a/src/dht/find-provs.js b/src/dht/find-provs.js index 9e301666..52787f6f 100644 --- a/src/dht/find-provs.js +++ b/src/dht/find-provs.js @@ -13,35 +13,32 @@ async function fakeCid () { return new CID(0, 'dag-pb', mh) } -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() - describe('.dht.findProvs', () => { + describe('.dht.findProvs', function () { + this.timeout(20000) let nodeA let nodeB let nodeC - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - nodeA = await common.setup() - nodeB = await common.setup() - nodeC = await common.setup() + before(async () => { + nodeA = (await common.spawn()).api + nodeB = (await common.spawn()).api + nodeC = (await common.spawn()).api await Promise.all([ nodeB.swarm.connect(nodeA.peerId.addresses[0]), nodeC.swarm.connect(nodeB.peerId.addresses[0]) ]) }) - after(function () { - this.timeout(50 * 1000) - - return common.teardown() - }) + after(() => common.clean()) let providedCid before('add providers for the same cid', async function () { diff --git a/src/dht/get.js b/src/dht/get.js index 0fe6df9e..356a4122 100644 --- a/src/dht/get.js +++ b/src/dht/get.js @@ -4,10 +4,14 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dht.get', function () { this.timeout(80 * 1000) @@ -15,21 +19,13 @@ module.exports = (createCommon, options) => { let nodeA let nodeB - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - nodeA = await common.setup() - nodeB = await common.setup() + before(async () => { + nodeA = (await common.spawn()).api + nodeB = (await common.spawn()).api await nodeA.swarm.connect(nodeB.peerId.addresses[0]) }) - after(function () { - this.timeout(50 * 1000) - - return common.teardown() - }) + after(() => common.clean()) it('should error when getting a non-existent key from the DHT', () => { return expect(nodeA.dht.get('non-existing', { timeout: 100 })).to.eventually.be.rejected diff --git a/src/dht/provide.js b/src/dht/provide.js index c4c6fafd..696f3aa7 100644 --- a/src/dht/provide.js +++ b/src/dht/provide.js @@ -4,31 +4,27 @@ const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dht.provide', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - const nodeB = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api + const nodeB = (await common.spawn()).api await ipfs.swarm.connect(nodeB.peerId.addresses[0]) }) - after(function () { - this.timeout(50 * 1000) - - return common.teardown() - }) + after(() => common.clean()) it('should provide local CID', async () => { const res = await ipfs.add(Buffer.from('test')) diff --git a/src/dht/put.js b/src/dht/put.js index 04a795c5..1f006cda 100644 --- a/src/dht/put.js +++ b/src/dht/put.js @@ -3,10 +3,14 @@ const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dht.put', function () { this.timeout(80 * 1000) @@ -14,17 +18,13 @@ module.exports = (createCommon, options) => { let nodeA let nodeB - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - nodeA = await common.setup() - nodeB = await common.setup() + before(async () => { + nodeA = (await common.spawn()).api + nodeB = (await common.spawn()).api await nodeA.swarm.connect(nodeB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should put a value to the DHT', async function () { this.timeout(80 * 1000) diff --git a/src/dht/query.js b/src/dht/query.js index 015147d4..f5fea5ec 100644 --- a/src/dht/query.js +++ b/src/dht/query.js @@ -4,10 +4,14 @@ const pTimeout = require('p-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dht.query', function () { this.timeout(80 * 1000) @@ -15,21 +19,13 @@ module.exports = (createCommon, options) => { let nodeA let nodeB - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - nodeA = await common.setup() - nodeB = await common.setup() + before(async () => { + nodeA = (await common.spawn()).api + nodeB = (await common.spawn()).api await nodeB.swarm.connect(nodeA.peerId.addresses[0]) }) - after(function () { - this.timeout(50 * 1000) - - return common.teardown() - }) + after(() => common.clean()) it('should return the other node in the query', async function () { const timeout = 150 * 1000 diff --git a/src/files-mfs/cp.js b/src/files-mfs/cp.js index 400fe88a..0515d83e 100644 --- a/src/files-mfs/cp.js +++ b/src/files-mfs/cp.js @@ -5,25 +5,23 @@ const hat = require('hat') const { fixtures } = require('../files-regular/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.cp', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should copy file, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/flush.js b/src/files-mfs/flush.js index fb53808c..54c74cdc 100644 --- a/src/files-mfs/flush.js +++ b/src/files-mfs/flush.js @@ -4,25 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.flush', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not flush not found file/dir, expect error', async () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/ls-pull-stream.js b/src/files-mfs/ls-pull-stream.js index 72f6563f..0674fa7b 100644 --- a/src/files-mfs/ls-pull-stream.js +++ b/src/files-mfs/ls-pull-stream.js @@ -5,25 +5,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.lsPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not ls not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/ls-readable-stream.js b/src/files-mfs/ls-readable-stream.js index c32cfd70..fab1c3ad 100644 --- a/src/files-mfs/ls-readable-stream.js +++ b/src/files-mfs/ls-readable-stream.js @@ -5,25 +5,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.lsReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not ls not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/ls.js b/src/files-mfs/ls.js index 0cf36c66..5497f49a 100644 --- a/src/files-mfs/ls.js +++ b/src/files-mfs/ls.js @@ -5,25 +5,23 @@ const hat = require('hat') const { fixtures } = require('../files-regular/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.ls', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not ls not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/mkdir.js b/src/files-mfs/mkdir.js index 4c2baf6b..0c35e5ec 100644 --- a/src/files-mfs/mkdir.js +++ b/src/files-mfs/mkdir.js @@ -4,25 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.mkdir', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should make directory on root', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/mv.js b/src/files-mfs/mv.js index fa54d598..d5c9bcc6 100644 --- a/src/files-mfs/mv.js +++ b/src/files-mfs/mv.js @@ -4,29 +4,27 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.mv', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) + before(async () => { ipfs = (await common.spawn()).api }) before(async () => { await ipfs.files.mkdir('/test/lv1/lv2', { parents: true }) await ipfs.files.write('/test/a', Buffer.from('Hello, world!'), { create: true }) }) - after(() => common.teardown()) + after(() => common.clean()) it('should not move not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/read-pull-stream.js b/src/files-mfs/read-pull-stream.js index 45b9af8d..ccd0c0f9 100644 --- a/src/files-mfs/read-pull-stream.js +++ b/src/files-mfs/read-pull-stream.js @@ -5,25 +5,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.readPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not read not found, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/read-readable-stream.js b/src/files-mfs/read-readable-stream.js index d8344ee1..c3f87101 100644 --- a/src/files-mfs/read-readable-stream.js +++ b/src/files-mfs/read-readable-stream.js @@ -5,25 +5,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.readReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not read not found, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/read.js b/src/files-mfs/read.js index 91c6e533..46467768 100644 --- a/src/files-mfs/read.js +++ b/src/files-mfs/read.js @@ -5,25 +5,23 @@ const hat = require('hat') const { fixtures } = require('../files-regular/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.read', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not read not found, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/rm.js b/src/files-mfs/rm.js index 9d13ca06..9a91e0d3 100644 --- a/src/files-mfs/rm.js +++ b/src/files-mfs/rm.js @@ -4,25 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.rm', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not remove not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/stat.js b/src/files-mfs/stat.js index b0619ea1..9640b30d 100644 --- a/src/files-mfs/stat.js +++ b/src/files-mfs/stat.js @@ -5,26 +5,24 @@ const hat = require('hat') const { fixtures } = require('../files-regular/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.stat', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) + before(async () => { ipfs = (await common.spawn()).api }) before(async () => { await ipfs.add(fixtures.smallFile.data) }) - after(() => common.teardown()) + after(() => common.clean()) it('should not stat not found file/dir, expect error', function () { const testDir = `/test-${hat()}` diff --git a/src/files-mfs/write.js b/src/files-mfs/write.js index f81a1a36..0fb3a72e 100644 --- a/src/files-mfs/write.js +++ b/src/files-mfs/write.js @@ -4,25 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.files.write', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should not write to non existent file, expect error', function () { const testDir = `/test-${hat()}` diff --git a/src/files-regular/add-from-fs.js b/src/files-regular/add-from-fs.js index dc5f892d..a20a0171 100644 --- a/src/files-regular/add-from-fs.js +++ b/src/files-regular/add-from-fs.js @@ -7,10 +7,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const fs = require('fs') const os = require('os') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.addFromFs', function () { this.timeout(40 * 1000) @@ -18,15 +22,9 @@ module.exports = (createCommon, options) => { const fixturesPath = path.join(__dirname, '../../test/fixtures') let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add a directory from the file system', async () => { const filesPath = path.join(fixturesPath, 'test-folder') diff --git a/src/files-regular/add-from-stream.js b/src/files-regular/add-from-stream.js index 9df66ee3..5762cb70 100644 --- a/src/files-regular/add-from-stream.js +++ b/src/files-regular/add-from-stream.js @@ -5,25 +5,23 @@ const { Readable } = require('readable-stream') const { getDescribe, getIt, expect } = require('../utils/mocha') const { fixtures } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.addFromStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add from a stream', async () => { const stream = new Readable({ diff --git a/src/files-regular/add-from-url.js b/src/files-regular/add-from-url.js index d1e68baa..0fa60577 100644 --- a/src/files-regular/add-from-url.js +++ b/src/files-regular/add-from-url.js @@ -5,25 +5,23 @@ const pTimeout = require('p-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') const { echoUrl, redirectUrl } = require('../utils/echo-http-server') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.addFromURL', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add from a HTTP URL', async () => { const text = `TEST${Date.now()}` diff --git a/src/files-regular/add-pull-stream.js b/src/files-regular/add-pull-stream.js index 9606e249..dd408114 100644 --- a/src/files-regular/add-pull-stream.js +++ b/src/files-regular/add-pull-stream.js @@ -6,25 +6,23 @@ const pull = require('pull-stream') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.addPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add pull stream of valid files and dirs', async function () { const content = (name) => ({ diff --git a/src/files-regular/add-readable-stream.js b/src/files-regular/add-readable-stream.js index 6b5d33ea..f2a32c87 100644 --- a/src/files-regular/add-readable-stream.js +++ b/src/files-regular/add-readable-stream.js @@ -5,25 +5,23 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.addReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add readable stream of valid files and dirs', async function () { const content = (name) => ({ diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 9faa3775..c1fbaaa7 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -8,25 +8,23 @@ const expectTimeout = require('../utils/expect-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') const { supportsFileReader } = require('ipfs-utils/src/supports') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.add', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) it('should add a File', async function () { if (!supportsFileReader) return this.skip('skip in node') diff --git a/src/files-regular/cat-pull-stream.js b/src/files-regular/cat-pull-stream.js index 18842d13..70b4cedc 100644 --- a/src/files-regular/cat-pull-stream.js +++ b/src/files-regular/cat-pull-stream.js @@ -5,26 +5,24 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.catPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) + before(async () => { ipfs = (await common.spawn()).api }) before(() => ipfs.add(fixtures.smallFile.data)) - after(() => common.teardown()) + after(() => common.clean()) it('should return a Pull Stream for a CID', async () => { const stream = ipfs.catPullStream(fixtures.smallFile.cid) diff --git a/src/files-regular/cat-readable-stream.js b/src/files-regular/cat-readable-stream.js index 17778b66..85a935c8 100644 --- a/src/files-regular/cat-readable-stream.js +++ b/src/files-regular/cat-readable-stream.js @@ -5,27 +5,27 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.catReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api await ipfs.add(fixtures.bigFile.data) await ipfs.add(fixtures.smallFile.data) }) - after(() => common.teardown()) + after(() => common.clean()) it('should return a Readable Stream for a CID', async () => { const stream = ipfs.catReadableStream(fixtures.bigFile.cid) diff --git a/src/files-regular/cat.js b/src/files-regular/cat.js index 41523adf..f3429759 100644 --- a/src/files-regular/cat.js +++ b/src/files-regular/cat.js @@ -6,25 +6,23 @@ const bs58 = require('bs58') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.cat', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) + before(async () => { ipfs = (await common.spawn()).api }) - ipfs = await common.setup() - }) - - after(() => common.teardown()) + after(() => common.clean()) before(() => Promise.all([ ipfs.add(fixtures.smallFile.data), diff --git a/src/files-regular/get-pull-stream.js b/src/files-regular/get-pull-stream.js index ee50075e..070ebfba 100644 --- a/src/files-regular/get-pull-stream.js +++ b/src/files-regular/get-pull-stream.js @@ -5,27 +5,25 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.getPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() - }) + before(async () => { ipfs = (await common.spawn()).api }) before(() => ipfs.add(fixtures.smallFile.data)) - after(() => common.teardown()) + after(() => common.clean()) it('should return a Pull Stream of Pull Streams', async () => { const stream = ipfs.getPullStream(fixtures.smallFile.cid) diff --git a/src/files-regular/get-readable-stream.js b/src/files-regular/get-readable-stream.js index ed1837bb..7a66915a 100644 --- a/src/files-regular/get-readable-stream.js +++ b/src/files-regular/get-readable-stream.js @@ -6,26 +6,26 @@ const through = require('through2') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.getReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api await ipfs.add(fixtures.smallFile.data) }) - after(() => common.teardown()) + after(() => common.clean()) it('should return a Readable Stream of Readable Streams', async () => { const stream = ipfs.getReadableStream(fixtures.smallFile.cid) diff --git a/src/files-regular/get.js b/src/files-regular/get.js index 8a940f2b..8f15d0a9 100644 --- a/src/files-regular/get.js +++ b/src/files-regular/get.js @@ -6,27 +6,27 @@ const bs58 = require('bs58') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.get', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api await ipfs.add(fixtures.smallFile.data) await ipfs.add(fixtures.bigFile.data) }) - after(() => common.teardown()) + after(() => common.clean()) it('should get with a base58 encoded multihash', async () => { const files = await ipfs.get(fixtures.smallFile.cid) diff --git a/src/files-regular/ls-pull-stream.js b/src/files-regular/ls-pull-stream.js index 8b9ff173..699574fa 100644 --- a/src/files-regular/ls-pull-stream.js +++ b/src/files-regular/ls-pull-stream.js @@ -5,25 +5,25 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const pullToPromise = require('pull-to-promise') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.lsPullStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should pull stream ls with a base58 encoded CID', async function () { const content = (name) => ({ diff --git a/src/files-regular/ls-readable-stream.js b/src/files-regular/ls-readable-stream.js index ccf27dc6..42e39fe0 100644 --- a/src/files-regular/ls-readable-stream.js +++ b/src/files-regular/ls-readable-stream.js @@ -5,25 +5,25 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.lsReadableStream', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should readable stream ls with a base58 encoded CID', async function () { const content = (name) => ({ diff --git a/src/files-regular/ls.js b/src/files-regular/ls.js index 6e32e6bc..4c365487 100644 --- a/src/files-regular/ls.js +++ b/src/files-regular/ls.js @@ -7,25 +7,25 @@ const CID = require('cids') const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.ls', function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should ls with a base58 encoded CID', async function () { const content = (name) => ({ diff --git a/src/files-regular/refs-local-tests.js b/src/files-regular/refs-local-tests.js index 6d5cda04..663a8e26 100644 --- a/src/files-regular/refs-local-tests.js +++ b/src/files-regular/refs-local-tests.js @@ -4,25 +4,27 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, suiteName, ipfsRefsLocal, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {*} suiteName + * @param {*} ipfsRefsLocal + * @param {Object} options + */ +module.exports = (common, suiteName, ipfsRefsLocal, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe(suiteName, function () { this.timeout(40 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get local refs', async function () { const content = (name) => ({ diff --git a/src/files-regular/refs-tests.js b/src/files-regular/refs-tests.js index 3725800d..d974614f 100644 --- a/src/files-regular/refs-tests.js +++ b/src/files-regular/refs-tests.js @@ -7,22 +7,24 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const loadFixture = require('aegir/fixtures') const CID = require('cids') -module.exports = (createCommon, suiteName, ipfsRefs, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {*} suiteName + * @param {*} ipfsRefs + * @param {Object} options + */ +module.exports = (common, suiteName, ipfsRefs, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe(suiteName, function () { this.timeout(40 * 1000) let ipfs, pbRootCb, dagRootCid - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) before(async function () { @@ -35,7 +37,7 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => { dagRootCid = cid }) - after(() => common.teardown()) + after(() => common.clean()) for (const [name, options] of Object.entries(getRefsTests())) { const { path, params, expected, expectError, expectTimeout } = options diff --git a/src/key/export.js b/src/key/export.js index 70d1588f..48fdb731 100644 --- a/src/key/export.js +++ b/src/key/export.js @@ -4,23 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.export', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should export "self" key', async function () { const pem = await ipfs.key.export('self', hat()) diff --git a/src/key/gen.js b/src/key/gen.js index 726cfdb0..c6afda3c 100644 --- a/src/key/gen.js +++ b/src/key/gen.js @@ -4,10 +4,14 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.gen', () => { const keyTypes = [ @@ -16,15 +20,11 @@ module.exports = (createCommon, options) => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) keyTypes.forEach((kt) => { it(`should generate a new ${kt.type} key`, async function () { diff --git a/src/key/import.js b/src/key/import.js index 4ed73ba3..8fc2162f 100644 --- a/src/key/import.js +++ b/src/key/import.js @@ -4,23 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.import', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should import an exported key', async () => { const password = hat() diff --git a/src/key/list.js b/src/key/list.js index b8b1af78..7cf88bef 100644 --- a/src/key/list.js +++ b/src/key/list.js @@ -5,23 +5,23 @@ const pTimes = require('p-times') const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.list', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should list all the keys', async function () { this.timeout(60 * 1000) diff --git a/src/key/rename.js b/src/key/rename.js index a3f5333c..d18c2a28 100644 --- a/src/key/rename.js +++ b/src/key/rename.js @@ -4,23 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.rename', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should rename a key', async function () { this.timeout(30 * 1000) diff --git a/src/key/rm.js b/src/key/rm.js index 3607b93a..8e86c1e4 100644 --- a/src/key/rm.js +++ b/src/key/rm.js @@ -4,23 +4,23 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.key.rm', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should rm a key', async function () { this.timeout(30 * 1000) diff --git a/src/miscellaneous/dns.js b/src/miscellaneous/dns.js index 9a68ea80..585557c1 100644 --- a/src/miscellaneous/dns.js +++ b/src/miscellaneous/dns.js @@ -3,25 +3,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.dns', function () { - this.timeout(10 * 1000) + this.timeout(60 * 1000) this.retries(3) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should non-recursively resolve ipfs.io', async () => { const res = await ipfs.dns('ipfs.io', { recursive: false }) diff --git a/src/miscellaneous/id.js b/src/miscellaneous/id.js index 2ba82464..3d25a045 100644 --- a/src/miscellaneous/id.js +++ b/src/miscellaneous/id.js @@ -3,20 +3,24 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.id', function () { this.timeout(60 * 1000) let ipfs before(async () => { - ipfs = await common.setup() + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get the node ID', async () => { const res = await ipfs.id() diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 6eb65819..ccf4851b 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -7,20 +7,24 @@ const hat = require('hat') const multibase = require('multibase') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.resolve', function () { this.timeout(60 * 1000) let ipfs before(async () => { - ipfs = await common.setup() + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should resolve an IPFS hash', async () => { const content = loadFixture('test/fixtures/testfile.txt', 'interface-ipfs-core') @@ -77,16 +81,8 @@ module.exports = (createCommon, options) => { it('should resolve IPNS link recursively', async function () { this.timeout(20 * 1000) - - // Ensure another node exists for publishing to - only required by go-ipfs - if (ipfs.peerId.agentVersion.includes('go-ipfs')) { - const node = await common.setup() - - // this fails in the browser because there is no relay node available to connect the two - // nodes, but we only need this for go-ipfs as it doesn't support the `allowOffline` flag yet - await ipfs.swarm.connect(node.peerId.addresses.find((a) => a.includes('127.0.0.1'))) - } - + const node = (await common.spawn({ type: 'go' })).api + await ipfs.swarm.connect(node.peerId.addresses[0]) const [{ path }] = await 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/miscellaneous/stop.js b/src/miscellaneous/stop.js index 58ee8bea..b6f3bd3b 100644 --- a/src/miscellaneous/stop.js +++ b/src/miscellaneous/stop.js @@ -3,21 +3,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() - describe('.stop', () => { - it('should stop the node', async function () { - this.timeout(10 * 1000) - const ipfs = await common.setup() + describe('.stop', function () { + this.timeout(60 * 1000) - await ipfs.stop() + it('should stop the node', async () => { + const ipfs = await common.spawn() + await ipfs.stop() // Trying to stop an already stopped node should return an error // as the node can't respond to requests anymore - return expect(ipfs.stop()).to.eventually.be.rejected() + return expect(ipfs.api.stop()).to.eventually.be.rejected() }) }) } diff --git a/src/miscellaneous/version.js b/src/miscellaneous/version.js index c38af691..82349177 100644 --- a/src/miscellaneous/version.js +++ b/src/miscellaneous/version.js @@ -3,23 +3,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.version', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get the node version', async () => { const result = await ipfs.version() diff --git a/src/name-pubsub/cancel.js b/src/name-pubsub/cancel.js index 2a887ca1..30cf5e81 100644 --- a/src/name-pubsub/cancel.js +++ b/src/name-pubsub/cancel.js @@ -6,25 +6,25 @@ const { promisify } = require('es6-promisify') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.name.pubsub.cancel', () => { let ipfs let nodeId - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api nodeId = ipfs.peerId.id }) - after(() => common.teardown()) + after(() => common.clean()) it('should return false when the name that is intended to cancel is not subscribed', async function () { this.timeout(60 * 1000) diff --git a/src/name-pubsub/state.js b/src/name-pubsub/state.js index 13ec1e08..01da8dba 100644 --- a/src/name-pubsub/state.js +++ b/src/name-pubsub/state.js @@ -3,23 +3,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.name.pubsub.state', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get the current state of pubsub', async function () { this.timeout(50 * 1000) diff --git a/src/name-pubsub/subs.js b/src/name-pubsub/subs.js index 1d3e2dd0..9b4764ff 100644 --- a/src/name-pubsub/subs.js +++ b/src/name-pubsub/subs.js @@ -3,23 +3,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.name.pubsub.subs', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get an empty array as a result of subscriptions before any resolve', async function () { this.timeout(60 * 1000) diff --git a/src/name/publish.js b/src/name/publish.js index 7c4733db..c40abf3a 100644 --- a/src/name/publish.js +++ b/src/name/publish.js @@ -6,27 +6,27 @@ const hat = require('hat') const { fixture } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.name.publish offline', () => { const keyName = hat() let ipfs let nodeId - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api nodeId = ipfs.peerId.id await ipfs.add(fixture.data, { pin: false }) }) - after(() => common.teardown()) + after(() => common.clean()) it('should publish an IPNS record with the default params', async function () { this.timeout(50 * 1000) diff --git a/src/name/resolve.js b/src/name/resolve.js index 94ff8249..d83d6845 100644 --- a/src/name/resolve.js +++ b/src/name/resolve.js @@ -5,21 +5,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') const CID = require('cids') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - describe('.name.resolve offline', () => { - const common = createCommon() + describe('.name.resolve offline', function () { let ipfs let nodeId before(async () => { - ipfs = await common.setup() + ipfs = (await common.spawn()).api nodeId = ipfs.peerId.id }) - after(() => common.teardown()) + after(() => common.clean()) it('should resolve a record default options', async function () { this.timeout(20 * 1000) @@ -127,15 +131,14 @@ module.exports = (createCommon, options) => { }) describe('.name.resolve dns', function () { - const common = createCommon() let ipfs this.retries(5) before(async () => { - ipfs = await common.setup() + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should resolve /ipns/ipfs.io', async () => { return expect(await ipfs.name.resolve('/ipns/ipfs.io')) diff --git a/src/object/data.js b/src/object/data.js index e2eeb515..4224b36d 100644 --- a/src/object/data.js +++ b/src/object/data.js @@ -5,25 +5,25 @@ const bs58 = require('bs58') const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.data', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get data by multihash', async () => { const testObj = { diff --git a/src/object/get.js b/src/object/get.js index c4f662df..5e7ecdf4 100644 --- a/src/object/get.js +++ b/src/object/get.js @@ -9,25 +9,25 @@ const UnixFs = require('ipfs-unixfs') const crypto = require('crypto') const { asDAGLink } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.get', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get object by multihash', async () => { const obj = { diff --git a/src/object/links.js b/src/object/links.js index 0770ef21..a3b3c45e 100644 --- a/src/object/links.js +++ b/src/object/links.js @@ -8,25 +8,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { asDAGLink } = require('./utils') const CID = require('cids') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.links', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get empty links by multihash', async () => { const testObj = { diff --git a/src/object/new.js b/src/object/new.js index 6f20522d..3faa3c05 100644 --- a/src/object/new.js +++ b/src/object/new.js @@ -3,25 +3,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.new', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should create a new object with no template', async () => { const cid = await ipfs.object.new() diff --git a/src/object/patch/add-link.js b/src/object/patch/add-link.js index 1e97a70b..cea45a53 100644 --- a/src/object/patch/add-link.js +++ b/src/object/patch/add-link.js @@ -6,25 +6,25 @@ const DAGNode = dagPB.DAGNode const { getDescribe, getIt, expect } = require('../../utils/mocha') const { asDAGLink } = require('../utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.patch.addLink', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should add a link to an existing node', async () => { const obj = { diff --git a/src/object/patch/append-data.js b/src/object/patch/append-data.js index 0364c12e..97b42c17 100644 --- a/src/object/patch/append-data.js +++ b/src/object/patch/append-data.js @@ -3,25 +3,25 @@ const { getDescribe, getIt, expect } = require('../../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.patch.appendData', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should append data to an existing node', async () => { const obj = { diff --git a/src/object/patch/rm-link.js b/src/object/patch/rm-link.js index f12ffefa..9ec9a7c4 100644 --- a/src/object/patch/rm-link.js +++ b/src/object/patch/rm-link.js @@ -4,25 +4,25 @@ const { getDescribe, getIt, expect } = require('../../utils/mocha') const { asDAGLink } = require('../utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.patch.rmLink', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should remove a link from an existing node', async () => { const obj1 = { diff --git a/src/object/patch/set-data.js b/src/object/patch/set-data.js index 1163b952..309a57a7 100644 --- a/src/object/patch/set-data.js +++ b/src/object/patch/set-data.js @@ -3,25 +3,25 @@ const { getDescribe, getIt, expect } = require('../../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.patch.setData', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should set data for an existing node', async () => { const obj = { diff --git a/src/object/put.js b/src/object/put.js index c1383e7f..e26c3bcc 100644 --- a/src/object/put.js +++ b/src/object/put.js @@ -7,25 +7,25 @@ const hat = require('hat') const { getDescribe, getIt, expect } = require('../utils/mocha') const { asDAGLink } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.put', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should put an object', async () => { const obj = { diff --git a/src/object/stat.js b/src/object/stat.js index 12c80b7d..25c60d27 100644 --- a/src/object/stat.js +++ b/src/object/stat.js @@ -6,25 +6,25 @@ const DAGNode = dagPB.DAGNode const { getDescribe, getIt, expect } = require('../utils/mocha') const { asDAGLink } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.object.stat', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get stats by multihash', async () => { const testObj = { diff --git a/src/pin/add.js b/src/pin/add.js index d8789080..1f2e9417 100644 --- a/src/pin/add.js +++ b/src/pin/add.js @@ -4,28 +4,27 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pin.add', function () { this.timeout(50 * 1000) let ipfs - - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api await Promise.all(fixtures.files.map(file => { return ipfs.add(file.data, { pin: false }) })) }) - after(() => common.teardown()) + after(() => common.clean()) it('should add a pin', async () => { const pinset = await ipfs.pin.add(fixtures.files[0].cid, { recursive: false }) diff --git a/src/pin/ls.js b/src/pin/ls.js index 47caed6c..780c3e3d 100644 --- a/src/pin/ls.js +++ b/src/pin/ls.js @@ -4,22 +4,22 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pin.ls', function () { this.timeout(50 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api // two files wrapped in directories, only root CID pinned recursively const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data })) await ipfs.add(dir, { pin: false, cidVersion: 0 }) @@ -32,7 +32,7 @@ module.exports = (createCommon, options) => { await ipfs.pin.add(fixtures.files[1].cid, { recursive: false }) }) - after(() => common.teardown()) + after(() => common.clean()) // 1st, because ipfs.add pins automatically it('should list all recursive pins', async () => { diff --git a/src/pin/rm.js b/src/pin/rm.js index 6be13eff..28ba073c 100644 --- a/src/pin/rm.js +++ b/src/pin/rm.js @@ -4,29 +4,28 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pin.rm', function () { this.timeout(50 * 1000) let ipfs - - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api await ipfs.add(fixtures.files[0].data, { pin: false }) await ipfs.pin.add(fixtures.files[0].cid, { recursive: true }) await ipfs.add(fixtures.files[1].data, { pin: false }) await ipfs.pin.add(fixtures.files[1].cid, { recursive: false }) }) - after(() => common.teardown()) + after(() => common.clean()) it('should remove a recursive pin', async () => { const removedPinset = await ipfs.pin.rm(fixtures.files[0].cid, { recursive: true }) diff --git a/src/ping/ping-pull-stream.js b/src/ping/ping-pull-stream.js index e9e65add..23c48077 100644 --- a/src/ping/ping-pull-stream.js +++ b/src/ping/ping-pull-stream.js @@ -5,10 +5,14 @@ const pullToPromise = require('pull-to-promise') const { getDescribe, getIt, expect } = require('../utils/mocha') const { isPong } = require('./utils.js') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pingPullStream', function () { this.timeout(60 * 1000) @@ -17,12 +21,12 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should send the specified number of packets over pull stream', async () => { const count = 3 diff --git a/src/ping/ping-readable-stream.js b/src/ping/ping-readable-stream.js index 3c69fc36..75b3ff84 100644 --- a/src/ping/ping-readable-stream.js +++ b/src/ping/ping-readable-stream.js @@ -6,10 +6,14 @@ const { Writable } = require('stream') const { getDescribe, getIt, expect } = require('../utils/mocha') const { isPong } = require('./utils.js') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pingReadableStream', function () { this.timeout(60 * 1000) @@ -18,12 +22,12 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should send the specified number of packets over readable stream', () => { let packetNum = 0 diff --git a/src/ping/ping.js b/src/ping/ping.js index 030a77f1..00e42b6c 100644 --- a/src/ping/ping.js +++ b/src/ping/ping.js @@ -4,10 +4,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { expectIsPingResponse, isPong } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.ping', function () { this.timeout(60 * 1000) @@ -15,17 +19,13 @@ module.exports = (createCommon, options) => { let ipfsA let ipfsB - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfsA = await common.setup() - ipfsB = await common.setup() + before(async () => { + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should send the specified number of packets', async () => { const count = 3 diff --git a/src/pubsub/ls.js b/src/pubsub/ls.js index daf2e358..85449bf0 100644 --- a/src/pubsub/ls.js +++ b/src/pubsub/ls.js @@ -5,23 +5,22 @@ const { getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pubsub.ls', function () { this.timeout(80 * 1000) let ipfs let subscribedTopics = [] - - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) afterEach(async () => { @@ -32,7 +31,7 @@ module.exports = (createCommon, options) => { await delay(100) }) - after(() => common.teardown()) + after(() => common.clean()) it('should return an empty list when no topics are subscribed', async () => { const topics = await ipfs.pubsub.ls() diff --git a/src/pubsub/peers.js b/src/pubsub/peers.js index 88bef2d6..22635fed 100644 --- a/src/pubsub/peers.js +++ b/src/pubsub/peers.js @@ -5,10 +5,14 @@ const { waitForPeers, getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pubsub.peers', function () { this.timeout(80 * 1000) @@ -17,15 +21,10 @@ module.exports = (createCommon, options) => { let ipfs2 let ipfs3 let subscribedTopics = [] - - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(100 * 1000) - - ipfs1 = await common.setup() - ipfs2 = await common.setup() - ipfs3 = await common.setup() + before(async () => { + ipfs1 = (await common.spawn()).api + ipfs2 = (await common.spawn({ type: 'go' })).api + ipfs3 = (await common.spawn({ type: 'go' })).api const ipfs2Addr = ipfs2.peerId.addresses.find((a) => a.includes('127.0.0.1')) const ipfs3Addr = ipfs3.peerId.addresses.find((a) => a.includes('127.0.0.1')) @@ -45,7 +44,7 @@ module.exports = (createCommon, options) => { await delay(100) }) - after(() => common.teardown()) + after(() => common.clean()) it('should not error when not subscribed to a topic', async () => { const topic = getTopic() diff --git a/src/pubsub/publish.js b/src/pubsub/publish.js index 3b8e93fc..f6359f58 100644 --- a/src/pubsub/publish.js +++ b/src/pubsub/publish.js @@ -5,25 +5,25 @@ const hat = require('hat') const { getTopic } = require('./utils') const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pubsub.publish', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should publish message from string', () => { const topic = getTopic() diff --git a/src/pubsub/subscribe.js b/src/pubsub/subscribe.js index 103aa937..f2b91faa 100644 --- a/src/pubsub/subscribe.js +++ b/src/pubsub/subscribe.js @@ -7,10 +7,14 @@ const { waitForPeers, getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pubsub.subscribe', function () { this.timeout(80 * 1000) @@ -20,13 +24,11 @@ module.exports = (createCommon, options) => { let topic let subscribedTopics = [] - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(100 * 1000) - - ipfs1 = await common.setup() - ipfs2 = await common.setup() + before(async () => { + ipfs1 = (await common.spawn()).api + // TODO 'multiple connected nodes' tests fails with go in Firefox + // and JS is flaky everywhere + ipfs2 = (await common.spawn({ type: 'go' })).api }) beforeEach(() => { @@ -44,7 +46,7 @@ module.exports = (createCommon, options) => { await delay(100) }) - after(() => common.teardown()) + after(() => common.clean()) describe('single node', () => { it('should subscribe to one topic', async () => { diff --git a/src/pubsub/unsubscribe.js b/src/pubsub/unsubscribe.js index 2fe522df..f58f9308 100644 --- a/src/pubsub/unsubscribe.js +++ b/src/pubsub/unsubscribe.js @@ -6,25 +6,25 @@ const { getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.pubsub.unsubscribe', function () { this.timeout(80 * 1000) let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) // Browser/worker has max ~5 open HTTP requests to the same origin const count = isBrowser || isWebWorker || isElectronRenderer ? 5 : 10 diff --git a/src/repo/gc.js b/src/repo/gc.js index 2c29c2de..861d062a 100644 --- a/src/repo/gc.js +++ b/src/repo/gc.js @@ -4,23 +4,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { DAGNode } = require('ipld-dag-pb') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.repo.gc', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should run garbage collection', async () => { const res = await ipfs.add(Buffer.from('apples')) diff --git a/src/repo/stat.js b/src/repo/stat.js index aaa7ad4b..ae9a0026 100644 --- a/src/repo/stat.js +++ b/src/repo/stat.js @@ -4,23 +4,23 @@ const { expectIsRepo } = require('../stats/utils') const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.repo.stat', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get repo stats', async () => { const res = await ipfs.repo.stat() diff --git a/src/repo/version.js b/src/repo/version.js index d8384e38..3010424c 100644 --- a/src/repo/version.js +++ b/src/repo/version.js @@ -3,23 +3,23 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.repo.version', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get the repo version', async () => { const version = await ipfs.repo.version() diff --git a/src/stats/bitswap.js b/src/stats/bitswap.js index 61bca7e6..3189cf22 100644 --- a/src/stats/bitswap.js +++ b/src/stats/bitswap.js @@ -4,23 +4,23 @@ const { getDescribe, getIt } = require('../utils/mocha') const { expectIsBitswap } = require('./utils') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.stats.bitswap', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get bitswap stats', async () => { const res = await ipfs.stats.bitswap() diff --git a/src/stats/bw-pull-stream.js b/src/stats/bw-pull-stream.js index 97d96193..f2329f32 100644 --- a/src/stats/bw-pull-stream.js +++ b/src/stats/bw-pull-stream.js @@ -5,23 +5,23 @@ const { expectIsBandwidth } = require('./utils') const pullToPromise = require('pull-to-promise') const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.stats.bwPullStream', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get bandwidth stats over pull stream', async () => { const stream = ipfs.stats.bwPullStream() diff --git a/src/stats/bw-readable-stream.js b/src/stats/bw-readable-stream.js index 50e0a8c0..2e6ed767 100644 --- a/src/stats/bw-readable-stream.js +++ b/src/stats/bw-readable-stream.js @@ -5,23 +5,23 @@ const { expectIsBandwidth } = require('./utils') const { getDescribe, getIt } = require('../utils/mocha') const getStream = require('get-stream') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.stats.bwReadableStream', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get bandwidth stats over readable stream', async () => { const stream = ipfs.stats.bwReadableStream() diff --git a/src/stats/bw.js b/src/stats/bw.js index 7994bca8..178eb5f9 100644 --- a/src/stats/bw.js +++ b/src/stats/bw.js @@ -4,23 +4,23 @@ const { expectIsBandwidth } = require('./utils') const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.stats.bw', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get bandwidth stats ', async () => { const res = await ipfs.stats.bw() diff --git a/src/stats/repo.js b/src/stats/repo.js index e6fae8d3..d6972d53 100644 --- a/src/stats/repo.js +++ b/src/stats/repo.js @@ -4,23 +4,23 @@ const { expectIsRepo } = require('./utils') const { getDescribe, getIt } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.stats.repo', () => { let ipfs - before(async function () { - // CI takes longer to instantiate the daemon, so we need to increase the - // timeout for the before step - this.timeout(60 * 1000) - - ipfs = await common.setup() + before(async () => { + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should get repo stats', async () => { const res = await ipfs.stats.repo() diff --git a/src/swarm/addrs.js b/src/swarm/addrs.js index 03196577..f7b7eeb4 100644 --- a/src/swarm/addrs.js +++ b/src/swarm/addrs.js @@ -4,10 +4,14 @@ const PeerInfo = require('peer-info') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.swarm.addrs', function () { this.timeout(80 * 1000) @@ -16,12 +20,12 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should get a list of node addresses', async () => { const peerInfos = await ipfsA.swarm.addrs() diff --git a/src/swarm/connect.js b/src/swarm/connect.js index 9de40265..21f501d6 100644 --- a/src/swarm/connect.js +++ b/src/swarm/connect.js @@ -3,10 +3,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.swarm.connect', function () { this.timeout(80 * 1000) @@ -14,11 +18,11 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should connect to a peer', async () => { let peers diff --git a/src/swarm/disconnect.js b/src/swarm/disconnect.js index 51551001..09f01a40 100644 --- a/src/swarm/disconnect.js +++ b/src/swarm/disconnect.js @@ -3,10 +3,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.swarm.disconnect', function () { this.timeout(80 * 1000) @@ -15,12 +19,12 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'js' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) }) - after(() => common.teardown()) + after(() => common.clean()) it('should disconnect from a peer', async () => { let peers diff --git a/src/swarm/local-addrs.js b/src/swarm/local-addrs.js index 0c534e6e..6ae57ce3 100644 --- a/src/swarm/local-addrs.js +++ b/src/swarm/local-addrs.js @@ -3,10 +3,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.swarm.localAddrs', function () { this.timeout(80 * 1000) @@ -14,10 +18,10 @@ module.exports = (createCommon, options) => { let ipfs before(async () => { - ipfs = await common.setup() + ipfs = (await common.spawn()).api }) - after(() => common.teardown()) + after(() => common.clean()) it('should list local addresses the node is listening on', async () => { const multiaddrs = await ipfs.swarm.localAddrs() diff --git a/src/swarm/peers.js b/src/swarm/peers.js index f37471c9..9fa23e24 100644 --- a/src/swarm/peers.js +++ b/src/swarm/peers.js @@ -6,10 +6,14 @@ const PeerId = require('peer-id') const delay = require('delay') const { getDescribe, getIt, expect } = require('../utils/mocha') -module.exports = (createCommon, options) => { +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - const common = createCommon() describe('.swarm.peers', function () { this.timeout(80 * 1000) @@ -18,13 +22,15 @@ module.exports = (createCommon, options) => { let ipfsB before(async () => { - ipfsA = await common.setup() - ipfsB = await common.setup() + ipfsA = (await common.spawn()).api + ipfsB = (await common.spawn({ type: 'go' })).api await ipfsA.swarm.connect(ipfsB.peerId.addresses[0]) - await delay(60 * 1000) // wait for open streams in the connection available + /* TODO: Seen if we still need this after this is fixed + https://github.com/ipfs/js-ipfs/issues/2601 gets resolved */ + // await delay(60 * 1000) // wait for open streams in the connection available }) - after(() => common.teardown()) + after(() => common.clean()) it('should list peers this node is connected to', async () => { const peers = await ipfsA.swarm.peers() @@ -80,10 +86,8 @@ module.exports = (createCommon, options) => { } it('should list peers only once', async () => { - const config = getConfig(['/ip4/127.0.0.1/tcp/0']) - - const nodeA = await common.setup({ spawnOptions: { config } }) - const nodeB = await common.setup({ spawnOptions: { config } }) + const nodeA = (await common.spawn()).api + const nodeB = (await common.spawn({ type: 'go' })).api await nodeA.swarm.connect(nodeB.peerId.addresses[0]) await delay(1000) const peersA = await nodeA.swarm.peers() @@ -99,11 +103,11 @@ module.exports = (createCommon, options) => { '/ip4/127.0.0.1/tcp/16544' ]) const configB = getConfig([ - '/ip4/127.0.0.1/tcp/26545', - '/ip4/127.0.0.1/tcp/26546' + '/ip4/127.0.0.1/tcp/26545/ws', + '/ip4/127.0.0.1/tcp/26546/ws' ]) - const nodeA = await common.setup({ spawnOptions: { config: configA } }) - const nodeB = await common.setup({ spawnOptions: { config: configB } }) + const nodeA = (await common.spawn({ ipfsOptions: { config: configA } })).api + const nodeB = (await common.spawn({ type: 'js', ipfsOptions: { config: configB } })).api await nodeA.swarm.connect(nodeB.peerId.addresses[0]) await delay(1000) const peersA = await nodeA.swarm.peers()