From 0c09622922be605434179499196ee257511d1e3e Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Sat, 18 Mar 2017 10:40:58 +0100 Subject: [PATCH 1/3] update block tests --- src/block.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/block.js b/src/block.js index 8cc289064..994516655 100644 --- a/src/block.js +++ b/src/block.js @@ -9,13 +9,8 @@ const multihash = require('multihashes') const CID = require('cids') function expectKey (block, expected, callback) { - block.key((err, key) => { - if (err) { - return callback(err) - } - expect(key).to.be.eql(expected) - callback() - }) + expect(block.cid.multihash).to.be.eql(expected) + callback() } module.exports = (common) => { @@ -44,11 +39,11 @@ module.exports = (common) => { it('.put a buffer', (done) => { const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' const cid = new CID(expectedHash) - const blob = Buffer('blorb') + const blob = new Buffer('blorb') - ipfs.block.put(blob, cid, (err, block) => { + ipfs.block.put(blob, (err, block) => { expect(err).to.not.exist - expect(block).to.have.a.property('data', blob) + expect(block.data).to.be.eql(blob) expectKey(block, multihash.fromB58String(expectedHash), done) }) }) @@ -56,9 +51,9 @@ module.exports = (common) => { it('.put a block', (done) => { const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' const cid = new CID(expectedHash) - const blob = new Block(new Buffer('blorb')) + const blob = new Block(new Buffer('blorb'), cid) - ipfs.block.put(blob, cid, (err, block) => { + ipfs.block.put(blob, (err, block) => { expect(err).to.not.exist expect(block.data).to.eql(new Buffer('blorb')) expectKey(block, multihash.fromB58String(expectedHash), done) @@ -67,7 +62,7 @@ module.exports = (common) => { it('.put a block (without using CID, legacy mode)', (done) => { const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' - const blob = new Block(new Buffer('blorb')) + const blob = new Block(new Buffer('blorb'), new CID(expectedHash)) ipfs.block.put(blob, (err, block) => { expect(err).to.not.exist @@ -79,7 +74,7 @@ module.exports = (common) => { it('.put error with array of blocks', (done) => { const blob = Buffer('blorb') - ipfs.block.put([blob, blob], 'fake cids', (err) => { + ipfs.block.put([blob, blob], (err) => { expect(err).to.be.an.instanceof(Error) done() }) From 5ff02c543da73145156c072e9a560f2c83e7175c Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 22 Mar 2017 14:38:12 +0000 Subject: [PATCH 2/3] chore: update deps --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index af2d6cb57..9dd289b6b 100644 --- a/package.json +++ b/package.json @@ -30,19 +30,19 @@ "bl": "^1.2.0", "bs58": "^4.0.0", "chai": "^3.5.0", - "cids": "^0.4.1", + "cids": "^0.4.2", "concat-stream": "^1.6.0", "detect-node": "^2.0.3", - "ipfs-block": "^0.5.5", - "ipld-dag-cbor": "^0.10.0", - "ipld-dag-pb": "^0.10.0", - "multiaddr": "^2.2.1", - "multihashes": "^0.4.3", + "ipfs-block": "^0.6.0", + "ipld-dag-cbor": "^0.11.0", + "ipld-dag-pb": "^0.11.0", + "multiaddr": "^2.2.2", + "multihashes": "^0.4.4", "pull-stream": "^3.5.0", - "readable-stream": "1.1.14" + "readable-stream": "2.2.6" }, "devDependencies": { - "aegir": "^10.0.0" + "aegir": "^11.0.1" }, "contributors": [ "David Dias ", @@ -55,4 +55,4 @@ "haad ", "nginnever " ] -} \ No newline at end of file +} From 01aee295641f87b7b06ceaf4b7e26a761fbc0fb4 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 22 Mar 2017 14:42:56 +0000 Subject: [PATCH 3/3] refactor: upgrade to latest standard --- package.json | 3 +- src/block.js | 23 ++++---- src/config.js | 55 +++++++++--------- src/dag.js | 75 +++++++++++++------------ src/dht.js | 27 +++++---- src/files.js | 53 +++++++++--------- src/generic.js | 13 +++-- src/object.js | 147 +++++++++++++++++++++++++------------------------ src/pin.js | 49 +++++++++-------- src/pubsub.js | 59 ++++++++++---------- src/swarm.js | 29 +++++----- 11 files changed, 282 insertions(+), 251 deletions(-) diff --git a/package.json b/package.json index 9dd289b6b..c48f3886d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "readable-stream": "2.2.6" }, "devDependencies": { - "aegir": "^11.0.1" + "aegir": "^11.0.1", + "dirty-chai": "^1.2.2" }, "contributors": [ "David Dias ", diff --git a/src/block.js b/src/block.js index 994516655..b3058ae68 100644 --- a/src/block.js +++ b/src/block.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 Block = require('ipfs-block') const multihash = require('multihashes') const CID = require('cids') @@ -24,9 +27,9 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -38,11 +41,11 @@ module.exports = (common) => { describe('callback API', () => { it('.put a buffer', (done) => { const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' - const cid = new CID(expectedHash) + // const cid = new CID(expectedHash) const blob = new Buffer('blorb') ipfs.block.put(blob, (err, block) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(block.data).to.be.eql(blob) expectKey(block, multihash.fromB58String(expectedHash), done) }) @@ -54,7 +57,7 @@ module.exports = (common) => { const blob = new Block(new Buffer('blorb'), cid) ipfs.block.put(blob, (err, block) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(block.data).to.eql(new Buffer('blorb')) expectKey(block, multihash.fromB58String(expectedHash), done) }) @@ -65,7 +68,7 @@ module.exports = (common) => { const blob = new Block(new Buffer('blorb'), new CID(expectedHash)) ipfs.block.put(blob, (err, block) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(block.data).to.eql(new Buffer('blorb')) expectKey(block, multihash.fromB58String(expectedHash), done) }) @@ -85,7 +88,7 @@ module.exports = (common) => { const cid = new CID(hash) ipfs.block.get(cid, (err, block) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(block.data).to.eql(new Buffer('blorb')) expectKey(block, cid.multihash, done) }) @@ -95,7 +98,7 @@ module.exports = (common) => { const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' ipfs.block.get(hash, (err, block) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(block.data).to.eql(new Buffer('blorb')) expectKey(block, multihash.fromB58String(hash), done) }) @@ -106,7 +109,7 @@ module.exports = (common) => { const cid = new CID(hash) ipfs.block.stat(cid, (err, stats) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(stats).to.have.property('key') expect(stats).to.have.property('size') done() diff --git a/src/config.js b/src/config.js index 4339e0e9e..9ed692a46 100644 --- a/src/config.js +++ b/src/config.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) module.exports = (common) => { describe('.config', () => { @@ -11,9 +14,9 @@ module.exports = (common) => { before((done) => { common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -28,38 +31,38 @@ module.exports = (common) => { describe('.get', () => { it('retrieve the whole config', (done) => { ipfs.config.get((err, config) => { - expect(err).to.not.exist - expect(config).to.exist + expect(err).to.not.exist() + expect(config).to.exist() done() }) }) it('retrieve a value through a key', (done) => { ipfs.config.get('Identity.PeerID', (err, peerId) => { - expect(err).to.not.exist - expect(peerId).to.exist + expect(err).to.not.exist() + expect(peerId).to.exist() done() }) }) it('retrieve a value through a nested key', (done) => { ipfs.config.get('Addresses.Swarm', (err, swarmAddrs) => { - expect(err).to.not.exist - expect(swarmAddrs).to.exist + expect(err).to.not.exist() + expect(swarmAddrs).to.exist() done() }) }) it('fail on non valid key', (done) => { ipfs.config.get(1234, (err, peerId) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) - it('fail on non existent key', (done) => { + it('fail on non exist()ent key', (done) => { ipfs.config.get('Bananas', (err, peerId) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -67,20 +70,20 @@ module.exports = (common) => { describe('.set', () => { it('set a new key', (done) => { ipfs.config.set('Fruit', 'banana', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.config.get('Fruit', (err, fruit) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(fruit).to.equal('banana') done() }) }) }) - it('set an already existing key', (done) => { + it('set an already exist()ing key', (done) => { ipfs.config.set('Fruit', 'morango', (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.config.get('Fruit', (err, fruit) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(fruit).to.equal('morango') done() }) @@ -91,9 +94,9 @@ module.exports = (common) => { const key = 'API.HTTPHeaders.Access-Control-Allow-Origin' const val = ['http://example.io'] ipfs.config.set(key, val, function (err) { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.config.get(key, function (err, result) { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result).to.deep.equal(val) done() }) @@ -102,14 +105,14 @@ module.exports = (common) => { it('fail on non valid key', (done) => { ipfs.config.set(new Buffer('heeey'), '', (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) it('fail on non valid value', (done) => { ipfs.config.set('Fruit', new Buffer('abc'), (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -125,9 +128,9 @@ module.exports = (common) => { it('replace the whole config', (done) => { ipfs.config.replace(config, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.config.get((err, _config) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(_config).to.deep.equal(config) }) }) @@ -135,9 +138,9 @@ module.exports = (common) => { it('replace to empty config', (done) => { ipfs.config.replace({}, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.config.get((err, _config) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(_config).to.deep.equal(config) }) }) @@ -150,7 +153,7 @@ module.exports = (common) => { it('retrieve the whole config', () => { return ipfs.config.get() .then((config) => { - expect(config).to.exist + expect(config).to.exist() }) }) }) diff --git a/src/dag.js b/src/dag.js index d3dc32039..a75998ab6 100644 --- a/src/dag.js +++ b/src/dag.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 series = require('async/series') const pull = require('pull-stream') const dagPB = require('ipld-dag-pb') @@ -20,9 +23,9 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -39,7 +42,7 @@ module.exports = (common) => { const someData = new Buffer('some data') pbNode = DAGNode.create(someData, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() pbNode = node done() }) @@ -70,7 +73,7 @@ module.exports = (common) => { // This works because dag-cbor will just treat pbNode as a // regular object ipfs.dag.put(pbNode, 'dag-cbor', 'sha3-512', (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -95,7 +98,7 @@ module.exports = (common) => { format: 'dag-pb', hashAlg: 'sha3-512' }, (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -105,11 +108,11 @@ module.exports = (common) => { format: 'dag-cbor', hashAlg: 'sha3-512' }, (err, cid) => { - expect(err).to.not.exist - expect(cid).to.exist - expect(CID.isCID(cid)).to.be.true + expect(err).to.not.exist() + expect(cid).to.exist() + expect(CID.isCID(cid)).to.equal(true) dagCBOR.util.cid(cborNode, (err, _cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(cid.buffer).to.eql(_cid.buffer) done() }) @@ -134,7 +137,7 @@ module.exports = (common) => { const someData = new Buffer('some other data') pbNode = DAGNode.create(someData, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() pbNode = node cb() }) @@ -145,14 +148,14 @@ module.exports = (common) => { }, (cb) => { dagPB.DAGNode.create(new Buffer('I am inside a Protobuf'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() nodePb = node cb() }) }, (cb) => { dagPB.util.cid(nodePb, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() cidPb = cid cb() }) @@ -164,7 +167,7 @@ module.exports = (common) => { } dagCBOR.util.cid(nodeCbor, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() cidCbor = cid cb() }) @@ -193,9 +196,9 @@ module.exports = (common) => { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.dag.get(cid, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() const node = result.value expect(pbNode.toJSON()).to.eql(node.toJSON()) done() @@ -208,9 +211,9 @@ module.exports = (common) => { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.dag.get(cid, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() const node = result.value expect(cborNode).to.eql(node) @@ -222,12 +225,12 @@ module.exports = (common) => { describe('with path', () => { it('dag-pb get the node', (done) => { ipfs.dag.get(cidPb, '/', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() const node = result.value dagPB.util.cid(node, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(cid).to.eql(cidPb) done() }) @@ -236,7 +239,7 @@ module.exports = (common) => { it('dag-pb local scope', (done) => { ipfs.dag.get(cidPb, 'Data', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.value).to.eql(new Buffer('I am inside a Protobuf')) done() }) @@ -247,12 +250,12 @@ module.exports = (common) => { it('dag-cbor get the node', (done) => { ipfs.dag.get(cidCbor, '/', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() const node = result.value dagCBOR.util.cid(node, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(cid).to.eql(cidCbor) done() }) @@ -261,7 +264,7 @@ module.exports = (common) => { it('dag-cbor local scope', (done) => { ipfs.dag.get(cidCbor, 'someData', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.value).to.eql('I am inside a Cbor object') done() }) @@ -273,7 +276,7 @@ module.exports = (common) => { it('from dag-cbor to dag-pb', (done) => { ipfs.dag.get(cidCbor, 'pb/Data', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.value).to.eql(new Buffer('I am inside a Protobuf')) done() }) @@ -283,12 +286,12 @@ module.exports = (common) => { const cidCborStr = cidCbor.toBaseEncodedString() ipfs.dag.get(cidCborStr, (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() const node = result.value dagCBOR.util.cid(node, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(cid).to.eql(cidCbor) done() }) @@ -299,7 +302,7 @@ module.exports = (common) => { const cidCborStr = cidCbor.toBaseEncodedString() ipfs.dag.get(cidCborStr + '/pb/Data', (err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result.value).to.eql(new Buffer('I am inside a Protobuf')) done() }) @@ -317,14 +320,14 @@ module.exports = (common) => { series([ (cb) => { dagPB.DAGNode.create(new Buffer('I am inside a Protobuf'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() nodePb = node cb() }) }, (cb) => { dagPB.util.cid(nodePb, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() cidPb = cid cb() }) @@ -336,7 +339,7 @@ module.exports = (common) => { } dagCBOR.util.cid(nodeCbor, (err, cid) => { - expect(err).to.not.exist + expect(err).to.not.exist() cidCbor = cid cb() }) @@ -362,7 +365,7 @@ module.exports = (common) => { it('.tree with CID', (done) => { ipfs.dag.tree(cidCbor, (err, paths) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(paths).to.eql([ 'pb', 'someData' @@ -373,7 +376,7 @@ module.exports = (common) => { it('.tree with CID and path', (done) => { ipfs.dag.tree(cidCbor, 'someData', (err, paths) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(paths).to.eql([]) done() }) @@ -383,7 +386,7 @@ module.exports = (common) => { const cidCborStr = cidCbor.toBaseEncodedString() ipfs.dag.tree(cidCborStr + '/someData', (err, paths) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(paths).to.eql([]) done() }) @@ -391,7 +394,7 @@ module.exports = (common) => { it('.tree with CID recursive (accross different formats)', (done) => { ipfs.dag.tree(cidCbor, { recursive: true }, (err, paths) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(paths).to.eql([ 'pb', 'someData', @@ -404,7 +407,7 @@ module.exports = (common) => { it('.tree with CID and path recursive', (done) => { ipfs.dag.tree(cidCbor, 'pb', { recursive: true }, (err, paths) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(paths).to.eql([ 'Links', 'Data' diff --git a/src/dht.js b/src/dht.js index dd2dc7ccf..f8ba13234 100644 --- a/src/dht.js +++ b/src/dht.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) module.exports = (common) => { describe('.dht', () => { @@ -10,9 +13,9 @@ module.exports = (common) => { before((done) => { common.setup((err, factory) => { - expect(err).to.not.exists + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -24,15 +27,15 @@ module.exports = (common) => { }) describe('callback API', () => { - it('.get errors when getting a non-existent key from the DHT', (done) => { - ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => { + it('.get errors when getting a non-exist()ent key from the DHT', (done) => { + ipfs.dht.get('non-exist()ing', {timeout: '100ms'}, (err, value) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('.findprovs', (done) => { ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.be.an('array') done() @@ -40,8 +43,8 @@ module.exports = (common) => { }) }) describe('promise API', () => { - it('.get errors when getting a non-existent key from the DHT', (done) => { - ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => { + it('.get errors when getting a non-exist()ent key from the DHT', (done) => { + ipfs.dht.get('non-exist()ing', {timeout: '100ms'}).catch((err) => { expect(err).to.be.an.instanceof(Error) done() }) @@ -58,12 +61,12 @@ module.exports = (common) => { xdescribe('.findpeer', () => { it('finds other peers', (done) => { peers.a.ipfs.dht.findpeer(peers.b.peerID, (err, foundPeer) => { - expect(err).to.be.empty + expect(err).to.be.empty() expect(foundPeer.peerID).to.be.equal(peers.b.peerID) done() }) }) - it('fails to find other peer, if peer doesnt exists', (done) => { + it('fails to find other peer, if peer doesnt exist()s', (done) => { peers.a.ipfs.dht.findpeer('ARandomPeerID', (err, foundPeer) => { expect(err).to.be.instanceof(Error) expect(foundPeer).to.be.equal(null) @@ -73,13 +76,13 @@ module.exports = (common) => { }) xit('.put and .get a key value pair in the DHT', (done) => { peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.be.an('array') // bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234 peers.b.ipfs.dht.get('scope', (err, value) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(value).to.be.equal('interplanetary') done() }) diff --git a/src/files.js b/src/files.js index b5857c065..32136f6db 100644 --- a/src/files.js +++ b/src/files.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 bs58 = require('bs58') const Readable = require('readable-stream') const loadFixture = require('aegir/fixtures') @@ -36,9 +39,9 @@ module.exports = (common) => { } common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -68,10 +71,10 @@ module.exports = (common) => { arr.push(filePair) ipfs.files.add(arr, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.be.length(1) const file = res[0] - expect(file).to.exist + expect(file).to.exist() expect(file.path).to.equal('data.txt') expect(file.size).to.equal(17) expect(file.hash).to.equal(expectedMultihash) @@ -87,7 +90,7 @@ module.exports = (common) => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.add([file], (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() const file = res[0] expect(file.hash).to.equal(expectedMultihash) @@ -100,7 +103,7 @@ module.exports = (common) => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.add(smallFile, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.length(1) const file = res[0] expect(file.hash).to.equal(expectedMultihash) @@ -113,7 +116,7 @@ module.exports = (common) => { 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) const file = res[0] expect(file.hash).to.equal(expectedMultihash) @@ -150,7 +153,7 @@ module.exports = (common) => { ] ipfs.files.add(dirs, (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() const root = res[res.length - 1] expect(root.path).to.equal('test-folder') @@ -184,7 +187,7 @@ module.exports = (common) => { ] ipfs.files.createAddStream((err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() stream.on('data', (file) => { if (file.path === 'test-folder') { @@ -207,7 +210,7 @@ module.exports = (common) => { const nonValid = 'sfdasfasfs' ipfs.files.add(nonValid, (err, result) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -217,9 +220,9 @@ module.exports = (common) => { it('with a base58 string encoded multihash', (done) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.cat(hash, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() stream.pipe(bl((err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(data.toString()).to.contain('Plz add me!') done() })) @@ -229,9 +232,9 @@ module.exports = (common) => { it('with a multihash', (done) => { const mhBuf = new Buffer(bs58.decode('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')) ipfs.files.cat(mhBuf, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() stream.pipe(bl((err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(data.toString()).to.contain('Plz add me!') done() })) @@ -241,9 +244,9 @@ module.exports = (common) => { it('streams a large file', (done) => { const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ipfs.files.cat(hash, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() stream.pipe(bl((err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(data).to.deep.equal(bigFile) done() })) @@ -273,7 +276,7 @@ module.exports = (common) => { return ipfs.files.cat(hash) .then((stream) => { stream.pipe(bl((err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(data.toString()).to.contain('Plz add me!') })) }) @@ -284,7 +287,7 @@ module.exports = (common) => { return ipfs.files.cat(hash) .catch((err) => { - expect(err).to.exist + expect(err).to.exist() const errString = err.toString() if (errString === 'Error: invalid ipfs ref path') { expect(err.toString()).to.contain('Error: invalid ipfs ref path') @@ -300,7 +303,7 @@ module.exports = (common) => { return ipfs.files.cat(hash) .then((stream) => { stream.pipe(bl((err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(data.toString()).to.contain('Plz add me!') })) }) @@ -312,7 +315,7 @@ module.exports = (common) => { it('with a base58 encoded multihash', (done) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.files.get(hash, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() let files = [] stream.pipe(through.obj((file, enc, next) => { @@ -336,7 +339,7 @@ module.exports = (common) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' const mhBuf = new Buffer(bs58.decode(hash)) ipfs.files.get(mhBuf, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() let files = [] stream.pipe(through.obj((file, enc, next) => { @@ -359,7 +362,7 @@ module.exports = (common) => { it('large file', (done) => { const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ipfs.files.get(hash, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() // accumulate the files and their content var files = [] @@ -387,7 +390,7 @@ module.exports = (common) => { const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' ipfs.files.get(hash, (err, stream) => { - expect(err).to.not.exist + expect(err).to.not.exist() // accumulate the files and their content var files = [] @@ -471,7 +474,7 @@ module.exports = (common) => { it('errors on invalid key', () => { const hash = 'somethingNotMultihash' return ipfs.files.get(hash).catch((err) => { - expect(err).to.exist + expect(err).to.exist() const errString = err.toString() if (errString === 'Error: invalid ipfs ref path') { expect(err.toString()).to.contain('Error: invalid ipfs ref path') diff --git a/src/generic.js b/src/generic.js index 809b8f563..3ad3c713a 100644 --- a/src/generic.js +++ b/src/generic.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) module.exports = (common) => { describe('.generic', () => { @@ -16,9 +19,9 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -32,7 +35,7 @@ module.exports = (common) => { describe('callback API', () => { it('.id', (done) => { ipfs.id((err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(res).to.have.a.property('id') expect(res).to.have.a.property('publicKey') done() @@ -41,7 +44,7 @@ module.exports = (common) => { it('.version', (done) => { ipfs.version((err, result) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(result).to.have.a.property('version') expect(result).to.have.a.property('commit') expect(result).to.have.a.property('repo') diff --git a/src/object.js b/src/object.js index cd130456c..ffc838a3a 100644 --- a/src/object.js +++ b/src/object.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 dagPB = require('ipld-dag-pb') const DAGNode = dagPB.DAGNode const bs58 = require('bs58') @@ -18,9 +21,9 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node done() }) @@ -35,7 +38,7 @@ module.exports = (common) => { describe('.new', () => { it('no layout', (done) => { ipfs.object.new((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() const nodeJSON = node.toJSON() expect(nodeJSON.multihash).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') done() @@ -44,7 +47,7 @@ module.exports = (common) => { it('template unixfs-dir', (done) => { ipfs.object.new('unixfs-dir', (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() const nodeJSON = node.toJSON() expect( nodeJSON.multihash @@ -64,7 +67,7 @@ module.exports = (common) => { } ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() const nodeJSON = node.toJSON() expect(nodeJSON.data).to.eql(obj.Data) expect(nodeJSON.links).to.eql(obj.Links) @@ -87,7 +90,7 @@ module.exports = (common) => { const buf = new Buffer(JSON.stringify(obj2)) ipfs.object.put(buf, { enc: 'json' }, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() const nodeJSON = node.toJSON() expect(nodeJSON.data).to.eql(node.data) @@ -103,21 +106,21 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(new Buffer('Some data'), (err, _node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node = _node cb() }) }, (cb) => { dagPB.util.serialize(node, (err, _serialized) => { - expect(err).to.not.exist + expect(err).to.not.exist() serialized = _serialized cb() }) }, (cb) => { ipfs.object.put(serialized, { enc: 'protobuf' }, (err, storedNode) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.data).to.deep.equal(node.data) expect(node.links).to.deep.equal(node.links) expect(node.multihash).to.eql(storedNode.multihash) @@ -130,7 +133,7 @@ module.exports = (common) => { it('of buffer treated as Data field', (done) => { const data = new Buffer('Some data') ipfs.object.put(data, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() const nodeJSON = node.toJSON() expect(data).to.deep.equal(nodeJSON.data) expect([]).to.deep.equal(nodeJSON.links) @@ -141,9 +144,9 @@ module.exports = (common) => { it('of DAGNode', (done) => { DAGNode.create(new Buffer('Some data'), (err, dNode) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.put(dNode, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(dNode.data).to.deep.equal(node.data) expect(dNode.links).to.deep.equal(node.links) done() @@ -153,7 +156,7 @@ module.exports = (common) => { it('fails if String is passed', (done) => { ipfs.object.put('aaa', (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -165,14 +168,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(new Buffer('Some data 1'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('Some data 2'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -181,14 +184,14 @@ module.exports = (common) => { const link = node2.toJSON() link.name = 'some-link' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) }, (cb) => { ipfs.object.put(node1b, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node1b.data).to.deep.equal(node.data) expect(node1b.links.map((l) => l.toJSON())) .to.deep.equal(node.links.map((l) => l.toJSON())) @@ -212,14 +215,14 @@ module.exports = (common) => { series([ (cb) => { ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1 = node cb() }) }, (cb) => { ipfs.object.get(node1.multihash, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node // because js-ipfs-api can't infer if the @@ -248,14 +251,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(new Buffer('Some data 1'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('Some data 2'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -264,7 +267,7 @@ module.exports = (common) => { const link = node2.toJSON() link.name = 'some-link' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) @@ -274,7 +277,7 @@ module.exports = (common) => { }, (cb) => { ipfs.object.get(node1b.multihash, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer if the // returned Data is Buffer or String @@ -306,14 +309,14 @@ module.exports = (common) => { series([ (cb) => { ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { ipfs.object.get(node1a.multihash, { enc: 'base58' }, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer if the // returned Data is Buffer or String if (typeof node.data === 'string') { @@ -344,14 +347,14 @@ module.exports = (common) => { series([ (cb) => { ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { ipfs.object.get(bs58.encode(node1a.multihash).toString(), { enc: 'base58' }, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer if the // returned Data is Buffer or String if (typeof node.data === 'string') { @@ -379,10 +382,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.data(node.multihash, (err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer // if the returned Data is Buffer or String @@ -402,10 +405,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.data(bs58.encode(node.multihash), { enc: 'base58' }, (err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer // if the returned Data is Buffer or String @@ -425,10 +428,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.data(bs58.encode(node.multihash).toString(), { enc: 'base58' }, (err, data) => { - expect(err).to.not.exist + expect(err).to.not.exist() // because js-ipfs-api can't infer if the // returned Data is Buffer or String @@ -450,10 +453,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.links(node.multihash, (err, links) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.links).to.deep.equal(links) done() }) @@ -468,14 +471,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(new Buffer('Some data 1'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('Some data 2'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -485,7 +488,7 @@ module.exports = (common) => { link.name = 'some-link' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) @@ -495,7 +498,7 @@ module.exports = (common) => { }, (cb) => { ipfs.object.links(node1b.multihash, (err, links) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node1b.links[0].toJSON()).to.eql(links[0].toJSON()) cb() }) @@ -510,10 +513,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.links(bs58.encode(node.multihash), { enc: 'base58' }, (err, links) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.links).to.deep.equal(links) done() }) @@ -527,9 +530,9 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.links(bs58.encode(node.multihash), { enc: 'base58' }, (err, links) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.links).to.deep.equal(links) done() }) @@ -545,10 +548,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.stat(node.multihash, (err, stats) => { - expect(err).to.not.exist + expect(err).to.not.exist() const expected = { Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', NumLinks: 0, @@ -571,14 +574,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(new Buffer('Some data 1'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('Some data 2'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -588,7 +591,7 @@ module.exports = (common) => { link.name = 'some-link' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) @@ -598,7 +601,7 @@ module.exports = (common) => { }, (cb) => { ipfs.object.stat(node1b.multihash, (err, stats) => { - expect(err).to.not.exist + expect(err).to.not.exist() const expected = { Hash: 'QmPR7W4kaADkAo4GKEVVPQN81EDUFCHJtqejQZ5dEG7pBC', NumLinks: 1, @@ -621,10 +624,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.stat(bs58.encode(node.multihash), { enc: 'base58' }, (err, stats) => { - expect(err).to.not.exist + expect(err).to.not.exist() const expected = { Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', NumLinks: 0, @@ -646,10 +649,10 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.stat(bs58.encode(node.multihash).toString(), { enc: 'base58' }, (err, stats) => { - expect(err).to.not.exist + expect(err).to.not.exist() const expected = { Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', NumLinks: 0, @@ -677,7 +680,7 @@ module.exports = (common) => { before((done) => { ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() testNodeMultihash = node.multihash done() }) @@ -691,14 +694,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(obj.Data, obj.Links, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('some other node'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -712,14 +715,14 @@ module.exports = (common) => { const link = node2.toJSON() link.name = 'link-to-node' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) }, (cb) => { ipfs.object.patch.addLink(testNodeMultihash, node1b.links[0], (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node1b.multihash).to.eql(node.multihash) testNodeWithLinkMultihash = node.multihash testLink = node1b.links[0] @@ -731,7 +734,7 @@ module.exports = (common) => { it('.rmLink', (done) => { ipfs.object.patch.rmLink(testNodeWithLinkMultihash, testLink, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.multihash).to.not.deep.equal(testNodeWithLinkMultihash) done() }) @@ -739,7 +742,7 @@ module.exports = (common) => { it('.appendData', (done) => { ipfs.object.patch.appendData(testNodeMultihash, new Buffer('append'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.multihash).to.not.deep.equal(testNodeMultihash) done() }) @@ -747,7 +750,7 @@ module.exports = (common) => { it('.setData', (done) => { ipfs.object.patch.appendData(testNodeMultihash, new Buffer('set'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(node.multihash).to.not.deep.equal(testNodeMultihash) done() }) @@ -828,7 +831,7 @@ module.exports = (common) => { } ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', {enc: 'base58'}) .then((stats) => { @@ -844,7 +847,7 @@ module.exports = (common) => { done() }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) }) }) @@ -875,7 +878,7 @@ module.exports = (common) => { before((done) => { ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() testNodeMultihash = node.multihash done() }) @@ -889,14 +892,14 @@ module.exports = (common) => { series([ (cb) => { DAGNode.create(obj.Data, obj.Links, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1a = node cb() }) }, (cb) => { DAGNode.create(new Buffer('some other node'), (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node2 = node cb() }) @@ -910,7 +913,7 @@ module.exports = (common) => { const link = node2.toJSON() link.name = 'link-to-node' DAGNode.addLink(node1a, link, (err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() node1b = node cb() }) @@ -924,7 +927,7 @@ module.exports = (common) => { cb() }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) } ], done) @@ -937,7 +940,7 @@ module.exports = (common) => { done() }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) }) @@ -948,7 +951,7 @@ module.exports = (common) => { done() }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) }) @@ -959,7 +962,7 @@ module.exports = (common) => { done() }) .catch((err) => { - expect(err).to.not.exist + expect(err).to.not.exist() }) }) }) diff --git a/src/pin.js b/src/pin.js index 2151f0292..c629824dc 100644 --- a/src/pin.js +++ b/src/pin.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 loadFixture = require('aegir/fixtures') const testfile = loadFixture(__dirname, '../test/fixtures/testfile.txt', 'interface-ipfs-core') @@ -19,9 +22,9 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs = node populate() }) @@ -31,7 +34,7 @@ module.exports = (common) => { 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,11 +54,11 @@ module.exports = (common) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.pin.rm(hash, { recursive: true }, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.exist + expect(err).to.not.exist() + expect(pinset).to.exist() ipfs.pin.ls({ type: 'direct' }, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.be.empty + expect(err).to.not.exist() + expect(pinset).to.be.empty() done() }) }) @@ -65,7 +68,7 @@ module.exports = (common) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.pin.add(hash, { recursive: false }, (err, pinset) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(pinset[0]).to.be.equal(hash) done() }) @@ -73,32 +76,32 @@ module.exports = (common) => { it('.ls', (done) => { ipfs.pin.ls((err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.not.be.empty + expect(err).to.not.exist() + expect(pinset).to.not.be.empty() done() }) }) it('.ls type direct', (done) => { ipfs.pin.ls({ type: 'direct' }, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.not.be.empty + expect(err).to.not.exist() + expect(pinset).to.not.be.empty() done() }) }) it('.ls type indirect', (done) => { ipfs.pin.ls({ type: 'indirect' }, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.not.be.empty + expect(err).to.not.exist() + expect(pinset).to.not.be.empty() done() }) }) it('.ls type recursive', (done) => { ipfs.pin.ls({ type: 'recursive' }, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.not.be.empty + expect(err).to.not.exist() + expect(pinset).to.not.be.empty() done() }) }) @@ -107,8 +110,8 @@ module.exports = (common) => { const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ipfs.pin.ls(hash, (err, pinset) => { - expect(err).to.not.exist - expect(pinset).to.exist + expect(err).to.not.exist() + expect(pinset).to.exist() done() }) }) @@ -127,8 +130,8 @@ module.exports = (common) => { it('.ls', () => { return ipfs.pin.ls() .then((pinset) => { - expect(pinset).to.exist - expect(pinset).to.not.be.empty + expect(pinset).to.exist() + expect(pinset).to.not.be.empty() }) }) @@ -137,7 +140,7 @@ module.exports = (common) => { return ipfs.pin.ls(hash) .then((pinset) => { - expect(pinset).to.exist + expect(pinset).to.exist() }) }) @@ -149,7 +152,7 @@ module.exports = (common) => { return ipfs.pin.ls({ type: 'direct' }) }) .then((pinset) => { - expect(pinset).to.be.empty + expect(pinset).to.be.empty() }) }) }) diff --git a/src/pubsub.js b/src/pubsub.js index 6ffae566a..95d9cb06d 100644 --- a/src/pubsub.js +++ b/src/pubsub.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 series = require('async/series') const waterfall = require('async/waterfall') const parallel = require('async/parallel') @@ -94,7 +97,7 @@ module.exports = (common) => { describe('.publish', () => { it('errors on string messags', (done) => { ipfs1.pubsub.publish(topic, 'hello friend', (err) => { - expect(err).to.exist + expect(err).to.exist() done() }) }) @@ -118,14 +121,14 @@ module.exports = (common) => { ipfs1.pubsub.unsubscribe(topic, handler) ipfs1.pubsub.ls((err, topics) => { - expect(err).to.not.exist - expect(topics).to.be.empty + expect(err).to.not.exist() + expect(topics).to.be.empty() check() }) } ipfs1.pubsub.subscribe(topic, handler, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.publish(topic, new Buffer('hi'), check) }) }) @@ -145,7 +148,7 @@ module.exports = (common) => { }, (cb) => ipfs1.pubsub.ls(cb) ], (err, res) => { - expect(err).to.not.exist + expect(err).to.not.exist() // Still subscribed as there is one listener left expect(res[0]).to.be.eql([topic]) @@ -164,7 +167,7 @@ module.exports = (common) => { (cb) => ipfs1.pubsub.subscribe(topic, handler1, cb), (cb) => ipfs1.pubsub.subscribe(topic, handler2, cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.publish(topic, new Buffer('hello'), check) }) }) @@ -181,7 +184,7 @@ module.exports = (common) => { ipfs1.pubsub.subscribe(topic, { discover: true }, handler, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.publish(topic, new Buffer('hi'), check) }) }) @@ -206,9 +209,9 @@ module.exports = (common) => { describe('.peers', () => { it('does not error when not subscribed to a topic', (done) => { ipfs1.pubsub.peers(topic, (err, peers) => { - expect(err).to.not.exist - // Should be empty but as mentioned below go-ipfs returns more than it should - // expect(peers).to.be.empty + expect(err).to.not.exist() + // Should be empty() but as mentioned below go-ipfs returns more than it should + // expect(peers).to.be.empty() done() }) @@ -226,12 +229,12 @@ module.exports = (common) => { (cb) => ipfs1.pubsub.subscribe(topic, sub1, cb), (cb) => ipfs2.pubsub.subscribe(topicOther, sub2, cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() setTimeout(() => { ipfs1.pubsub.peers(topic, (err, peers) => { - expect(err).to.not.exist + expect(err).to.not.exist() - expect(peers).to.be.empty + expect(peers).to.be.empty() ipfs1.pubsub.unsubscribe(topic, sub1) ipfs2.pubsub.unsubscribe(topicOther, sub2) done() @@ -251,7 +254,7 @@ module.exports = (common) => { (cb) => ipfs2.pubsub.subscribe(topic, sub2, cb), (cb) => waitForPeers(ipfs1, topic, [ipfs2.peerId.id], cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.unsubscribe(topic, sub1) ipfs2.pubsub.unsubscribe(topic, sub2) @@ -273,7 +276,7 @@ module.exports = (common) => { ipfs3.peerId.id ], cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.unsubscribe(topic, sub1) ipfs2.pubsub.unsubscribe(topic, sub2) ipfs3.pubsub.unsubscribe(topic, sub3) @@ -284,9 +287,9 @@ module.exports = (common) => { }) describe('.ls', () => { - it('empty list when no topics are subscribed', (done) => { + it('empty() list when no topics are subscribed', (done) => { ipfs1.pubsub.ls((err, topics) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(topics.length).to.equal(0) done() }) @@ -296,10 +299,10 @@ module.exports = (common) => { const sub1 = (msg) => {} ipfs1.pubsub.subscribe(topic, sub1, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.ls((err, topics) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(topics).to.be.eql([topic]) ipfs1.pubsub.unsubscribe(topic, sub1) @@ -323,9 +326,9 @@ module.exports = (common) => { each(topics, (t, cb) => { ipfs1.pubsub.subscribe(t.name, t.handler, cb) }, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs1.pubsub.ls((err, list) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect( list.sort() @@ -367,7 +370,7 @@ module.exports = (common) => { (cb) => ipfs2.pubsub.subscribe(topic, sub2, cb), (cb) => waitForPeers(ipfs2, topic, [ipfs1.peerId.id], cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfs2.pubsub.publish(topic, new Buffer(expectedString), check) }) @@ -405,7 +408,7 @@ module.exports = (common) => { (cb) => ipfs2.pubsub.subscribe(topic, sub2, cb), (cb) => waitForPeers(ipfs2, topic, [ipfs1.peerId.id], cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() outbox.forEach((msg) => { ipfs2.pubsub.publish(topic, new Buffer(msg), check) @@ -481,7 +484,7 @@ module.exports = (common) => { (cb) => ipfs2.pubsub.subscribe(topic, sub2, cb), (cb) => waitForPeers(ipfs1, topic, [ipfs2.peerId.id], cb) ], (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() startTime = new Date().getTime() whilst( @@ -512,13 +515,13 @@ module.exports = (common) => { ipfs1.pubsub.subscribe(someTopic, handler, cb) }, (err) => { - expect(err).to.not.exist + expect(err).to.not.exist() handlers.forEach((handler) => { ipfs1.pubsub.unsubscribe(someTopic, handler) }) ipfs1.pubsub.ls((err, topics) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(topics).to.eql([]) done() }) @@ -569,7 +572,7 @@ module.exports = (common) => { return ipfs1.pubsub.subscribe(topic, sub) .then(() => ipfs1.pubsub.peers(topic)) .then((peers) => { - expect(peers).to.exist + expect(peers).to.exist() ipfs1.pubsub.unsubscribe(topic, sub) }) }) diff --git a/src/swarm.js b/src/swarm.js index ff9ca3993..355472a42 100644 --- a/src/swarm.js +++ b/src/swarm.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 series = require('async/series') const multiaddr = require('multiaddr') @@ -19,18 +22,18 @@ module.exports = (common) => { this.timeout(20 * 1000) common.setup((err, factory) => { - expect(err).to.not.exist + expect(err).to.not.exist() series([ (cb) => { factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfsA = node cb() }) }, (cb) => { factory.spawnNode((err, node) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfsB = node cb() }) @@ -48,7 +51,7 @@ module.exports = (common) => { describe('callback API', () => { it('.connect', (done) => { ipfsB.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() ipfsBId = id const ipfsBAddr = id.addresses[0] ipfsA.swarm.connect(ipfsBAddr, done) @@ -68,13 +71,13 @@ module.exports = (common) => { it('default', (done) => { ipfsA.swarm.peers((err, peers) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(peers).to.have.length.above(0) const peer = peers[0] expect(peer).to.have.a.property('addr') - expect(multiaddr.isMultiaddr(peer.addr)).to.be.true + expect(multiaddr.isMultiaddr(peer.addr)).to.equal(true) expect(peer).to.have.a.property('peer') expect(peer).to.not.have.a.property('latency') @@ -88,12 +91,12 @@ module.exports = (common) => { it('verbose', (done) => { ipfsA.swarm.peers({verbose: true}, (err, peers) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(peers).to.have.length.above(0) const peer = peers[0] expect(peer).to.have.a.property('addr') - expect(multiaddr.isMultiaddr(peer.addr)).to.be.true + expect(multiaddr.isMultiaddr(peer.addr)).to.equal(true) expect(peer).to.have.a.property('peer') expect(peer).to.have.a.property('latency') @@ -108,8 +111,8 @@ module.exports = (common) => { it('.addrs', (done) => { ipfsA.swarm.addrs((err, multiaddrs) => { - expect(err).to.not.exist - expect(multiaddrs).to.not.be.empty + expect(err).to.not.exist() + expect(multiaddrs).to.not.be.empty() expect(multiaddrs).to.be.an('array') expect(multiaddrs[0].constructor.name).to.be.eql('PeerInfo') done() @@ -118,7 +121,7 @@ module.exports = (common) => { it('.localAddrs', (done) => { ipfsA.swarm.localAddrs((err, multiaddrs) => { - expect(err).to.not.exist + expect(err).to.not.exist() expect(multiaddrs).to.have.length.above(0) done() }) @@ -126,7 +129,7 @@ module.exports = (common) => { it('.disconnect', (done) => { ipfsB.id((err, id) => { - expect(err).to.not.exist + expect(err).to.not.exist() const ipfsBAddr = id.addresses[0] ipfsA.swarm.disconnect(ipfsBAddr, done) })