diff --git a/.aegir.js b/.aegir.js index 0e7eebbde..15d99090e 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,7 +1,8 @@ 'use strict' -const factory = require('./test/ipfs-factory/tasks') +const createServer = require('ipfsd-ctl').createServer +const server = createServer() module.exports = { karma: { files: [{ @@ -9,10 +10,11 @@ module.exports = { watched: false, served: true, included: false - }] + }], + singleRun: true }, hooks: { - pre: factory.start, - post: factory.stop + pre: server.start.bind(server), + post: server.stop.bind(server) } } diff --git a/package.json b/package.json index ab520573a..58ab6abdd 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "http": "stream-http" }, "scripts": { - "test": "aegir test ", - "test:node": "aegir test -t node ", + "test": "aegir test", + "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", + "test:webworker": "aegir test -t webworker", "lint": "aegir lint", "build": "aegir build", "release": "aegir release ", @@ -65,10 +66,11 @@ "chai": "^4.1.2", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.5.1", + "go-ipfs-dep": "^0.4.13", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.40.0", + "interface-ipfs-core": "~0.41.0", "hapi": "^16.6.2", - "ipfsd-ctl": "~0.26.0", + "ipfsd-ctl": "~0.27.0", "pre-commit": "^1.2.2", "socket.io": "^2.0.4", "socket.io-client": "^2.0.4", diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js index 35cd7a855..ef4c18f23 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -5,26 +5,26 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.bitswap', function () { this.timeout(20 * 1000) // slow CI let ipfs - let fc + let ipfsd = null before((done) => { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { it('.wantlist', (done) => { diff --git a/test/bootstrap.spec.js b/test/bootstrap.spec.js index 65b053485..a0331ba8a 100644 --- a/test/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -6,7 +6,9 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -14,21 +16,19 @@ const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrS describe('.bootstrap', function () { this.timeout(100 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) let peers diff --git a/test/commands.spec.js b/test/commands.spec.js index 5962d47fb..09e8db6e7 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -6,26 +6,25 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.commands', function () { this.timeout(20 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) it('lists commands', (done) => { ipfs.commands((err, res) => { diff --git a/test/constructor.spec.js b/test/constructor.spec.js index a210d1e36..46ef3fb3e 100644 --- a/test/constructor.spec.js +++ b/test/constructor.spec.js @@ -5,7 +5,9 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const ipfsAPI = require('../src/index.js') @@ -22,19 +24,19 @@ function clientWorks (client, done) { describe('ipfs-api constructor tests', () => { describe('parameter permuations', () => { let apiAddr - let fc + let ipfsd before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - apiAddr = node.apiAddr + ipfsd = node + apiAddr = node.apiAddr.toString() done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('opts', (done) => { const splitted = apiAddr.split('/') diff --git a/test/diag.spec.js b/test/diag.spec.js index ca88ba225..f862693c5 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -1,13 +1,15 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const os = require('os') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.diag', function () { this.timeout(50 * 1000) @@ -16,19 +18,19 @@ describe('.diag', function () { return } + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { // Disabled in go-ipfs 0.4.10 diff --git a/test/files.spec.js b/test/files.spec.js index 6806643eb..93ddb8a31 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -11,7 +11,8 @@ const loadFixture = require('aegir/fixtures') const mh = require('multihashes') const CID = require('cids') -const FactoryClient = require('./ipfs-factory/client') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -32,21 +33,21 @@ const HASH_ALGS = [ describe('.files (the MFS API part)', function () { this.timeout(120 * 1000) + let ipfsd let ipfs - let fc const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', function () { this.timeout(120 * 1000) diff --git a/test/get.spec.js b/test/get.spec.js index 008905bba..4231a8c72 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -10,7 +10,9 @@ chai.use(dirtyChai) const isNode = require('detect-node') const series = require('async/series') const loadFixture = require('aegir/fixtures') -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.get (specific go-ipfs features)', function () { this.timeout(20 * 1000) @@ -24,23 +26,22 @@ describe('.get (specific go-ipfs features)', function () { data: fixture('../test/fixtures/testfile.txt') } + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - series([ - (cb) => fc.spawnNode((err, node) => { + (cb) => df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api cb() }), - (cb) => ipfs.files.add(smallFile.data, cb) + (cb) => ipfsd.api.files.add(smallFile.data, cb) ], done) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('no compression args', (done) => { ipfs.get(smallFile.cid, (err, files) => { diff --git a/test/interface/block.spec.js b/test/interface/block.spec.js index ce96664dc..76a305720 100644 --- a/test/interface/block.spec.js +++ b/test/interface/block.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) - }, - teardown: function (callback) { - factory.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/config.spec.js b/test/interface/config.spec.js index 0527c954e..64305131e 100644 --- a/test/interface/config.spec.js +++ b/test/interface/config.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/dht.spec.js b/test/interface/dht.spec.js index b1e731e77..202aa4dd6 100644 --- a/test/interface/dht.spec.js +++ b/test/interface/dht.spec.js @@ -2,17 +2,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/files.spec.js b/test/interface/files.spec.js index 8170ce597..9bf84fe25 100644 --- a/test/interface/files.spec.js +++ b/test/interface/files.spec.js @@ -4,17 +4,12 @@ const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') - -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/generic.spec.js b/test/interface/generic.spec.js index 2e4403c60..69d1f579d 100644 --- a/test/interface/generic.spec.js +++ b/test/interface/generic.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/key.spec.js b/test/interface/key.spec.js index 1f285895d..b7c8f2985 100644 --- a/test/interface/key.spec.js +++ b/test/interface/key.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) - }, - teardown: function (callback) { - factory.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/object.spec.js b/test/interface/object.spec.js index ea127d09c..affa0d6ae 100644 --- a/test/interface/object.spec.js +++ b/test/interface/object.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/pin.spec.js b/test/interface/pin.spec.js index b841568ac..d434dba77 100644 --- a/test/interface/pin.spec.js +++ b/test/interface/pin.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/pubsub.spec.js b/test/interface/pubsub.spec.js index 5448ccc97..0eeb0714f 100644 --- a/test/interface/pubsub.spec.js +++ b/test/interface/pubsub.spec.js @@ -3,19 +3,15 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') const isNode = require('detect-node') -if (isNode) { - let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() +if (isNode) { const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/interface/swarm.spec.js b/test/interface/swarm.spec.js index 420f08543..ebbeaeb01 100644 --- a/test/interface/swarm.spec.js +++ b/test/interface/swarm.spec.js @@ -3,17 +3,13 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/ipfs-factory/client.js b/test/ipfs-factory/client.js deleted file mode 100644 index a3df65e0e..000000000 --- a/test/ipfs-factory/client.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict' - -const io = require('socket.io-client') -const ipfsAPI = require('../../src') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - const sioOptions = { - transports: ['websocket'], - 'force new connection': true - } - const sioUrl = 'http://localhost:55155' - let sioConnected = false - let ioC - - this.spawnNode = (repoPath, config, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof config === 'function') { - callback = config - config = undefined - } - - if (sioConnected) { - spawnNode() - } else { - ioC = io.connect(sioUrl, sioOptions) - ioC.once('error', callback) - ioC.once('connect_error', callback) - ioC.once('connect', () => { - sioConnected = true - spawnNode() - }) - } - - function spawnNode () { - ioC.once('fc-node', (apiAddr) => { - const ipfs = ipfsAPI(apiAddr) - ipfs.apiAddr = apiAddr - callback(null, ipfs) - }) - ioC.emit('fs-spawn-node', repoPath, config) - } - } - - this.dismantle = function (callback) { - ioC.once('fc-nodes-shutdown', (err) => { - ioC.disconnect() - sioConnected = false - callback(err) - }) - ioC.emit('fs-dismantle') - } -} diff --git a/test/ipfs-factory/daemon-spawner.js b/test/ipfs-factory/daemon-spawner.js deleted file mode 100644 index 0d861c402..000000000 --- a/test/ipfs-factory/daemon-spawner.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict' - -const ipfsd = require('ipfsd-ctl') -const series = require('async/series') -const eachSeries = require('async/eachSeries') -const once = require('once') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - - let nodes = [] - - this.spawnNode = (repoPath, config, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof config === 'function') { - callback = config - config = undefined - } - - // TODO - // support custom repoPath - // support custom configs being passed - - spawnEphemeralNode((err, node) => { - if (err) { - return callback(err) - } - - nodes.push(node) - - callback(null, node.apiAddr) - }) - } - - this.dismantle = (callback) => { - eachSeries(nodes, (node, cb) => { - cb = once(cb) - node.stopDaemon(cb) - }, (err) => { - if (err) { - return callback(err) - } - - nodes = [] - - callback() - }) - } -} - -function spawnEphemeralNode (callback) { - ipfsd.disposable((err, node) => { - if (err) { - return callback(err) - } - - // Note: we have to set each config value - // independently since the config/replace endpoint - // doesn't work as expected - series([ - (cb) => { - const configValues = { - Bootstrap: [], - Discovery: {}, - 'API.HTTPHeaders.Access-Control-Allow-Origin': ['*'], - // This is not needed after all - // 'API.HTTPHeaders.Access-Control-Allow-Credentials': true, - 'API.HTTPHeaders.Access-Control-Allow-Methods': [ - 'PUT', - 'POST', - 'GET' - ] - } - - eachSeries(Object.keys(configValues), (configKey, cb) => { - const configVal = JSON.stringify(configValues[configKey]) - node.setConfig(configKey, configVal, cb) - }, cb) - }, - (cb) => node.startDaemon(['--enable-pubsub-experiment'], cb) - ], (err) => callback(err, node)) - }) -} diff --git a/test/ipfs-factory/server-routes.js b/test/ipfs-factory/server-routes.js deleted file mode 100644 index 31c60019a..000000000 --- a/test/ipfs-factory/server-routes.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict' - -const SocketIO = require('socket.io') -const DaemonSpawner = require('./daemon-spawner') - -module.exports = (http) => { - const io = new SocketIO(http.listener) - io.on('connection', handle) - io.on('error', (err) => this.emit('error', err)) - - const ds = new DaemonSpawner() - - function handle (socket) { - socket.on('fs-spawn-node', spawnNode.bind(socket)) - socket.on('fs-dismantle', dismantle.bind(socket)) - } - - function spawnNode (repoPath, config) { - ds.spawnNode(repoPath, config, (err, apiAddr) => { - if (err) { - return this.emit('error', err) - } - this.emit('fc-node', apiAddr.toString()) - }) - } - - function dismantle () { - ds.dismantle((err) => { - if (err) { - return this.emit('error', err) - } - this.emit('fc-nodes-shutdown') - }) - } -} diff --git a/test/ipfs-factory/server.js b/test/ipfs-factory/server.js deleted file mode 100644 index 9f4663334..000000000 --- a/test/ipfs-factory/server.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -const Hapi = require('hapi') - -const port = Number(process.env.PORT) || 55155 -const options = { - connections: { - routes: { - cors: true - } - } -} - -module.exports = (callback) => { - const http = new Hapi.Server(options) - - http.connection({ port: port }) - - http.start((err) => { - if (err) { - return callback(err) - } - require('./server-routes')(http) - - callback(null, http) - // note: http.stop(callback) to stop the server :) - }) -} diff --git a/test/ipfs-factory/tasks.js b/test/ipfs-factory/tasks.js deleted file mode 100644 index eca18f8f3..000000000 --- a/test/ipfs-factory/tasks.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -const factoryServer = require('./server') - -let factory - -module.exports = { - start (done) { - factoryServer((err, http) => { - if (err) { - return done(err) - } - factory = http - done() - }) - }, - stop (done) { - factory.stop({ - timeout: 1 - }, done) - } -} diff --git a/test/key.spec.js b/test/key.spec.js index f3bbaf7ef..652dd76c8 100644 --- a/test/key.spec.js +++ b/test/key.spec.js @@ -2,30 +2,30 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.key', function () { this.timeout(50 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { describe('.gen', () => { diff --git a/test/log.spec.js b/test/log.spec.js index 24d4fe11c..cdfb7f337 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -6,24 +6,26 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.log', function () { this.timeout(100 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', function () { this.timeout(100 * 1000) diff --git a/test/name.spec.js b/test/name.spec.js index 4e2330e51..d4b621e22 100644 --- a/test/name.spec.js +++ b/test/name.spec.js @@ -5,10 +5,14 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + +const parallel = require('async/parallel') const isNode = require('detect-node') const series = require('async/series') const loadFixture = require('aegir/fixtures') -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -18,28 +22,30 @@ describe('.name', function () { this.timeout(50 * 1000) let ipfs + let ipfsd let other - let fc + let otherd before((done) => { - fc = new FactoryClient() series([ (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api cb() }) }, (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - other = node + other = node.api + otherd = node cb() }) }, (cb) => { - ipfs.id((err, id) => { + ipfsd.api.id((err, id) => { expect(err).to.not.exist() const ma = id.addresses[0] other.swarm.connect(ma, cb) @@ -48,7 +54,12 @@ describe('.name', function () { ], done) }) - after((done) => fc.dismantle(done)) + after((done) => { + parallel([ + (cb) => ipfsd.stop(cb), + (cb) => otherd.stop(cb) + ], done) + }) describe('Callback API', () => { let name @@ -88,7 +99,8 @@ describe('.name', function () { describe('Promise API', () => { let name - it('.name.publish', () => { + it('.name.publish', function () { + this.timeout(80 * 1000) return ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((res) => { name = res diff --git a/test/ping.spec.js b/test/ping.spec.js index af287431c..bee554e48 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -6,44 +6,54 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const parallel = require('async/parallel') const series = require('async/series') -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe.skip('.ping', () => { let ipfs + let ipfsd let other - let fc + let otherd before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() series([ (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api cb() }) }, (cb) => { console.log('going to spawn second node') - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - other = node + other = node.api + otherd = node cb() }) }, (cb) => { - ipfs.id((err, id) => { + ipfsd.api.id((err, id) => { expect(err).to.not.exist() const ma = id.addresses[0] - other.swarm.connect(ma, cb) + other.api.swarm.connect(ma, cb) }) } ], done) }) - after((done) => fc.dismantle(done)) + after((done) => { + parallel([ + (cb) => ipfsd.stop(cb), + (cb) => otherd.stop(cb) + ], done) + }) describe('callback API', () => { it('ping another peer', (done) => { diff --git a/test/pubsub-in-browser.spec.js b/test/pubsub-in-browser.spec.js index b6efe9f5c..3e7dcc0f6 100644 --- a/test/pubsub-in-browser.spec.js +++ b/test/pubsub-in-browser.spec.js @@ -26,29 +26,16 @@ /* eslint max-nested-callbacks: ['error', 8] */ 'use strict' -const series = require('async/series') -const waterfall = require('async/waterfall') const isNode = require('detect-node') -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const expectedError = 'pubsub is currently not supported when run in the browser' +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() -function spawnWithId (factory, callback) { - waterfall([ - (cb) => factory.spawnNode(cb), - (node, cb) => node.id((err, res) => { - if (err) { - return cb(err) - } - node.peerId = res - cb(null, node) - }) - ], callback) -} +const expectedError = 'pubsub is currently not supported when run in the browser' describe('.pubsub-browser (pubsub not supported in the browsers currently)', function () { this.timeout(50 * 1000) @@ -59,33 +46,25 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun } const topic = 'pubsub-tests' - let factory - let ipfs1 + let ipfs + let ipfsd before((done) => { - factory = new FactoryClient() - - series([ - (cb) => spawnWithId(factory, cb) - ], (err, nodes) => { - if (err) { - return done(err) - } - - ipfs1 = nodes[0] + df.spawn((err, node) => { + expect(err).to.not.exist() + ipfs = node.api + ipfsd = node done() }) }) - after((done) => { - factory.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('everything errors', () => { describe('Callback API', () => { describe('.publish', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.publish(topic, 'hello friend', (err, topics) => { + ipfs.pubsub.publish(topic, 'hello friend', (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -96,7 +75,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.subscribe', () => { const handler = () => {} it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler, (err, topics) => { + ipfs.pubsub.subscribe(topic, {}, handler, (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -106,7 +85,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.peers', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic, (err, topics) => { + ipfs.pubsub.peers(topic, (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -116,7 +95,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.ls', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.ls((err, topics) => { + ipfs.pubsub.ls((err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -128,7 +107,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('Promise API', () => { describe('.publish', () => { it('throws an error if called in the browser', () => { - return ipfs1.pubsub.publish(topic, 'hello friend') + return ipfs.pubsub.publish(topic, 'hello friend') .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -139,7 +118,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.subscribe', () => { const handler = () => {} it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler) + ipfs.pubsub.subscribe(topic, {}, handler) .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -150,7 +129,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.peers', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic) + ipfs.pubsub.peers(topic) .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -161,7 +140,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.ls', () => { it('throws an error if called in the browser', () => { - return ipfs1.pubsub.ls() + return ipfs.pubsub.ls() .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -173,7 +152,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.unsubscribe', () => { it('throws an error if called in the browser', (done) => { try { - ipfs1.pubsub.unsubscribe() + ipfs.pubsub.unsubscribe() done('unsubscribe() didn\'t throw an error') } catch (err) { expect(err).to.exist() diff --git a/test/refs.spec.js b/test/refs.spec.js index b004db6de..0b0a406cd 100644 --- a/test/refs.spec.js +++ b/test/refs.spec.js @@ -8,20 +8,23 @@ chai.use(dirtyChai) const isNode = require('detect-node') const waterfall = require('async/waterfall') const path = require('path') -const FactoryClient = require('./ipfs-factory/client') const fs = require('fs') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.refs', function () { this.timeout(80 * 1000) - if (!isNode) { return } + if (!isNode) { + return + } let ipfs - let fc + let ipfsd let folder before((done) => { - fc = new FactoryClient() const filesPath = path.join(__dirname, '/fixtures/test-folder') // Symlinks in a repo don't always clone well, especially on Windows. @@ -34,10 +37,11 @@ describe('.refs', function () { } waterfall([ - (cb) => fc.spawnNode(cb), + (cb) => df.spawn(cb), (node, cb) => { - ipfs = node - ipfs.util.addFromFs(filesPath, { recursive: true }, cb) + ipfsd = node + ipfs = node.api + ipfsd.api.util.addFromFs(filesPath, { recursive: true }, cb) }, (hashes, cb) => { folder = hashes[hashes.length - 1].hash @@ -47,7 +51,7 @@ describe('.refs', function () { ], done) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) const result = [ { diff --git a/test/repo.spec.js b/test/repo.spec.js index 0af2a0001..aa044f606 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -1,30 +1,30 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.repo', function () { this.timeout(50 * 1000) // slow CI let ipfs - let fc + let ipfsd before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { it('.repo.gc', (done) => { diff --git a/test/stats.spec.js b/test/stats.spec.js index 8775d88ed..67bf6b360 100644 --- a/test/stats.spec.js +++ b/test/stats.spec.js @@ -1,30 +1,30 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('stats', function () { this.timeout(50 * 1000) // slow CI let ipfs - let fc + let ipfsd before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { it('.stats.bitswap', (done) => { diff --git a/test/util.spec.js b/test/util.spec.js index e0a43d7d0..184f3c15b 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -9,26 +9,28 @@ chai.use(dirtyChai) const isNode = require('detect-node') const path = require('path') const fs = require('fs') -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.util', () => { if (!isNode) { return } + let ipfsd let ipfs - let fc before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('.streamAdd', (done) => { const tfpath = path.join(__dirname, '/fixtures/testfile.txt')