diff --git a/.aegir.js b/.aegir.js index 0e7eebbde7..7f287dd89d 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,12 @@ module.exports = { watched: false, served: true, included: false - }] + }], + browserNoActivityTimeout: 100 * 1000, + 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 ab520573ad..58ab6abdd8 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 35cd7a855f..46051e258d 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -5,86 +5,58 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) - - describe('Callback API', () => { - it('.wantlist', (done) => { - ipfs.bitswap.wantlist((err, res) => { - expect(err).to.not.exist() - expect(res).to.have.to.be.eql({ - Keys: null - }) - done() - }) - }) - - it('.stat', (done) => { - ipfs.bitswap.stat((err, res) => { - expect(err).to.not.exist() - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - - done() - }) - }) + after((done) => ipfsd.stop(done)) - it('.unwant', (done) => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - ipfs.bitswap.unwant(key, (err) => { - expect(err).to.not.exist() - done() + it('.wantlist', (done) => { + ipfs.bitswap.wantlist((err, res) => { + expect(err).to.not.exist() + expect(res).to.have.to.eql({ + Keys: null }) + done() }) }) - describe('Promise API', () => { - it('.wantlist', () => { - return ipfs.bitswap.wantlist() - .then((res) => { - expect(res).to.have.to.be.eql({ - Keys: null - }) - }) - }) + it('.stat', (done) => { + ipfs.bitswap.stat((err, res) => { + expect(err).to.not.exist() + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') - it('.stat', () => { - return ipfs.bitswap.stat() - .then((res) => { - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - }) + done() }) + }) - it('.unwant', () => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - return ipfs.bitswap.unwant(key) + it('.unwant', (done) => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + ipfs.bitswap.unwant(key, (err) => { + expect(err).to.not.exist() + done() }) }) }) diff --git a/test/bootstrap.spec.js b/test/bootstrap.spec.js index 65b0534853..4cc7e32213 100644 --- a/test/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -6,7 +6,11 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +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 +18,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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 5962d47fb3..5e2b3804d0 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -6,26 +6,27 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') +const IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 a210d1e369..46ef3fb3ef 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 ca88ba2255..5f68a3e954 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -1,13 +1,17 @@ /* 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 IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.diag', function () { this.timeout(50 * 1000) @@ -16,19 +20,19 @@ describe('.diag', function () { return } + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 c1ccc56d13..3a9425d56b 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -11,7 +11,10 @@ const loadFixture = require('aegir/fixtures') const mh = require('multihashes') const CID = require('cids') -const FactoryClient = require('./ipfs-factory/client') +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -32,21 +35,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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', function () { this.timeout(120 * 1000) diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link deleted file mode 100644 index 50b07e9e71..0000000000 --- a/test/fixtures/test-folder/hello-link +++ /dev/null @@ -1 +0,0 @@ -files/hello.txt \ No newline at end of file diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link new file mode 120000 index 0000000000..50b07e9e71 --- /dev/null +++ b/test/fixtures/test-folder/hello-link @@ -0,0 +1 @@ +files/hello.txt \ No newline at end of file diff --git a/test/get.spec.js b/test/get.spec.js index 008905bba7..3cd9e99c61 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -10,7 +10,11 @@ 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 IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.get (specific go-ipfs features)', function () { this.timeout(20 * 1000) @@ -24,23 +28,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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) cb() }), (cb) => ipfs.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) => { @@ -78,7 +81,9 @@ describe('.get (specific go-ipfs features)', function () { }) it('add path containing "+"s (for testing get)', (done) => { - if (!isNode) { return done() } + if (!isNode) { + return done() + } const filename = 'ti,c64x+mega++mod-pic.txt' const subdir = 'tmp/c++files' @@ -94,7 +99,9 @@ describe('.get (specific go-ipfs features)', function () { }) it('get path containing "+"s', (done) => { - if (!isNode) { return done() } + if (!isNode) { + return done() + } const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff' let count = 0 diff --git a/test/interface/block.spec.js b/test/interface/block.spec.js index ce96664dce..5a18830885 100644 --- a/test/interface/block.spec.js +++ b/test/interface/block.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let factory +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - factory.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/config.spec.js b/test/interface/config.spec.js index 0527c954e0..91f551a7da 100644 --- a/test/interface/config.spec.js +++ b/test/interface/config.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/dht.spec.js b/test/interface/dht.spec.js index b1e731e772..1ae3081fc4 100644 --- a/test/interface/dht.spec.js +++ b/test/interface/dht.spec.js @@ -2,17 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/files.spec.js b/test/interface/files.spec.js index 8170ce5977..c58b9d5e83 100644 --- a/test/interface/files.spec.js +++ b/test/interface/files.spec.js @@ -3,18 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') -const FactoryClient = require('../ipfs-factory/client') +const IPFSApi = require('../../src') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/generic.spec.js b/test/interface/generic.spec.js index 2e4403c60a..31a6e66e81 100644 --- a/test/interface/generic.spec.js +++ b/test/interface/generic.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/key.spec.js b/test/interface/key.spec.js index 1f285895de..6fd3510f57 100644 --- a/test/interface/key.spec.js +++ b/test/interface/key.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let factory +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - factory.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/object.spec.js b/test/interface/object.spec.js index ea127d09c4..be4ffa70c5 100644 --- a/test/interface/object.spec.js +++ b/test/interface/object.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/pin.spec.js b/test/interface/pin.spec.js index b841568ac7..d72d008b37 100644 --- a/test/interface/pin.spec.js +++ b/test/interface/pin.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/pubsub.spec.js b/test/interface/pubsub.spec.js index 5448ccc97b..4499bcbce1 100644 --- a/test/interface/pubsub.spec.js +++ b/test/interface/pubsub.spec.js @@ -3,19 +3,35 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') const isNode = require('detect-node') -if (isNode) { - let fc +const parallel = require('async/parallel') + +const IPFSApi = require('../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() +if (isNode) { + const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn({ args: ['--enable-pubsub-experiment'] }, + (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/swarm.spec.js b/test/interface/swarm.spec.js index 420f08543a..6d04fbcd81 100644 --- a/test/interface/swarm.spec.js +++ b/test/interface/swarm.spec.js @@ -3,17 +3,41 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (repoPath, config, cb) => { + if (typeof repoPath === 'function') { + cb = repoPath + repoPath = undefined + } + + if (typeof config === 'function') { + cb = config + config = undefined + } + + df.spawn({ repoPath, config }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/ipfs-factory/client.js b/test/ipfs-factory/client.js deleted file mode 100644 index a3df65e0e1..0000000000 --- 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 0d861c4027..0000000000 --- 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 31c60019aa..0000000000 --- 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 9f46633345..0000000000 --- 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 eca18f8f3e..0000000000 --- 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 f3bbaf7ef4..3db9a99535 100644 --- a/test/key.spec.js +++ b/test/key.spec.js @@ -2,30 +2,32 @@ /* 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 IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { describe('.gen', () => { @@ -61,13 +63,13 @@ describe('.key', function () { describe('Promise API', () => { describe('.gen', () => { it('create a new rsa key', () => { - return ipfs.key.gen('foobarsa2', {type: 'rsa', size: 2048}).then((res) => { + return ipfs.key.gen('foobarsa2', { type: 'rsa', size: 2048 }).then((res) => { expect(res).to.exist() }) }) it('create a new ed25519 key', () => { - return ipfs.key.gen('bazed2', {type: 'ed25519'}).then((res) => { + return ipfs.key.gen('bazed2', { type: 'ed25519' }).then((res) => { expect(res).to.exist() }) }) diff --git a/test/log.spec.js b/test/log.spec.js index 24d4fe11cf..38dc7d710b 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -6,24 +6,28 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 4e2330e51f..4cf1088f9b 100644 --- a/test/name.spec.js +++ b/test/name.spec.js @@ -5,10 +5,16 @@ 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 IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -18,28 +24,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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 +56,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 @@ -66,7 +79,8 @@ describe('.name', function () { }) }) - it('.name.publish', (done) => { + it('.name.publish', function (done) { + this.timeout(100 * 1000) ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { expect(err).to.not.exist() name = res @@ -88,7 +102,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 af287431cb..e2bcc44ffc 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -6,44 +6,56 @@ 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 IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 b6efe9f5c3..818b477bb9 100644 --- a/test/pubsub-in-browser.spec.js +++ b/test/pubsub-in-browser.spec.js @@ -26,29 +26,18 @@ /* 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 IPFSApi = require('../src') -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 DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +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 +48,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, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 +77,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 +87,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 +97,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 +109,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 +120,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 +131,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 +142,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 +154,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 b004db6de2..d6ca6572d4 100644 --- a/test/refs.spec.js +++ b/test/refs.spec.js @@ -8,20 +8,25 @@ 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 IPFSApi = require('../src') + +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,9 +39,10 @@ describe('.refs', function () { } waterfall([ - (cb) => fc.spawnNode(cb), - (node, cb) => { - ipfs = node + (cb) => df.spawn(cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) ipfs.util.addFromFs(filesPath, { recursive: true }, cb) }, (hashes, cb) => { @@ -47,7 +53,7 @@ describe('.refs', function () { ], done) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) const result = [ { @@ -86,7 +92,7 @@ describe('.refs', function () { describe('Promise API', () => { it('refs', () => { - return ipfs.refs(folder, {format: ' '}) + return ipfs.refs(folder, { format: ' ' }) .then((objs) => { expect(objs).to.eql(result) }) diff --git a/test/repo.spec.js b/test/repo.spec.js index 0af2a0001b..9507918deb 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -1,30 +1,32 @@ /* 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 IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) 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 8775d88ed9..1f16191573 100644 --- a/test/stats.spec.js +++ b/test/stats.spec.js @@ -1,113 +1,72 @@ /* 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 IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) - - describe('Callback API', () => { - it('.stats.bitswap', (done) => { - ipfs.stats.bitswap((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('provideBufLen') - expect(res).to.have.a.property('wantlist') - expect(res).to.have.a.property('peers') - expect(res).to.have.a.property('blocksReceived') - expect(res).to.have.a.property('dataReceived') - expect(res).to.have.a.property('blocksSent') - expect(res).to.have.a.property('dataSent') - expect(res).to.have.a.property('dupBlksReceived') - expect(res).to.have.a.property('dupDataReceived') - done() - }) - }) - - it('.stats.bw', (done) => { - ipfs.stats.bw((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('totalIn') - expect(res).to.have.a.property('totalOut') - expect(res).to.have.a.property('rateIn') - expect(res).to.have.a.property('rateOut') - done() - }) - }) + after((done) => ipfsd.stop(done)) - it('.stats.repo', (done) => { - ipfs.stats.repo((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - done() - }) + it('.stats.bitswap', (done) => { + ipfs.stats.bitswap((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('provideBufLen') + expect(res).to.have.a.property('wantlist') + expect(res).to.have.a.property('peers') + expect(res).to.have.a.property('blocksReceived') + expect(res).to.have.a.property('dataReceived') + expect(res).to.have.a.property('blocksSent') + expect(res).to.have.a.property('dataSent') + expect(res).to.have.a.property('dupBlksReceived') + expect(res).to.have.a.property('dupDataReceived') + done() }) }) - describe('Promise API', () => { - it('.stats.bw', () => { - return ipfs.stats.bw() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('totalIn') - expect(res).to.have.a.property('totalOut') - expect(res).to.have.a.property('rateIn') - expect(res).to.have.a.property('rateOut') - }) - }) - - it('.stats.repo', () => { - return ipfs.stats.repo() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - }) + it('.stats.bw', (done) => { + ipfs.stats.bw((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('totalIn') + expect(res).to.have.a.property('totalOut') + expect(res).to.have.a.property('rateIn') + expect(res).to.have.a.property('rateOut') + done() }) + }) - it('.stats.bitswap', () => { - return ipfs.stats.bitswap() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('provideBufLen') - expect(res).to.have.a.property('wantlist') - expect(res).to.have.a.property('peers') - expect(res).to.have.a.property('blocksReceived') - expect(res).to.have.a.property('dataReceived') - expect(res).to.have.a.property('blocksSent') - expect(res).to.have.a.property('dataSent') - expect(res).to.have.a.property('dupBlksReceived') - expect(res).to.have.a.property('dupDataReceived') - }) + it('.stats.repo', (done) => { + ipfs.stats.repo((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') + done() }) }) }) diff --git a/test/util.spec.js b/test/util.spec.js index e0a43d7d09..89b81414bd 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -9,26 +9,30 @@ chai.use(dirtyChai) const isNode = require('detect-node') const path = require('path') const fs = require('fs') -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +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, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('.streamAdd', (done) => { const tfpath = path.join(__dirname, '/fixtures/testfile.txt')