From b560d3319a88e2c98082dc64ea5dd97ec6370316 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Sat, 18 Mar 2017 12:14:54 +0100 Subject: [PATCH 1/4] update for new block interface --- src/api/block.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/api/block.js b/src/api/block.js index 73d745063..aa56b0e46 100644 --- a/src/api/block.js +++ b/src/api/block.js @@ -10,12 +10,19 @@ module.exports = (send) => { return { get: promisify((args, opts, callback) => { // TODO this needs to be adjusted with the new go-ipfs http-api + let cid if (CID.isCID(args)) { + cid = args args = multihash.toB58String(args.multihash) - } - if (Buffer.isBuffer(args)) { + } else if (Buffer.isBuffer(args)) { + cid = new CID(args) args = multihash.toB58String(args) + } else if (typeof args == 'string') { + cid = new CID(args) + } else { + return callback(new Error('invalid argument')) } + if (typeof opts === 'function') { callback = opts opts = {} @@ -24,13 +31,13 @@ module.exports = (send) => { // Transform the response from Buffer or a Stream to a Block const transform = (res, callback) => { if (Buffer.isBuffer(res)) { - callback(null, new Block(res)) + callback(null, new Block(res, cid)) } else { streamToValue(res, (err, data) => { if (err) { return callback(err) } - callback(null, new Block(data)) + callback(null, new Block(data, cid)) }) } } @@ -92,7 +99,9 @@ module.exports = (send) => { } // Transform the response to a Block - const transform = (blockInfo, callback) => callback(null, new Block(block)) + const transform = (info, callback) => { + callback(null, new Block(block, new CID(info.Key))) + } send.andTransform(request, transform, callback) }) From 9904a374c69640313e8a881962f0b71b0c752a45 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Sun, 19 Mar 2017 22:26:13 +0100 Subject: [PATCH 2/4] more fixes --- src/api/block.js | 32 ++++++++++++++++++-------------- src/request-api.js | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/api/block.js b/src/api/block.js index aa56b0e46..965f423d8 100644 --- a/src/api/block.js +++ b/src/api/block.js @@ -9,25 +9,29 @@ const streamToValue = require('../stream-to-value') module.exports = (send) => { return { get: promisify((args, opts, callback) => { - // TODO this needs to be adjusted with the new go-ipfs http-api - let cid - if (CID.isCID(args)) { - cid = args - args = multihash.toB58String(args.multihash) - } else if (Buffer.isBuffer(args)) { - cid = new CID(args) - args = multihash.toB58String(args) - } else if (typeof args == 'string') { - cid = new CID(args) - } else { - return callback(new Error('invalid argument')) - } - if (typeof opts === 'function') { callback = opts opts = {} } + // TODO this needs to be adjusted with the new go-ipfs http-api + let cid + try { + if (CID.isCID(args)) { + cid = args + args = multihash.toB58String(args.multihash) + } else if (Buffer.isBuffer(args)) { + cid = new CID(args) + args = multihash.toB58String(args) + } else if (typeof args === 'string') { + cid = new CID(args) + } else { + return callback(new Error('invalid argument')) + } + } catch (err) { + return callback(err) + } + // Transform the response from Buffer or a Stream to a Block const transform = (res, callback) => { if (Buffer.isBuffer(res)) { diff --git a/src/request-api.js b/src/request-api.js index b12e44cdd..6cb852fec 100644 --- a/src/request-api.js +++ b/src/request-api.js @@ -18,6 +18,7 @@ function parseError (res, cb) { if (err) { return cb(err) } + if (payload) { error.code = payload.Code error.message = payload.Message || payload.toString() From 4f7db946f4f808c26d8da0b564e5586b73bdf246 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 22 Mar 2017 14:47:21 +0000 Subject: [PATCH 3/4] chore: update deps --- package.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 97f82e5fa..5556d32d3 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "flatmap": "0.0.3", "glob": "^7.1.1", "glob-escape": "0.0.2", - "ipfs-block": "~0.5.5", + "ipfs-block": "~0.6.0", "ipfs-unixfs": "~0.1.11", - "ipld-dag-pb": "~0.10.1", + "ipld-dag-pb": "~0.11.0", "is-ipfs": "~0.3.0", "isstream": "^0.1.2", "lru-cache": "^4.0.2", @@ -60,12 +60,13 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^10.0.0", + "aegir": "^11.0.1", "chai": "^3.5.0", - "eslint-plugin-react": "^6.10.2", + "dirty-chai": "^1.2.2", + "eslint-plugin-react": "^6.10.3", "gulp": "^3.9.1", "hapi": "^16.1.0", - "interface-ipfs-core": "~0.25.1", + "interface-ipfs-core": "~0.26.0", "ipfsd-ctl": "~0.20.0", "pre-commit": "^1.2.2", "socket.io": "^1.7.3", From 97bc7e472e97e6bd81fcb5744d1858c05ed8c84e Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 22 Mar 2017 15:44:43 +0000 Subject: [PATCH 4/4] refactor: latest standard --- src/clean-multihash.js | 1 - src/get-files-stream.js | 4 +--- test/add.spec.js | 9 +++++--- test/bitswap.spec.js | 13 +++++++---- test/bootstrap.spec.js | 43 +++++++++++++++++++---------------- test/commands.spec.js | 14 ++++++++---- test/constructor.spec.js | 9 +++++--- test/diag.spec.js | 25 +++++++++++--------- test/files.spec.js | 49 +++++++++++++++++++++------------------- test/get.spec.js | 29 +++++++++++++----------- test/log.spec.js | 11 +++++---- test/ls.spec.js | 27 ++++++++++++---------- test/name.spec.js | 25 +++++++++++--------- test/ping.spec.js | 16 ++++++++----- test/refs.spec.js | 9 +++++--- test/repo.spec.js | 19 +++++++++------- test/request-api.spec.js | 7 ++++-- test/util.spec.js | 23 +++++++++++-------- 18 files changed, 190 insertions(+), 143 deletions(-) diff --git a/src/clean-multihash.js b/src/clean-multihash.js index 3de371b65..ff66af759 100644 --- a/src/clean-multihash.js +++ b/src/clean-multihash.js @@ -15,4 +15,3 @@ module.exports = function (multihash) { } return multihash } - diff --git a/src/get-files-stream.js b/src/get-files-stream.js index 17a65ad5e..c6f2c48df 100644 --- a/src/get-files-stream.js +++ b/src/get-files-stream.js @@ -46,7 +46,7 @@ function loadPaths (opts, file) { if (stats.isDirectory() && opts.recursive) { const globEscapedDir = escape(file) + (file.endsWith('/') ? '' : '/') - const mg = new glob.sync.GlobSync(`${globEscapedDir}**/*`, { + const mg = new glob.sync.GlobSync(`${globEscapedDir}` + '**/*', { follow: followSymlinks, dot: opts.hidden, ignore: (opts.ignore || []).map(function (ignoreGlob) { @@ -84,9 +84,7 @@ function loadPaths (opts, file) { dir: true } } - // files inside symlinks and others - return }) // filter out null files .filter(Boolean) diff --git a/test/add.spec.js b/test/add.spec.js index 1ca0c0b59..68f9fd529 100644 --- a/test/add.spec.js +++ b/test/add.spec.js @@ -2,7 +2,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const path = require('path') @@ -18,7 +21,7 @@ describe('.add (extra tests)', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -30,7 +33,7 @@ describe('.add (extra tests)', () => { const validPath = path.join(process.cwd() + '/package.json') ipfs.files.add(validPath, (err, res) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js index 41d7ffb7e..6ed821da3 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -1,7 +1,10 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') describe('.bitswap', () => { @@ -12,7 +15,7 @@ describe('.bitswap', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -25,7 +28,7 @@ describe('.bitswap', () => { describe('Callback API', () => { it('.wantlist', (done) => { ipfs.bitswap.wantlist((err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.to.be.eql({ Keys: null }) @@ -35,7 +38,7 @@ describe('.bitswap', () => { it('.stat', (done) => { ipfs.bitswap.stat((err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.property('BlocksReceived') expect(res).to.have.property('DupBlksReceived') expect(res).to.have.property('DupDataReceived') @@ -50,7 +53,7 @@ describe('.bitswap', () => { it('.unwant', (done) => { const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.bitswap.unwant(key, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() done() }) }) diff --git a/test/bootstrap.spec.js b/test/bootstrap.spec.js index 168a6cd14..041b069d9 100644 --- a/test/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -2,7 +2,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') const invalidArg = 'this/Is/So/Invalid/' @@ -16,7 +19,7 @@ describe('.bootstrap', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -39,10 +42,10 @@ describe('.bootstrap', () => { it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { ipfs.bootstrap.add(validIp4, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.be.eql({ Peers: [validIp4] }) peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(1) done() }) @@ -50,9 +53,9 @@ describe('.bootstrap', () => { it('returns a list of bootstrap peers when called with the default option', (done) => { ipfs.bootstrap.add({ default: true }, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.above(1) done() }) @@ -62,9 +65,9 @@ describe('.bootstrap', () => { describe('.list', () => { it('returns a list of peers', (done) => { ipfs.bootstrap.list((err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() done() }) }) @@ -80,9 +83,9 @@ describe('.bootstrap', () => { it('returns empty list because no peers removed when called without an arg or options', (done) => { ipfs.bootstrap.rm(null, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(0) done() }) @@ -90,9 +93,9 @@ describe('.bootstrap', () => { it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { ipfs.bootstrap.rm(null, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(0) done() }) @@ -100,9 +103,9 @@ describe('.bootstrap', () => { it('returns list of all peers removed when all option is passed', (done) => { ipfs.bootstrap.rm(null, { all: true }, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() done() }) }) @@ -130,7 +133,7 @@ describe('.bootstrap', () => { .then((res) => { expect(res).to.be.eql({ Peers: [validIp4] }) peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(1) }) }) @@ -139,7 +142,7 @@ describe('.bootstrap', () => { return ipfs.bootstrap.add(null, { default: true }) .then((res) => { peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.above(1) }) }) @@ -150,7 +153,7 @@ describe('.bootstrap', () => { return ipfs.bootstrap.list() .then((res) => { peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() }) }) }) @@ -167,7 +170,7 @@ describe('.bootstrap', () => { return ipfs.bootstrap.rm(null) .then((res) => { peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(0) }) }) @@ -176,7 +179,7 @@ describe('.bootstrap', () => { return ipfs.bootstrap.rm(null) .then((res) => { peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() expect(peers.length).to.eql(0) }) }) @@ -185,7 +188,7 @@ describe('.bootstrap', () => { return ipfs.bootstrap.rm(null, { all: true }) .then((res) => { peers = res.Peers - expect(peers).to.exist + expect(peers).to.exist() }) }) }) diff --git a/test/commands.spec.js b/test/commands.spec.js index b4ca05cd9..c5553d83b 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -1,7 +1,11 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + const FactoryClient = require('./ipfs-factory/client') describe('.commands', () => { @@ -12,7 +16,7 @@ describe('.commands', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -24,8 +28,8 @@ describe('.commands', () => { it('lists commands', (done) => { ipfs.commands((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() done() }) }) @@ -34,7 +38,7 @@ describe('.commands', () => { it('lists commands', () => { return ipfs.commands() .then((res) => { - expect(res).to.exist + expect(res).to.exist() }) }) }) diff --git a/test/constructor.spec.js b/test/constructor.spec.js index d46bc39f8..a210d1e36 100644 --- a/test/constructor.spec.js +++ b/test/constructor.spec.js @@ -1,14 +1,17 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +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/index.js') function clientWorks (client, done) { client.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(id).to.have.a.property('id') expect(id).to.have.a.property('publicKey') @@ -25,7 +28,7 @@ describe('ipfs-api constructor tests', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() apiAddr = node.apiAddr done() }) diff --git a/test/diag.spec.js b/test/diag.spec.js index e0d2afd13..1f3357c58 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -2,7 +2,10 @@ 'use strict' const FactoryClient = require('./ipfs-factory/client') -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) describe('.diag', () => { let ipfs @@ -12,7 +15,7 @@ describe('.diag', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -23,16 +26,16 @@ describe('.diag', () => { describe('Callback API', () => { it('.diag.net', (done) => { ipfs.diag.net((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() done() }) }) it('.diag.sys', (done) => { ipfs.diag.sys((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() expect(res).to.have.a.property('memory') expect(res).to.have.a.property('diskinfo') done() @@ -41,8 +44,8 @@ describe('.diag', () => { it('.diag.cmds', (done) => { ipfs.diag.cmds((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() done() }) }) @@ -51,13 +54,13 @@ describe('.diag', () => { describe('Promise API', () => { it('.diag.net', () => { return ipfs.diag.net() - .then((res) => expect(res).to.exist) + .then((res) => expect(res).to.exist()) }) it('.diag.sys', () => { return ipfs.diag.sys() .then((res) => { - expect(res).to.exist + expect(res).to.exist() expect(res).to.have.a.property('memory') expect(res).to.have.a.property('diskinfo') }) @@ -65,7 +68,7 @@ describe('.diag', () => { it('.diag.cmds', () => { return ipfs.diag.cmds() - .then((res) => expect(res).to.exist) + .then((res) => expect(res).to.exist()) }) }) }) diff --git a/test/files.spec.js b/test/files.spec.js index c93073a0c..ea1388ba4 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -2,7 +2,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const loadFixture = require('aegir/fixtures') @@ -20,7 +23,7 @@ describe('.files (the MFS API part)', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -33,7 +36,7 @@ describe('.files (the MFS API part)', () => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.add(testfile, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.length(1) expect(res[0].hash).to.equal(expectedMultihash) @@ -51,14 +54,14 @@ describe('.files (the MFS API part)', () => { '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file' ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() done() }) }) it('files.ls', (done) => { ipfs.files.ls('/test-folder', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res.Entries.length).to.equal(1) done() }) @@ -67,14 +70,14 @@ describe('.files (the MFS API part)', () => { it('files.write', (done) => { ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() let buf = '' stream - .on('error', (err) => expect(err).to.not.exist) + .on('error', (err) => expect(err).to.not.exist()) .on('data', (data) => { buf += data }) @@ -89,15 +92,15 @@ describe('.files (the MFS API part)', () => { it('files.write without options', (done) => { ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() let buf = '' stream .on('error', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) .on('data', (data) => { buf += data @@ -112,7 +115,7 @@ describe('.files (the MFS API part)', () => { it('files.stat', (done) => { ipfs.files.stat('/test-folder/test-file', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.deep.equal({ Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', Size: 12, @@ -125,9 +128,9 @@ describe('.files (the MFS API part)', () => { }) }) - it('files.stat file that does not exist', (done) => { - ipfs.files.stat('/test-folder/does-not-exist', (err, res) => { - expect(err).to.exist + it('files.stat file that does not exist()', (done) => { + ipfs.files.stat('/test-folder/does-not-exist()', (err, res) => { + expect(err).to.exist() if (err.code === 0) { return done() } @@ -141,11 +144,11 @@ describe('.files (the MFS API part)', () => { } ipfs.files.read('/test-folder/test-file', (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() let buf = '' stream .on('error', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) .on('data', (data) => { buf += data @@ -193,7 +196,7 @@ describe('.files (the MFS API part)', () => { let buf = '' stream .on('error', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) .on('data', (data) => { buf += data @@ -216,7 +219,7 @@ describe('.files (the MFS API part)', () => { let buf = '' stream .on('error', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) .on('data', (data) => { buf += data @@ -242,10 +245,10 @@ describe('.files (the MFS API part)', () => { }) }) - it('files.stat file that does not exist', () => { - return ipfs.files.stat('/test-folder/does-not-exist') + it('files.stat file that does not exist()', () => { + return ipfs.files.stat('/test-folder/does-not-exist()') .catch((err) => { - expect(err).to.exist + expect(err).to.exist() expect(err.code).to.be.eql(0) }) }) @@ -258,7 +261,7 @@ describe('.files (the MFS API part)', () => { let buf = '' stream .on('error', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) .on('data', (data) => { buf += data diff --git a/test/get.spec.js b/test/get.spec.js index 266068f95..b9e7e1307 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -3,7 +3,10 @@ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const fs = require('fs') const concat = require('concat-stream') @@ -30,7 +33,7 @@ describe('.get', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -43,7 +46,7 @@ describe('.get', () => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.add(testfile, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.length(1) expect(res[0].hash).to.equal(expectedMultihash) @@ -54,7 +57,7 @@ describe('.get', () => { it('get with no compression args', (done) => { ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() // accumulate the files and their content var files = [] @@ -79,7 +82,7 @@ describe('.get', () => { ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', { archive: true }, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() // accumulate the files and their content var files = [] @@ -105,7 +108,7 @@ describe('.get', () => { compress: true, 'compression-level': 10 }, (err, res) => { - expect(err).to.exist + expect(err).to.exist() expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9') done() }) @@ -116,7 +119,7 @@ describe('.get', () => { compress: true, 'compression-level': 1 }, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() done() }) }) @@ -128,7 +131,7 @@ describe('.get', () => { const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ipfs.files.add(bigFile, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.length(1) expect(res[0].path).to.equal(expectedMultihash) @@ -141,13 +144,13 @@ describe('.get', () => { if (!isNode) { return done() } ipfs.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => { - expect(err).to.not.exist + expect(err).to.not.exist() files.on('data', (file) => { // Do not blow out the memory of nodejs :) streamEqual(file.content, testfileBig, (err, equal) => { - expect(err).to.not.exist - expect(equal).to.be.true + expect(err).to.not.exist() + expect(equal).to.equal(true) done() }) }) @@ -162,7 +165,7 @@ describe('.get', () => { files.on('data', (file) => { let buf = '' file.content - .on('error', (err) => expect(err).to.not.exist) + .on('error', (err) => expect(err).to.not.exist()) .on('data', (data) => { buf += data.toString() }) @@ -173,7 +176,7 @@ describe('.get', () => { }) }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) }) }) diff --git a/test/log.spec.js b/test/log.spec.js index 121b18b1b..011a9f332 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -2,7 +2,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') describe('.log', () => { @@ -13,7 +16,7 @@ describe('.log', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -24,8 +27,8 @@ describe('.log', () => { describe('Callback API', () => { it('.log.tail', (done) => { const req = ipfs.log.tail((err, res) => { - expect(err).to.not.exist - expect(req).to.exist + expect(err).to.not.exist() + expect(req).to.exist() res.once('data', (obj) => { expect(obj).to.be.an('object') diff --git a/test/ls.spec.js b/test/ls.spec.js index 6876989e7..cc7a64195 100644 --- a/test/ls.spec.js +++ b/test/ls.spec.js @@ -1,7 +1,10 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const waterfall = require('async/waterfall') const path = require('path') @@ -38,7 +41,7 @@ describe('.ls', () => { describe('Callback API', () => { it('should correctly retrieve links', function (done) { ipfs.ls(folder, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.a.property('Objects') expect(res.Objects[0]).to.have.a.property('Links') @@ -47,18 +50,18 @@ describe('.ls', () => { }) }) - it('should correctly handle a nonexisting hash', function (done) { + it('should correctly handle a nonexist()ing hash', function (done) { ipfs.ls('surelynotavalidhashheh?', (err, res) => { - expect(err).to.exist - expect(res).to.not.exist + expect(err).to.exist() + expect(res).to.not.exist() done() }) }) - it('should correctly handle a nonexisting path', function (done) { + it('should correctly handle a nonexist()ing path', function (done) { ipfs.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => { - expect(err).to.exist - expect(res).to.not.exist + expect(err).to.exist() + expect(res).to.not.exist() done() }) }) @@ -74,14 +77,14 @@ describe('.ls', () => { }) }) - it('should correctly handle a nonexisting hash', () => { + it('should correctly handle a nonexist()ing hash', () => { return ipfs.ls('surelynotavalidhashheh?') - .catch((err) => expect(err).to.exist) + .catch((err) => expect(err).to.exist()) }) - it('should correctly handle a nonexisting path', () => { + it('should correctly handle a nonexist()ing path', () => { return ipfs.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there') - .catch((err) => expect(err).to.exist) + .catch((err) => expect(err).to.exist()) }) }) }) diff --git a/test/name.spec.js b/test/name.spec.js index 9e08fd035..c9fc68b87 100644 --- a/test/name.spec.js +++ b/test/name.spec.js @@ -1,7 +1,10 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const series = require('async/series') const loadFixture = require('aegir/fixtures') @@ -22,21 +25,21 @@ describe('.name', () => { series([ (cb) => { fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node cb() }) }, (cb) => { fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() other = node cb() }) }, (cb) => { ipfs.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() const ma = id.addresses[0] other.swarm.connect(ma, cb) }) @@ -53,7 +56,7 @@ describe('.name', () => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.add(testfile, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.length(1) expect(res[0].hash).to.equal(expectedMultihash) @@ -64,17 +67,17 @@ describe('.name', () => { it('.name.publish', (done) => { ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() name = res - expect(name).to.exist + expect(name).to.exist() done() }) }) it('.name.resolve', (done) => { ipfs.name.resolve(name.Name, (err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() expect(res).to.be.eql({ Path: name.Value }) @@ -90,14 +93,14 @@ describe('.name', () => { return ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((res) => { name = res - expect(name).to.exist + expect(name).to.exist() }) }) it('.name.resolve', () => { return ipfs.name.resolve(name.Name) .then((res) => { - expect(res).to.exist + expect(res).to.exist() expect(res).to.be.eql({ Path: name.Value }) diff --git a/test/ping.spec.js b/test/ping.spec.js index c46e591bd..af287431c 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -1,7 +1,11 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + const series = require('async/series') const FactoryClient = require('./ipfs-factory/client') @@ -16,7 +20,7 @@ describe.skip('.ping', () => { series([ (cb) => { fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node cb() }) @@ -24,14 +28,14 @@ describe.skip('.ping', () => { (cb) => { console.log('going to spawn second node') fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() other = node cb() }) }, (cb) => { ipfs.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() const ma = id.addresses[0] other.swarm.connect(ma, cb) }) @@ -44,10 +48,10 @@ describe.skip('.ping', () => { describe('callback API', () => { it('ping another peer', (done) => { other.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.ping(id.id, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.a.property('Success') expect(res).to.have.a.property('Time') expect(res).to.have.a.property('Text') diff --git a/test/refs.spec.js b/test/refs.spec.js index d4e0ff9da..7ca22d687 100644 --- a/test/refs.spec.js +++ b/test/refs.spec.js @@ -1,7 +1,10 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const waterfall = require('async/waterfall') const path = require('path') @@ -61,8 +64,8 @@ describe('.refs', () => { describe('Callback API', () => { it('refs', (done) => { - ipfs.refs(folder, {format: ' '}, (err, objs) => { - expect(err).to.not.exist + ipfs.refs(folder, { format: ' ' }, (err, objs) => { + expect(err).to.not.exist() expect(objs).to.eql(result) done() }) diff --git a/test/repo.spec.js b/test/repo.spec.js index 6558774ce..fef637e06 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -2,7 +2,10 @@ 'use strict' const FactoryClient = require('./ipfs-factory/client') -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) describe('.repo', () => { let ipfs @@ -12,7 +15,7 @@ describe('.repo', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -25,16 +28,16 @@ describe('.repo', () => { describe('Callback API', () => { it('.repo.gc', (done) => { ipfs.repo.gc((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() done() }) }) it('.repo.stat', (done) => { ipfs.repo.stat((err, res) => { - expect(err).to.not.exist - expect(res).to.exist + expect(err).to.not.exist() + expect(res).to.exist() expect(res).to.have.a.property('NumObjects') expect(res).to.have.a.property('RepoSize') done() @@ -44,13 +47,13 @@ describe('.repo', () => { describe('Promise API', () => { it('.repo.gc', () => { - return ipfs.repo.gc().then((res) => expect(res).to.exist) + return ipfs.repo.gc().then((res) => expect(res).to.exist()) }) it('.repo.stat', () => { return ipfs.repo.stat() .then((res) => { - expect(res).to.exist + expect(res).to.exist() expect(res).to.have.a.property('NumObjects') expect(res).to.have.a.property('RepoSize') }) diff --git a/test/request-api.spec.js b/test/request-api.spec.js index b19c9f23a..6588ccbbd 100644 --- a/test/request-api.spec.js +++ b/test/request-api.spec.js @@ -1,7 +1,10 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const ipfsAPI = require('../src/index.js') @@ -18,7 +21,7 @@ describe('\'deal with HTTP weirdness\' tests', () => { server.listen(6001, () => { ipfsAPI('/ip4/127.0.0.1/tcp/6001').config.replace('test/fixtures/r-config.json', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() server.close(done) }) }) diff --git a/test/util.spec.js b/test/util.spec.js index 0df41afc6..dadd2b4ee 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -2,7 +2,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const expect = require('chai').expect +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) const isNode = require('detect-node') const path = require('path') const fs = require('fs') @@ -18,7 +21,7 @@ describe('.util', () => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -33,7 +36,7 @@ describe('.util', () => { rs.path = '' // clean the path for testing purposes ipfs.util.addFromStream(rs, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.equal(1) done() }) @@ -43,7 +46,7 @@ describe('.util', () => { it('a directory', (done) => { const filesPath = path.join(__dirname, '/fixtures/test-folder') ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.be.above(8) done() }) @@ -52,7 +55,7 @@ describe('.util', () => { it('a directory with an odd name', (done) => { const filesPath = path.join(__dirname, '/fixtures/weird name folder [v0]') ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.be.above(8) done() }) @@ -61,7 +64,7 @@ describe('.util', () => { it('add and ignore a directory', (done) => { const filesPath = path.join(__dirname, '/fixtures/test-folder') ipfs.util.addFromFs(filesPath, { recursive: true, ignore: ['files/**'] }, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.be.below(9) done() }) @@ -70,7 +73,7 @@ describe('.util', () => { it('a file', (done) => { const filePath = path.join(__dirname, '/fixtures/testfile.txt') ipfs.util.addFromFs(filePath, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.be.equal(1) expect(result[0].path).to.be.equal('testfile.txt') done() @@ -80,7 +83,7 @@ describe('.util', () => { it('a hidden file in a directory', (done) => { const filesPath = path.join(__dirname, '/fixtures/test-folder') ipfs.util.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.be.above(10) expect(result.map(object => object.path)).to.include('test-folder/.hiddenTest.txt') expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') @@ -91,7 +94,7 @@ describe('.util', () => { it('.urlAdd http', (done) => { ipfs.util.addFromURL('http://example.com/', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.equal(1) done() }) @@ -99,7 +102,7 @@ describe('.util', () => { it('.urlAdd https', (done) => { ipfs.util.addFromURL('https://example.com/', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.length).to.equal(1) done() })