diff --git a/.aegir.js b/.aegir.js index 4765d7f7a6..93a928004c 100644 --- a/.aegir.js +++ b/.aegir.js @@ -4,11 +4,9 @@ const IPFSFactory = require('ipfsd-ctl') const MockPreloadNode = require('./test/utils/mock-preload-node') const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server') -const promisify = require('promisify-es6') - const ipfsdServer = IPFSFactory.createServer() -const preloadNode = promisify(MockPreloadNode.createNode()) -const echoServer = promisify(EchoServer.createServer()) +const preloadNode = MockPreloadNode.createNode() +const echoServer = EchoServer.createServer() module.exports = { bundlesize: { maxSize: '652kB' }, diff --git a/test/cli/dht.js b/test/cli/dht.js index 71b2012155..d593f7d079 100644 --- a/test/cli/dht.js +++ b/test/cli/dht.js @@ -3,33 +3,12 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const path = require('path') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - type: 'js', - IpfsClient: require('ipfs-http-client') -}) - +const factory = require('../utils/factory') const ipfsExec = require('../utils/ipfs-exec') -const daemonOpts = { - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } - } - }, - initOptions: { bits: 512 } -} - // TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994 describe.skip('dht', () => { + const df = factory({ type: 'js' }) const nodes = [] let ipfsA let ipfsB @@ -41,11 +20,11 @@ describe.skip('dht', () => { before(async function () { this.timeout(80 * 1000) - const ipfsdA = await df.spawn(daemonOpts) + const ipfsdA = await df.spawn() ipfsA = ipfsExec(ipfsdA.repoPath) nodes.push(ipfsdA) - const ipfsdB = await df.spawn(daemonOpts) + const ipfsdB = await df.spawn() ipfsB = ipfsExec(ipfsdB.repoPath) nodes.push(ipfsdB) }) @@ -71,7 +50,7 @@ describe.skip('dht', () => { return nodes[0].api.swarm.connect(multiaddrB) }) - after(() => Promise.all(nodes.map((node) => node.stop()))) + after(() => df.clean()) it('should be able to put a value to the dht and get it afterwards', async function () { this.timeout(60 * 1000) diff --git a/test/cli/name-pubsub.js b/test/cli/name-pubsub.js index fb7d02a645..900b9dee0b 100644 --- a/test/cli/name-pubsub.js +++ b/test/cli/name-pubsub.js @@ -3,34 +3,13 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') +const factory = require('../utils/factory') const path = require('path') const ipfsExec = require('../utils/ipfs-exec') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - type: 'js', - IpfsClient: require('ipfs-http-client') -}) - -const spawnDaemon = () => df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - args: ['--enable-namesys-pubsub'], - initOptions: { bits: 512 }, - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } - } - } -}) - describe('name-pubsub', () => { describe('enabled', () => { + const df = factory({ type: 'js', args: ['--enable-namesys-pubsub'] }) let ipfsA let ipfsB let nodeAId @@ -44,12 +23,12 @@ describe('name-pubsub', () => { // timeout for the before step this.timeout(80 * 1000) - const nodeA = await spawnDaemon() - ipfsA = ipfsExec(nodeA.repoPath) + const nodeA = await df.spawn() + ipfsA = ipfsExec(nodeA.path) nodes.push(nodeA) - const nodeB = await spawnDaemon() - ipfsB = ipfsExec(nodeB.repoPath) + const nodeB = await df.spawn() + ipfsB = ipfsExec(nodeB.path) nodes.push(nodeB) }) @@ -71,7 +50,7 @@ describe('name-pubsub', () => { expect(out).to.eql(`connect ${bMultiaddr} success\n`) }) - after(() => Promise.all(nodes.map((node) => node.stop()))) + after(() => df.clean()) describe('pubsub commands', () => { it('should get enabled state of pubsub', async function () { @@ -114,6 +93,7 @@ describe('name-pubsub', () => { }) describe('disabled', () => { + const df = factory({ type: 'js' }) let ipfsA let node @@ -123,19 +103,11 @@ describe('name-pubsub', () => { // timeout for the before step this.timeout(80 * 1000) - node = await df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config: {}, - initOptions: { bits: 512 } - }) + node = await df.spawn() ipfsA = ipfsExec(node.repoPath) }) - after(() => { - if (node) { - return node.stop() - } - }) + after(() => df.clean()) it('should get disabled state of pubsub', async function () { const res = await ipfsA('name pubsub state') diff --git a/test/cli/ping.js b/test/cli/ping.js index 66216fe0d2..ef59ce51e7 100644 --- a/test/cli/ping.js +++ b/test/cli/ping.js @@ -3,23 +3,8 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const DaemonFactory = require('ipfsd-ctl') +const factory = require('../utils/factory') const ipfsExec = require('../utils/ipfs-exec') -const path = require('path') -const df = DaemonFactory.create({ - type: 'js', - IpfsClient: require('ipfs-http-client') -}) - -const config = { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: - false - } - } -} describe('ping', function () { this.timeout(60 * 1000) @@ -28,15 +13,12 @@ describe('ping', function () { let bMultiaddr let ipfsdBId let cli + const df = factory({ type: 'js' }) before(async function () { this.timeout(60 * 1000) - ipfsdB = await df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }) + ipfsdB = await df.spawn() const peerInfo = await ipfsdB.api.id() ipfsdBId = peerInfo.id bMultiaddr = peerInfo.addresses[0] @@ -45,30 +27,17 @@ describe('ping', function () { before(async function () { this.timeout(60 * 1000) - ipfsdA = await df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }) + ipfsdA = await df.spawn() // Without DHT we need to have an already established connection await ipfsdA.api.swarm.connect(bMultiaddr) }) before(() => { this.timeout(60 * 1000) - cli = ipfsExec(ipfsdA.repoPath) + cli = ipfsExec(ipfsdA.path) }) - after(() => { - if (ipfsdA) { - return ipfsdA.stop() - } - }) - after(() => { - if (ipfsdB) { - return ipfsdB.stop() - } - }) + after(() => df.clean()) it('ping host', async () => { this.timeout(60 * 1000) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index 5255946ee1..4bf49c7b3a 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -6,23 +6,11 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const delay = require('delay') const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') -const IPFS = require('../../src') -const path = require('path') -const DaemonFactory = require('ipfsd-ctl') - -const config = { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: - false - } - } -} +const factory = require('../utils/factory') describe('pubsub', function () { this.timeout(80 * 1000) - + const df = factory() let node let ipfsdA let ipfsdB @@ -36,15 +24,7 @@ describe('pubsub', function () { before(async function () { this.timeout(60 * 1000) - const df = DaemonFactory.create({ - type: 'proc', - IpfsClient: require('ipfs-http-client') - }) - ipfsdA = await df.spawn({ - exec: IPFS, - initOptions: { bits: 512 }, - config - }) + ipfsdA = await df.spawn({ type: 'proc' }) node = ipfsdA.api }) @@ -55,17 +35,9 @@ describe('pubsub', function () { }) before(async () => { - const df = DaemonFactory.create({ - type: 'js', - IpfsClient: require('ipfs-http-client') - }) - ipfsdB = await df.spawn({ - initOptions: { bits: 512 }, - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config - }) + ipfsdB = await df.spawn({ type: 'js' }) httpApi = ipfsdB.api - httpApi.repoPath = ipfsdB.repoPath + httpApi.repoPath = ipfsdB.path }) after(() => { diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 2b3b08f017..9fac1ceadd 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -4,31 +4,15 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const sinon = require('sinon') -const ipfsExec = require('../utils/ipfs-exec') -const path = require('path') -const addrsCommand = require('../../src/cli/commands/swarm/addrs') - const multiaddr = require('multiaddr') const PeerInfo = require('peer-info') +const ipfsExec = require('../utils/ipfs-exec') const PeerId = require('peer-id') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - type: 'js', - IpfsClient: require('ipfs-http-client') -}) - -const config = { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: - false - } - } -} +const addrsCommand = require('../../src/cli/commands/swarm/addrs') +const factory = require('../utils/factory') describe('swarm', () => { + const df = factory({ type: 'js' }) afterEach(() => { sinon.restore() }) @@ -39,31 +23,21 @@ describe('swarm', () => { let bMultiaddr let ipfsA - const nodes = [] before(async function () { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(80 * 1000) const res = await Promise.all([ - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }), - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }) + df.spawn(), + df.spawn() ]) - ipfsA = ipfsExec(res[0].repoPath) + ipfsA = ipfsExec(res[0].path) const id = await res[1].api.id() bMultiaddr = id.addresses[0] - nodes.push(...res) }) - after(() => Promise.all(nodes.map((node) => node.stop()))) + after(() => df.clean()) it('connect', async () => { const out = await ipfsA(`swarm connect ${bMultiaddr}`) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index bff879b5ef..f64215e4f6 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -4,34 +4,40 @@ const tests = require('interface-ipfs-core') const { isNode } = require('ipfs-utils/src/env') const merge = require('merge-options') -const ctl = require('ipfsd-ctl') +const { createFactory } = require('ipfsd-ctl') const IPFS = require('../../src') -/** @ignore @typedef { import("ipfsd-ctl").FactoryOptions } FactoryOptions */ +/** @ignore @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */ describe('interface-ipfs-core tests', function () { - /** @type FactoryOptions */ + /** @type ControllerOptions */ const commonOptions = { + test: true, type: 'proc', - ipfsApi: { + ipfsModule: { path: require.resolve('../../src'), ref: IPFS }, - ipfsHttp: { + ipfsHttpModule: { path: require.resolve('ipfs-http-client'), ref: require('ipfs-http-client') }, - ipfsBin: './src/cli/bin.js' + ipfsOptions: { + pass: 'ipfs-is-awesome-software' + } + } + const overrides = { + js: { + ipfsBin: require.resolve('../../src/cli/bin.js') + } } - const commonFactory = ctl.createTestsInterface(commonOptions) + const commonFactory = createFactory(commonOptions, overrides) tests.bitswap(commonFactory, { - skip: [ - { - name: 'should get the wantlist by peer ID for a diffreent node', - reason: 'TODO: find the reason' - } - ] + skip: isNode ? null : [{ + name: 'should get the wantlist by peer ID for a different node', + reason: 'FIXME: Does not find wantlist list in the browser' + }] }) tests.block(commonFactory) @@ -60,32 +66,24 @@ describe('interface-ipfs-core tests', function () { tests.filesMFS(commonFactory) - tests.key(ctl.createTestsInterface(merge(commonOptions, { - ipfsOptions: { - pass: 'ipfs-is-awesome-software' - } - }))) + tests.key(commonFactory) - tests.miscellaneous(ctl.createTestsInterface(merge(commonOptions, { - ipfsOptions: { - pass: 'ipfs-is-awesome-software' - } - }))) + tests.miscellaneous(commonFactory) - tests.name(ctl.createTestsInterface(merge(commonOptions, { + tests.name(createFactory(merge(commonOptions, { ipfsOptions: { pass: 'ipfs-is-awesome-software', offline: true } - }))) + }), overrides)) - tests.namePubsub(ctl.createTestsInterface(merge(commonOptions, { + tests.namePubsub(createFactory(merge(commonOptions, { ipfsOptions: { EXPERIMENTAL: { ipnsPubsub: true } } - }))) + }), overrides)) tests.object(commonFactory, { skip: [ @@ -100,7 +98,11 @@ describe('interface-ipfs-core tests', function () { tests.ping(commonFactory) - tests.pubsub(commonFactory) + tests.pubsub(createFactory(merge(commonOptions, + { + args: ['--enable-pubsub-experiment'] + } + ), overrides)) tests.repo(commonFactory) diff --git a/test/utils/factory.js b/test/utils/factory.js new file mode 100644 index 0000000000..5deb0ba1f6 --- /dev/null +++ b/test/utils/factory.js @@ -0,0 +1,27 @@ +'use strict' +const { createFactory } = require('ipfsd-ctl') +const merge = require('merge-options') + +const factory = (options, overrides) => { + return createFactory( + merge({ + test: true, + type: 'proc', + ipfsModule: { + path: require.resolve('../../src'), + ref: require('../../src') + }, + ipfsHttpModule: { + path: require.resolve('ipfs-http-client'), + ref: require('ipfs-http-client') + }, + ipfsBin: require.resolve('../../src/cli/bin.js') + }, options), + merge({ + js: { + ipfsBin: require.resolve('../../src/cli/bin.js') + } + }, overrides) + ) +} +module.exports = factory diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index c88af2821c..94528c3adc 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -5,13 +5,9 @@ const hat = require('hat') const ipfsExec = require('../utils/ipfs-exec') const clean = require('../utils/clean') +const factory = require('./factory') const os = require('os') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ - IpfsClient: require('ipfs-http-client') -}) -const path = require('path') const origLocale = process.env.LC_ALL function off (tests) { @@ -46,6 +42,7 @@ function off (tests) { function on (tests) { describe('daemon on (through http-api)', function () { this.timeout(60 * 1000) + const df = factory({ type: 'js' }) const thing = { on: true } @@ -59,14 +56,9 @@ function on (tests) { // before step this.timeout(60 * 1000) - ipfsd = await df.spawn({ - type: 'js', - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - initOptions: { bits: 512 }, - config: { Bootstrap: [] } - }) - thing.ipfs = ipfsExec(ipfsd.repoPath) - thing.ipfs.repoPath = ipfsd.repoPath + ipfsd = await df.spawn() + thing.ipfs = ipfsExec(ipfsd.path) + thing.ipfs.repoPath = ipfsd.path }) after(function () {