diff --git a/src/config.js b/src/config.js index 5bd1a09b1..ee05971bb 100644 --- a/src/config.js +++ b/src/config.js @@ -142,31 +142,23 @@ module.exports = (common) => { describe('promise API', () => { describe('.get', () => { - it('retrieve the whole config', (done) => { - ipfs.config.get() + it('retrieve the whole config', () => { + return ipfs.config.get() .then((config) => { expect(config).to.exist - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) }) describe('.set', () => { - it('set a new key', (done) => { - ipfs.config.set('Fruit', 'banana') + it('set a new key', () => { + return ipfs.config.set('Fruit', 'banana') .then(() => { ipfs.config.get('Fruit', (err, fruit) => { expect(err).to.not.exist expect(fruit).to.equal('banana') - done() }) }) - .catch((err) => { - expect(err).to.not.exist - }) }) }) diff --git a/src/files.js b/src/files.js index 49f1fd1f4..766ce4dff 100644 --- a/src/files.js +++ b/src/files.js @@ -226,9 +226,9 @@ module.exports = (common) => { }) }) - describe('promise API', (done) => { + describe('promise API', () => { describe('.add', () => { - it('buffer', (done) => { + it('buffer', () => { return ipfs.files.add(smallFile) .then((res) => { const added = res[0] != null ? res[0] : res @@ -236,34 +236,27 @@ module.exports = (common) => { expect(mh).to.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') expect(added.path).to.equal(mh) expect(added.node.links).to.have.length(0) - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) }) describe('.cat', () => { - it('with a bas58 multihash encoded string', (done) => { + it('with a bas58 multihash encoded string', () => { const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' - ipfs.cat(hash) + + return ipfs.cat(hash) .then((stream) => { stream.pipe(bl((err, data) => { expect(err).to.not.exist expect(data.toString()).to.contain('Check out some of the other files in this directory:') - done() })) }) - .catch((err) => { - expect(err).to.not.exist - }) }) - it('errors on invalid key', (done) => { + it('errors on invalid key', () => { const hash = 'somethingNotMultihash' - ipfs.cat(hash) - .then((stream) => {}) + + return ipfs.cat(hash) .catch((err) => { expect(err).to.exist const errString = err.toString() @@ -273,23 +266,18 @@ module.exports = (common) => { if (errString === 'Error: Invalid Key') { expect(err.toString()).to.contain('Error: Invalid Key') } - done() }) }) - it('with a multihash', (done) => { + it('with a multihash', () => { const hash = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')) - ipfs.cat(hash) + return ipfs.cat(hash) .then((stream) => { stream.pipe(bl((err, bldata) => { expect(err).to.not.exist expect(bldata.toString()).to.contain('Check out some of the other files in this directory:') - done() })) }) - .catch((err) => { - expect(err).to.not.exist - }) }) }) }) diff --git a/src/object.js b/src/object.js index b6d54cf59..853cde3d9 100644 --- a/src/object.js +++ b/src/object.js @@ -539,132 +539,106 @@ module.exports = (common) => { }) describe('promise API', () => { - it('object.new', (done) => { - ipfs.object.new() + it('object.new', () => { + return ipfs.object.new() .then((node) => { expect(node.toJSON().Hash).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) - it('object.put', (done) => { + it('object.put', () => { const obj = { Data: new Buffer('Some data'), Links: [] } - ipfs.object.put(obj) + return ipfs.object.put(obj) .then((node) => { const nodeJSON = node.toJSON() expect(obj.Data).to.deep.equal(nodeJSON.Data) expect(obj.Links).to.deep.equal(nodeJSON.Links) expect(nodeJSON.Hash).to.equal('QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK') - done() - }).catch((err) => { - expect(err).to.not.exist }) }) - it('object.get', (done) => { + it('object.get', () => { const testObj = { Data: new Buffer('get test object'), Links: [] } - ipfs.object.put(testObj, (err, node1) => { - expect(err).to.not.exist - - ipfs.object.get(node1.multihash()) - .then((node2) => { - // because js-ipfs-api can't infer if the returned Data is Buffer - // or String - if (typeof node2.data === 'string') { - node2.data = new Buffer(node2.data) - } - expect(node1.multihash()).to.deep.equal(node2.multihash()) - expect(node1.data).to.deep.equal(node2.data) - expect(node1.links).to.deep.equal(node2.links) - done() - }) - .catch((err) => { - expect(err).to.not.exist - }) - }) + return ipfs.object.put(testObj) + .then((node1) => { + return ipfs.object.get(node1.multihash()) + .then((node2) => { + // because js-ipfs-api can't infer if the returned Data is Buffer + // or String + if (typeof node2.data === 'string') { + node2.data = new Buffer(node2.data) + } + expect(node1.multihash()).to.deep.equal(node2.multihash()) + expect(node1.data).to.deep.equal(node2.data) + expect(node1.links).to.deep.equal(node2.links) + }) + }) }) - it('object.data', (done) => { + it('object.data', () => { const testObj = { Data: new Buffer('get test object'), Links: [] } - ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist - - ipfs.object.data(node.multihash()) - .then((data) => { - // because js-ipfs-api can't infer - // if the returned Data is Buffer or String - if (typeof data === 'string') { - data = new Buffer(data) - } - expect(node.data).to.deep.equal(data) - done() - }) - .catch((err) => { - expect(err).to.not.exist - }) - }) + return ipfs.object.put(testObj) + .then((node) => { + return ipfs.object.data(node.multihash()) + .then((data) => { + // because js-ipfs-api can't infer + // if the returned Data is Buffer or String + if (typeof data === 'string') { + data = new Buffer(data) + } + expect(node.data).to.deep.equal(data) + }) + }) }) - it('object.stat', (done) => { + it('object.stat', () => { const testObj = { Data: new Buffer('get test object'), Links: [] } - ipfs.object.put(testObj) + return ipfs.object.put(testObj) .then((node) => { - ipfs.object.stat(node.multihash(), (err, stats) => { - expect(err).to.not.exist - const expected = { - Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', - NumLinks: 0, - BlockSize: 17, - LinksSize: 2, - DataSize: 15, - CumulativeSize: 17 - } - expect(expected).to.deep.equal(stats) - done() - }) - }) - .catch((err) => { - expect(err).to.not.exist + return ipfs.object.stat(node.multihash()) + }) + .then((stats) => { + const expected = { + Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', + NumLinks: 0, + BlockSize: 17, + LinksSize: 2, + DataSize: 15, + CumulativeSize: 17 + } + expect(expected).to.deep.equal(stats) }) }) - it('object.links', (done) => { + it('object.links', () => { const testObj = { Data: new Buffer('get test object'), Links: [] } - ipfs.object.put(testObj, (err, node) => { - expect(err).to.not.exist - - ipfs.object.links(node.multihash()) - .then((links) => { - expect(node.links).to.deep.equal(links) - done() - }) - .catch((err) => { - expect(err).to.not.exist - }) - }) + return ipfs.object.put(testObj) + .then((node) => { + return ipfs.object.links(node.multihash()) + .then((links) => { + expect(node.links).to.deep.equal(links) + }) + }) }) describe('object.patch', () => { @@ -672,71 +646,58 @@ module.exports = (common) => { let testNodeWithLink let testLink - before((done) => { + before(() => { const obj = { Data: new Buffer('patch test object'), Links: [] } - ipfs.object.put(obj, (err, node) => { - expect(err).to.not.exist - testNode = node - done() - }) + return ipfs.object.put(obj) + .then((node) => { + testNode = node + }) }) - it('.addLink', (done) => { + it('.addLink', () => { const dNode1 = testNode.copy() const dNode2 = new DAGNode(new Buffer('some other node')) // note: we need to put the linked obj, otherwise IPFS won't timeout // cause it needs the node to get its size - ipfs.object.put(dNode2, (err) => { - expect(err).to.not.exist - dNode1.addNodeLink('link-to-node', dNode2) - - ipfs.object.patch.addLink(testNode.multihash(), dNode1.links[0]) - .then((node3) => { - expect(dNode1.multihash()).to.deep.equal(node3.multihash()) - testNodeWithLink = node3 - testLink = dNode1.links[0] - done() - }) - .catch((err) => { - expect(err).to.not.exist - }) - }) + return ipfs.object.put(dNode2) + .then(() => { + dNode1.addNodeLink('link-to-node', dNode2) + + return ipfs.object.patch + .addLink(testNode.multihash(), dNode1.links[0]) + .then((node3) => { + expect(dNode1.multihash()).to.deep.equal(node3.multihash()) + testNodeWithLink = node3 + testLink = dNode1.links[0] + }) + }) }) - it('.rmLink', (done) => { - ipfs.object.patch.rmLink(testNodeWithLink.multihash(), testLink) + it('.rmLink', () => { + return ipfs.object.patch + .rmLink(testNodeWithLink.multihash(), testLink) .then((node) => { expect(node.multihash()).to.deep.equal(testNode.multihash()) - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) - it('.appendData', (done) => { - ipfs.object.patch.appendData(testNode.multihash(), new Buffer('append')) + it('.appendData', () => { + return ipfs.object.patch + .appendData(testNode.multihash(), new Buffer('append')) .then((node) => { expect(node.multihash()).to.not.deep.equal(testNode.multihash()) - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) - it('.setData', (done) => { - ipfs.object.patch.appendData(testNode.multihash(), new Buffer('set')) + it('.setData', () => { + return ipfs.object.patch + .appendData(testNode.multihash(), new Buffer('set')) .then((node) => { expect(node.multihash()).to.not.deep.equal(testNode.multihash()) - done() - }) - .catch((err) => { - expect(err).to.not.exist }) }) })