diff --git a/package.json b/package.json index 791fe0a2b..33f66d82e 100644 --- a/package.json +++ b/package.json @@ -84,8 +84,8 @@ "cross-env": "^6.0.0", "detect-node": "^2.0.4", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "^0.124.0", - "ipfsd-ctl": "^0.47.1", + "interface-ipfs-core": "~0.125.0", + "ipfsd-ctl": "^1.0.0", "ndjson": "^1.5.0", "nock": "^11.4.0", "pull-stream": "^3.6.14", diff --git a/test/commands.spec.js b/test/commands.spec.js index 2f7b1f5e3..9e68a1e01 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -2,30 +2,18 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.commands', function () { this.timeout(60 * 1000) - let ipfsd let ipfs before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('lists commands', async () => { const res = await ipfs.commands() diff --git a/test/constructor.spec.js b/test/constructor.spec.js index 60bfc9f33..a1a000c84 100644 --- a/test/constructor.spec.js +++ b/test/constructor.spec.js @@ -93,24 +93,18 @@ describe('ipfs-http-client constructor tests', () => { }) describe('integration', () => { - let apiAddr let ipfsd before(async function () { this.timeout(60 * 1000) // slow CI - ipfsd = await f.spawn({ initOptions: { bits: 1024, profile: 'test' } }) - apiAddr = ipfsd.apiAddr.toString() + ipfsd = await f.spawn() }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('can connect to an ipfs http api', async () => { - await clientWorks(ipfsClient(apiAddr)) + await clientWorks(ipfsClient(ipfsd.apiAddr)) }) }) }) diff --git a/test/dag.spec.js b/test/dag.spec.js index cd58002ad..de9217d13 100644 --- a/test/dag.spec.js +++ b/test/dag.spec.js @@ -6,29 +6,17 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const { DAGNode } = require('ipld-dag-pb') const CID = require('cids') -const ipfsClient = require('../src') const f = require('./utils/factory') -let ipfsd let ipfs describe('.dag', function () { this.timeout(20 * 1000) before(async function () { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('should be able to put and get a DAG node with format dag-pb', async () => { const data = Buffer.from('some data') diff --git a/test/diag.spec.js b/test/diag.spec.js index e42716214..37a1911e7 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -3,7 +3,6 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const platform = require('browser-process-platform') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.diag', function () { @@ -12,24 +11,13 @@ describe('.diag', function () { // go-ipfs does not support these on Windows if (platform === 'win32') { return } - let ipfsd let ipfs before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) describe('api API', () => { // Disabled in go-ipfs 0.4.10 diff --git a/test/files-mfs.spec.js b/test/files-mfs.spec.js index 6ae508d1d..0e3d6b1af 100644 --- a/test/files-mfs.spec.js +++ b/test/files-mfs.spec.js @@ -10,7 +10,6 @@ const values = require('pull-stream/sources/values') const pull = require('pull-stream/pull') const collect = require('pull-stream/sinks/collect') -const ipfsClient = require('../src') const f = require('./utils/factory') const expectTimeout = require('./utils/expect-timeout') @@ -31,26 +30,15 @@ const HASH_ALGS = [ describe('.files (the MFS API part)', function () { this.timeout(20 * 1000) - let ipfsd let ipfs const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('.add file for testing', async () => { const res = await ipfs.add(testfile) diff --git a/test/get.spec.js b/test/get.spec.js index 7c1a63e74..a6fb3aaa4 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -6,7 +6,6 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const loadFixture = require('aegir/fixtures') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.get (specific go-ipfs features)', function () { @@ -21,26 +20,14 @@ describe('.get (specific go-ipfs features)', function () { data: fixture('test/fixtures/testfile.txt') } - let ipfsd let ipfs before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) - + ipfs = (await f.spawn()).api await ipfs.add(smallFile.data) }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('no compression args', async () => { const files = await ipfs.get(smallFile.cid) diff --git a/test/interface.spec.js b/test/interface.spec.js index dc41ec325..5435518cf 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -2,47 +2,41 @@ 'use strict' const tests = require('interface-ipfs-core') -const isNode = require('detect-node') -const CommonFactory = require('./utils/interface-common-factory') +const merge = require('merge-options') +const { isNode } = require('ipfs-utils/src/env') +const { createFactory } = require('ipfsd-ctl') +const { findBin } = require('ipfsd-ctl/src/utils') const isWindows = process.platform && process.platform === 'win32' -describe('interface-ipfs-core tests', () => { - const defaultCommonFactory = CommonFactory.createAsync() - - tests.bitswap(defaultCommonFactory, { - skip: [ - // bitswap.stat - { - name: 'should not get bitswap stats when offline', - reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' - }, - // bitswap.wantlist - { - name: 'should not get the wantlist when offline', - reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' - }, - // bitswap.unwant - { - name: 'should remove a key from the wantlist', - reason: 'FIXME why is this skipped?' - }, - { - name: 'should not remove a key from the wantlist when offline', - reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' - } - ] - }) +/** @typedef {import("ipfsd-ctl").ControllerOptions} ControllerOptions */ - tests.block(defaultCommonFactory, { +describe('interface-ipfs-core tests', () => { + /** @type ControllerOptions */ + const commonOptions = { + test: true, + ipfsHttpModule: { + path: require.resolve('../src'), + ref: require('../src') + }, + ipfsOptions: { + pass: 'ipfs-is-awesome-software' + }, + ipfsBin: findBin('go') + } + const commonFactory = createFactory(commonOptions) + + tests.bitswap(commonFactory) + + tests.block(commonFactory, { skip: [{ name: 'should get a block added as CIDv1 with a CIDv0', reason: 'go-ipfs does not support the `version` param' }] }) - tests.bootstrap(defaultCommonFactory) + tests.bootstrap(commonFactory) - tests.config(defaultCommonFactory, { + tests.config(commonFactory, { skip: [ // config.replace { @@ -60,7 +54,7 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.dag(defaultCommonFactory, { + tests.dag(commonFactory, { skip: [ // dag.tree { @@ -87,7 +81,7 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.dht(defaultCommonFactory, { + tests.dht(commonFactory, { skip: [ // dht.findpeer { @@ -107,47 +101,47 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.filesRegular(defaultCommonFactory, { + tests.filesMFS(commonFactory, { skip: [ - // .addFromFs - isNode ? null : { - name: 'addFromFs', - reason: 'Not designed to run in the browser' - }, - // .catPullStream { - name: 'should export a chunk of a file', - reason: 'TODO not implemented in go-ipfs yet' + name: 'should ls directory with long option', + reason: 'TODO unskip when go-ipfs supports --long https://github.com/ipfs/go-ipfs/pull/6528' }, { - name: 'should export a chunk of a file in a Pull Stream', + name: 'should read from outside of mfs', reason: 'TODO not implemented in go-ipfs yet' }, { - name: 'should export a chunk of a file in a Readable Stream', + name: 'should ls from outside of mfs', reason: 'TODO not implemented in go-ipfs yet' } ] }) - tests.filesMFS(defaultCommonFactory, { + tests.filesRegular(commonFactory, { skip: [ + // .addFromFs + isNode ? null : { + name: 'addFromFs', + reason: 'Not designed to run in the browser' + }, + // .catPullStream { - name: 'should ls directory with long option', - reason: 'TODO unskip when go-ipfs supports --long https://github.com/ipfs/go-ipfs/pull/6528' + name: 'should export a chunk of a file', + reason: 'TODO not implemented in go-ipfs yet' }, { - name: 'should read from outside of mfs', + name: 'should export a chunk of a file in a Pull Stream', reason: 'TODO not implemented in go-ipfs yet' }, { - name: 'should ls from outside of mfs', + name: 'should export a chunk of a file in a Readable Stream', reason: 'TODO not implemented in go-ipfs yet' } ] }) - tests.key(defaultCommonFactory, { + tests.key(commonFactory, { skip: [ // key.export { @@ -162,21 +156,15 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.miscellaneous(defaultCommonFactory, { - skip: [ - // stop - { - name: 'should stop the node', - reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' - } - ] - }) + tests.miscellaneous(commonFactory) - tests.name(CommonFactory.createAsync({ - spawnOptions: { - args: ['--offline'] + tests.name(createFactory(merge(commonOptions, + { + ipfsOptions: { + offline: true + } } - }), { + )), { skip: [ // stop { @@ -186,12 +174,15 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.namePubsub(CommonFactory.createAsync({ - spawnOptions: { - args: ['--enable-namesys-pubsub'], - initOptions: { bits: 1024, profile: 'test' } + tests.namePubsub(createFactory(merge(commonOptions, + { + ipfsOptions: { + EXPERIMENTAL: { + ipnsPubsub: true + } + } } - }), { + )), { skip: [ // name.pubsub.cancel { @@ -206,11 +197,11 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.object(defaultCommonFactory) + tests.object(commonFactory) - tests.pin(defaultCommonFactory) + tests.pin(commonFactory) - tests.ping(defaultCommonFactory, { + tests.ping(commonFactory, { skip: [ { name: 'should fail when pinging an unknown peer over pull stream', @@ -227,10 +218,9 @@ describe('interface-ipfs-core tests', () => { ] }) - tests.pubsub(CommonFactory.createAsync({ - spawnOptions: { - args: ['--enable-pubsub-experiment'], - initOptions: { bits: 1024, profile: 'test' } + tests.pubsub(createFactory(commonOptions, { + go: { + args: ['--enable-pubsub-experiment'] } }), { skip: isWindows ? [ @@ -246,9 +236,9 @@ describe('interface-ipfs-core tests', () => { ] : null }) - tests.repo(defaultCommonFactory) + tests.repo(commonFactory) - tests.stats(defaultCommonFactory) + tests.stats(commonFactory) - tests.swarm(defaultCommonFactory) + tests.swarm(commonFactory) }) diff --git a/test/key.spec.js b/test/key.spec.js index 2e4e15714..180cb795b 100644 --- a/test/key.spec.js +++ b/test/key.spec.js @@ -1,32 +1,19 @@ /* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.key', function () { this.timeout(50 * 1000) - let ipfsd let ipfs before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) describe('.gen', () => { it('create a new rsa key', async () => { diff --git a/test/log.spec.js b/test/log.spec.js index 7f8e2c608..1a885028d 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -3,30 +3,18 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.log', function () { this.timeout(100 * 1000) - let ipfsd let ipfs before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('.log.tail', async () => { const i = setInterval(async () => { diff --git a/test/ping.spec.js b/test/ping.spec.js index 10c131b75..01636ed60 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -5,7 +5,6 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const pull = require('pull-stream/pull') const collect = require('pull-stream/sinks/collect') -const ipfsClient = require('../src') const f = require('./utils/factory') // Determine if a ping response object is a pong, or something else, like a status message @@ -17,29 +16,14 @@ describe('.ping', function () { this.timeout(20 * 1000) let ipfs - let ipfsd let other - let otherd let otherId before(async function () { this.timeout(30 * 1000) // slow CI - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) - - otherd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - other = otherd.api + ipfs = (await f.spawn()).api + other = (await f.spawn()).api const ma = (await ipfs.id()).addresses[0] await other.swarm.connect(ma) @@ -47,15 +31,7 @@ describe('.ping', function () { otherId = (await other.id()).id }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - - if (otherd) { - await otherd.stop() - } - }) + after(() => f.clean()) it('.ping with default count', async () => { const res = await ipfs.ping(otherId) diff --git a/test/repo.spec.js b/test/repo.spec.js index 84b5a42c3..21482135d 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -2,30 +2,18 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('.repo', function () { this.timeout(50 * 1000) // slow CI let ipfs - let ipfsd before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('.repo.gc', async () => { const res = await ipfs.repo.gc() diff --git a/test/stats.spec.js b/test/stats.spec.js index 0b7084d0a..d60aaa330 100644 --- a/test/stats.spec.js +++ b/test/stats.spec.js @@ -2,30 +2,18 @@ 'use strict' const { expect } = require('interface-ipfs-core/src/utils/mocha') -const ipfsClient = require('../src') const f = require('./utils/factory') describe('stats', function () { this.timeout(50 * 1000) // slow CI let ipfs - let ipfsd before(async () => { - ipfsd = await f.spawn({ - initOptions: { - bits: 1024, - profile: 'test' - } - }) - ipfs = ipfsClient(ipfsd.apiAddr) + ipfs = (await f.spawn()).api }) - after(async () => { - if (ipfsd) { - await ipfsd.stop() - } - }) + after(() => f.clean()) it('.stats.bitswap', async () => { const res = await ipfs.stats.bitswap() diff --git a/test/utils/factory.js b/test/utils/factory.js index aab6296fe..d6ac161ea 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -1,5 +1,15 @@ 'use strict' +const { createFactory } = require('ipfsd-ctl') +const { findBin } = require('ipfsd-ctl/src/utils') -const IPFSFactory = require('ipfsd-ctl') +const factory = createFactory({ + test: 'true', + type: 'go', + ipfsBin: findBin('go'), + ipfsHttpModule: { + path: require.resolve('../../src'), + ref: require('../../src') + } +}) -module.exports = IPFSFactory.create() +module.exports = factory diff --git a/test/utils/interface-common-factory.js b/test/utils/interface-common-factory.js deleted file mode 100644 index bd4720b6e..000000000 --- a/test/utils/interface-common-factory.js +++ /dev/null @@ -1,92 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const each = require('async/each') -const IPFSFactory = require('ipfsd-ctl') -const ipfsClient = require('../../src') -const merge = require('merge-options') - -const DEFAULT_FACTORY_OPTIONS = { - IpfsClient: ipfsClient -} - -function createFactory (options) { - options = options || {} - - options.factoryOptions = options.factoryOptions || { ...DEFAULT_FACTORY_OPTIONS } - options.spawnOptions = options.spawnOptions || { initOptions: { bits: 1024, profile: 'test' } } - - const ipfsFactory = IPFSFactory.create(options.factoryOptions) - - return function createCommon () { - const nodes = [] - let setup, teardown - - if (options.createSetup) { - setup = options.createSetup({ ipfsFactory, nodes }, options) - } else { - setup = (callback) => { - callback(null, { - spawnNode (cb) { - ipfsFactory.spawn(options.spawnOptions) - .then((ipfsd) => { - nodes.push(ipfsd) - setImmediate(() => cb(null, ipfsd.api)) - }) - .catch(err => { - setImmediate(() => cb(err)) - }) - } - }) - } - } - - if (options.createTeardown) { - teardown = options.createTeardown({ ipfsFactory, nodes }, options) - } else { - teardown = callback => each(nodes, (node, cb) => { - node - .stop() - .then(() => setImmediate(() => cb())) - .catch(err => setImmediate(() => cb(err))) - }, callback) - } - - return { setup, teardown } - } -} - -function createAsync (options = {}) { - return () => { - const nodes = [] - const setup = async (setupOptions = {}) => { - const ipfsFactory = IPFSFactory.create(merge( - options.factoryOptions ? {} : { ...DEFAULT_FACTORY_OPTIONS }, - setupOptions.factoryOptions, - options.factoryOptions - )) - const node = await ipfsFactory.spawn(merge( - setupOptions.spawnOptions, - options.spawnOptions || { initOptions: { profile: 'test' } } - )) - nodes.push(node) - - const id = await node.api.id() - node.api.peerId = id - - return node.api - } - - const teardown = () => { - return Promise.all(nodes.map(n => n.stop())) - } - return { - setup, - teardown - } - } -} -module.exports = { - createAsync, - create: createFactory -}