From 9ffe84803733eeab82cca2b8bec96c2ba1021d45 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 14:05:16 +0100 Subject: [PATCH 01/20] feat: migrate to next AEgir (v12) --- .aegir.js | 8 +- .travis.yml | 2 - circle.yml | 4 + examples/bundle-browserify/index.js | 2 +- examples/bundle-webpack/src/App.js | 2 +- examples/files-api/files-api.js | 2 +- examples/name-api/index.js | 2 +- examples/upload-file-via-browser/src/App.js | 22 +-- gulpfile.js | 12 -- package.json | 34 ++-- src/config/replace.js | 2 +- src/object/get.js | 2 +- src/object/links.js | 2 +- src/object/new.js | 2 +- src/object/put.js | 4 +- src/utils/get-dagnode.js | 42 ++--- src/utils/get-files-stream.js | 6 +- src/utils/pubsub-message-utils.js | 6 +- test/bitswap.spec.js | 5 +- test/bootstrap.spec.js | 15 +- test/commands.spec.js | 7 +- test/diag.spec.js | 7 +- test/files.spec.js | 27 +-- test/get.spec.js | 17 +- test/ipfs-factory/client.js | 6 +- test/ipfs-factory/tasks.js | 30 +-- test/key.spec.js | 7 +- test/log.spec.js | 15 +- test/ls.spec.js | 7 +- test/mount.spec.js | 4 +- test/name.spec.js | 7 +- test/pubsub-in-browser.spec.js | 196 ++++++++++---------- test/refs.spec.js | 7 +- test/repo.spec.js | 7 +- 34 files changed, 277 insertions(+), 243 deletions(-) delete mode 100644 gulpfile.js diff --git a/.aegir.js b/.aegir.js index efeced9a7..0e7eebbde 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,5 +1,7 @@ 'use strict' +const factory = require('./test/ipfs-factory/tasks') + module.exports = { karma: { files: [{ @@ -8,5 +10,9 @@ module.exports = { served: true, included: false }] + }, + hooks: { + pre: factory.start, + post: factory.stop } -} \ No newline at end of file +} diff --git a/.travis.yml b/.travis.yml index 584f308f8..c5ed64e0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,6 @@ matrix: script: - npm run lint - npm run test - - npm run coverage - - make test before_script: - export DISPLAY=:99.0 diff --git a/circle.yml b/circle.yml index 56f7efbe2..d67b6ae70 100644 --- a/circle.yml +++ b/circle.yml @@ -2,6 +2,10 @@ machine: node: version: stable +test: + post: + - npm run coverage -- --upload + dependencies: pre: - google-chrome --version diff --git a/examples/bundle-browserify/index.js b/examples/bundle-browserify/index.js index 5216b7269..d38d3f548 100644 --- a/examples/bundle-browserify/index.js +++ b/examples/bundle-browserify/index.js @@ -6,7 +6,7 @@ var ipfs = IPFS() function store () { var toStore = document.getElementById('source').value - ipfs.add(new Buffer(toStore), function (err, res) { + ipfs.add(Buffer.from(toStore), function (err, res) { if (err || !res) { return console.error('ipfs add error', err, res) } diff --git a/examples/bundle-webpack/src/App.js b/examples/bundle-webpack/src/App.js index 7316d9996..1c8d3d149 100644 --- a/examples/bundle-webpack/src/App.js +++ b/examples/bundle-webpack/src/App.js @@ -25,7 +25,7 @@ class App extends React.Component { protocol_version: res.protocolVersion }) }) - ipfs.add([new Buffer(stringToUse)], (err, res) => { + ipfs.add([Buffer.from(stringToUse)], (err, res) => { if (err) throw err const hash = res[0].hash this.setState({added_file_hash: hash}) diff --git a/examples/files-api/files-api.js b/examples/files-api/files-api.js index f0b92318a..fefc957d6 100644 --- a/examples/files-api/files-api.js +++ b/examples/files-api/files-api.js @@ -1,6 +1,6 @@ 'use strict' -var ipfs = require('../../src')('localhost', 5001) +const ipfs = require('../../src')('localhost', 5001) ipfs.files.ls('/folder1', function (err, res) { if (err) { diff --git a/examples/name-api/index.js b/examples/name-api/index.js index 887f464ff..263c051cf 100644 --- a/examples/name-api/index.js +++ b/examples/name-api/index.js @@ -52,7 +52,7 @@ const addAndPublish = (e) => { e.preventDefault() let input = e.target.elements['text'] - let buffer = new Buffer(input.value) + let buffer = Buffer.from(input.value) showStatus('adding to IPFS...', COLORS.active) diff --git a/examples/upload-file-via-browser/src/App.js b/examples/upload-file-via-browser/src/App.js index 2111b30b3..7b913f7f0 100644 --- a/examples/upload-file-via-browser/src/App.js +++ b/examples/upload-file-via-browser/src/App.js @@ -30,14 +30,14 @@ class App extends React.Component { let ipfsId const buffer = Buffer.from(reader.result) this.ipfsApi.add(buffer) - .then((response) => { - console.log(response) - ipfsId = response[0].hash - console.log(ipfsId) - this.setState({added_file_hash: ipfsId}) - }).catch((err) => { - console.error(err) - }) + .then((response) => { + console.log(response) + ipfsId = response[0].hash + console.log(ipfsId) + this.setState({added_file_hash: ipfsId}) + }).catch((err) => { + console.error(err) + }) } arrayBufferToString (arrayBuffer) { @@ -51,11 +51,11 @@ class App extends React.Component { render () { return (
-
- + +
- {this.state.added_file_hash} diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index a9ff11eb5..000000000 --- a/gulpfile.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const gulp = require('gulp') - -require('./test/ipfs-factory/tasks') - -gulp.task('test:node:before', ['factory:start']) -gulp.task('test:node:after', ['factory:stop']) -gulp.task('test:browser:before', ['factory:start']) -gulp.task('test:browser:after', ['factory:stop']) - -require('aegir/gulp')(gulp) diff --git a/package.json b/package.json index 5e25107de..0fcdeb828 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,16 @@ "http": "stream-http" }, "scripts": { - "test": "gulp test", - "test:node": "gulp test:node", - "test:browser": "gulp test:browser", - "lint": "aegir-lint", - "build": "gulp build", - "release": "gulp release", - "release-minor": "gulp release --type minor", - "release-major": "gulp release --type major", - "coverage": "gulp coverage", - "coverage-publish": "aegir-coverage publish" + "test": "aegir test --no-parallel", + "test:node": "aegir test --target node --no-parallel", + "test:browser": "aegir test --target browser", + "lint": "aegir lint", + "build": "aegir build", + "release": "aegir release --no-parallel", + "release-minor": "aegir release --type minor --no-parallel", + "release-major": "aegir release --type major --no-parallel", + "coverage": "aegir coverage --no-parallel --timeout 100000", + "coverage-publish": "aegir coverage --provider coveralls --no-parallel --timeout 100000" }, "dependencies": { "async": "^2.5.0", @@ -36,13 +36,13 @@ "is-ipfs": "^0.3.0", "is-stream": "^1.1.0", "lru-cache": "^4.1.1", - "multiaddr": "^2.3.0", + "multiaddr": "^3.0.0", "multihashes": "~0.4.9", "multipart-stream": "^2.0.1", "ndjson": "^1.5.0", "once": "^1.4.0", - "peer-id": "~0.9.0", - "peer-info": "~0.10.0", + "peer-id": "~0.10.0", + "peer-info": "~0.11.0", "promisify-es6": "^1.0.3", "pump": "^1.0.2", "qs": "^6.5.0", @@ -52,7 +52,7 @@ "tar-stream": "^1.5.4" }, "engines": { - "node": ">=4.0.0", + "node": ">=6.0.0", "npm": ">=3.0.0" }, "repository": { @@ -60,13 +60,13 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^11.0.2", + "aegir": "^12.0.2", "chai": "^4.1.2", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.3.0", "gulp": "^3.9.1", "hapi": "^16.5.2", - "interface-ipfs-core": "~0.31.16", + "interface-ipfs-core": "~0.31.18", "ipfsd-ctl": "~0.22.0", "pre-commit": "^1.2.2", "socket.io": "^2.0.3", @@ -136,4 +136,4 @@ "url": "https://github.com/ipfs/js-ipfs-api/issues" }, "homepage": "https://github.com/ipfs/js-ipfs-api" -} \ No newline at end of file +} diff --git a/src/config/replace.js b/src/config/replace.js index 14f4294ca..f6a41df97 100644 --- a/src/config/replace.js +++ b/src/config/replace.js @@ -6,7 +6,7 @@ const promisify = require('promisify-es6') module.exports = (send) => { return promisify((config, callback) => { if (typeof config === 'object') { - config = streamifier.createReadStream(new Buffer(JSON.stringify(config))) + config = streamifier.createReadStream(Buffer.from(JSON.stringify(config))) } send({ diff --git a/src/object/get.js b/src/object/get.js index 319ab12ce..5f0f80e10 100644 --- a/src/object/get.js +++ b/src/object/get.js @@ -45,7 +45,7 @@ module.exports = (send) => { } const links = result.Links.map((l) => { - return new DAGLink(l.Name, l.Size, new Buffer(bs58.decode(l.Hash))) + return new DAGLink(l.Name, l.Size, Buffer.from(bs58.decode(l.Hash))) }) DAGNode.create(result.Data, links, (err, node) => { diff --git a/src/object/links.js b/src/object/links.js index e3ab1c7dd..9b4f6284e 100644 --- a/src/object/links.js +++ b/src/object/links.js @@ -46,7 +46,7 @@ module.exports = (send) => { if (result.Links) { links = result.Links.map((l) => { - return new DAGLink(l.Name, l.Size, new Buffer(bs58.decode(l.Hash))) + return new DAGLink(l.Name, l.Size, Buffer.from(bs58.decode(l.Hash))) }) } callback(null, links) diff --git a/src/object/new.js b/src/object/new.js index c9a08ad02..e508be129 100644 --- a/src/object/new.js +++ b/src/object/new.js @@ -27,7 +27,7 @@ module.exports = (send) => { } data = (new Unixfs('directory')).marshal() } else { - data = new Buffer(0) + data = Buffer.alloc(0) } DAGNode.create(data, (err, node) => { diff --git a/src/object/put.js b/src/object/put.js index e7ef76c39..537c9d34f 100644 --- a/src/object/put.js +++ b/src/object/put.js @@ -52,7 +52,7 @@ module.exports = (send) => { if (Buffer.isBuffer(obj) && options.enc) { buf = obj } else { - buf = new Buffer(JSON.stringify(tmpObj)) + buf = Buffer.from(JSON.stringify(tmpObj)) } const enc = options.enc || 'json' @@ -87,7 +87,7 @@ module.exports = (send) => { }) return } else { - DAGNode.create(new Buffer(obj.Data), obj.Links, (err, _node) => { + DAGNode.create(Buffer.from(obj.Data), obj.Links, (err, _node) => { if (err) { return callback(err) } diff --git a/src/utils/get-dagnode.js b/src/utils/get-dagnode.js index 02cc8e139..edb89c4d9 100644 --- a/src/utils/get-dagnode.js +++ b/src/utils/get-dagnode.js @@ -14,14 +14,13 @@ module.exports = function (send, hash, callback) { // Retrieve the object and its data in parallel, then produce a DAGNode // instance using this information. parallel([ - function get (done) { + (done) => { send({ path: 'object/get', args: multihash }, done) }, - - function data (done) { + (done) => { // WORKAROUND: request the object's data separately, since raw bits in JSON // are interpreted as UTF-8 and corrupt the data. // See https://github.com/ipfs/go-ipfs/issues/1582 for more details. @@ -29,25 +28,24 @@ module.exports = function (send, hash, callback) { path: 'object/data', args: multihash }, done) - }], - - function done (err, res) { - if (err) { - return callback(err) - } + } + ], (err, res) => { + if (err) { + return callback(err) + } - var object = res[0] - var stream = res[1] + var object = res[0] + var stream = res[1] - if (Buffer.isBuffer(stream)) { - DAGNode.create(stream, object.Links, callback) - } else { - streamToValue(stream, (err, data) => { - if (err) { - return callback(err) - } - DAGNode.create(data, object.Links, callback) - }) - } - }) + if (Buffer.isBuffer(stream)) { + DAGNode.create(stream, object.Links, callback) + } else { + streamToValue(stream, (err, data) => { + if (err) { + return callback(err) + } + DAGNode.create(data, object.Links, callback) + }) + } + }) } diff --git a/src/utils/get-files-stream.js b/src/utils/get-files-stream.js index f931fb5c0..b283cee7a 100644 --- a/src/utils/get-files-stream.js +++ b/src/utils/get-files-stream.js @@ -25,9 +25,9 @@ function headers (file) { function strip (name, base) { const smallBase = base - .split('/') - .slice(0, -1) - .join('/') + '/' + .split('/') + .slice(0, -1) + .join('/') + '/' return name.replace(smallBase, '') } diff --git a/src/utils/pubsub-message-utils.js b/src/utils/pubsub-message-utils.js index ae7ec6bab..486632f53 100644 --- a/src/utils/pubsub-message-utils.js +++ b/src/utils/pubsub-message-utils.js @@ -27,9 +27,9 @@ function deserializeFromBase64 (obj) { } return { - from: bs58.encode(new Buffer(obj.from, 'base64')).toString(), - seqno: new Buffer(obj.seqno, 'base64'), - data: new Buffer(obj.data, 'base64'), + from: bs58.encode(Buffer.from(obj.from, 'base64')).toString(), + seqno: Buffer.from(obj.seqno, 'base64'), + data: Buffer.from(obj.data, 'base64'), topicCIDs: obj.topicIDs || obj.topicCIDs } } diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js index 6ed821da3..35cd7a855 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -7,11 +7,12 @@ const expect = chai.expect chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') -describe('.bitswap', () => { +describe('.bitswap', function () { + this.timeout(20 * 1000) // slow CI let ipfs let fc - before(function (done) { + before((done) => { this.timeout(20 * 1000) // slow CI fc = new FactoryClient() fc.spawnNode((err, node) => { diff --git a/test/bootstrap.spec.js b/test/bootstrap.spec.js index 041b069d9..65b053485 100644 --- a/test/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -11,12 +11,13 @@ const FactoryClient = require('./ipfs-factory/client') const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' -describe('.bootstrap', () => { +describe('.bootstrap', function () { + this.timeout(100 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() @@ -31,7 +32,9 @@ describe('.bootstrap', () => { let peers - describe('Callback API', () => { + describe('Callback API', function () { + this.timeout(100 * 1000) + describe('.add', () => { it('returns an error when called with an invalid arg', (done) => { ipfs.bootstrap.add(invalidArg, (err) => { @@ -112,7 +115,9 @@ describe('.bootstrap', () => { }) }) - describe('Promise API', () => { + describe('Promise API', function () { + this.timeout(100 * 1000) + describe('.add', () => { it('returns an error when called without args or options', () => { return ipfs.bootstrap.add(null) diff --git a/test/commands.spec.js b/test/commands.spec.js index c5553d83b..5962d47fb 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -8,12 +8,13 @@ chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') -describe('.commands', () => { +describe('.commands', function () { + this.timeout(20 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() diff --git a/test/diag.spec.js b/test/diag.spec.js index 94ee50bb3..7a74e2be5 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -7,12 +7,13 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -describe('.diag', () => { +describe('.diag', function () { + this.timeout(50 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() diff --git a/test/files.spec.js b/test/files.spec.js index d5712fe62..0a597c8a6 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -15,12 +15,13 @@ const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') : loadFixture(__dirname, 'fixtures/testfile.txt') -describe('.files (the MFS API part)', () => { +describe('.files (the MFS API part)', function () { + this.timeout(120 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() @@ -31,7 +32,9 @@ describe('.files (the MFS API part)', () => { after((done) => fc.dismantle(done)) - describe('Callback API', () => { + describe('Callback API', function () { + this.timeout(120 * 1000) + it('add file for testing', (done) => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' @@ -83,7 +86,7 @@ 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) => { + .write('/test-folder/test-file-2.txt', Buffer.from('hello world'), {create: true}, (err) => { expect(err).to.not.exist() ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { @@ -105,7 +108,7 @@ 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) => { + .write('/test-folder/test-file-2.txt', Buffer.from('hello world'), (err) => { expect(err).to.not.exist() ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { @@ -168,7 +171,7 @@ describe('.files (the MFS API part)', () => { buf += data }) .on('end', () => { - expect(new Buffer(buf)).to.deep.equal(testfile) + expect(Buffer.from(buf)).to.deep.equal(testfile) done() }) }) @@ -183,7 +186,9 @@ describe('.files (the MFS API part)', () => { }) }) - describe('Promise API', () => { + describe('Promise API', function () { + this.timeout(120 * 1000) + it('files.add with cid-version=1 and raw-leaves=false', () => { const expectedHash = 'zdj7Wh9x6gXdg4UAqhRYnjBTw9eJF7hvzUU4HjpnZXHYQz9jK' const options = { 'cid-version': 1, 'raw-leaves': false } @@ -214,7 +219,7 @@ 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}) + .write('/test-folder/test-file-2.txt', Buffer.from('hello world'), {create: true}) .then(() => { return ipfs.files.read('/test-folder/test-file-2.txt') }) @@ -237,7 +242,7 @@ 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')) + .write('/test-folder/test-file-2.txt', Buffer.from('hello world')) .then(() => { return ipfs.files.read('/test-folder/test-file-2.txt') }) @@ -293,7 +298,7 @@ describe('.files (the MFS API part)', () => { buf += data }) .on('end', () => { - expect(new Buffer(buf)).to.deep.equal(testfile) + expect(Buffer.from(buf)).to.eql(testfile) done() }) }) diff --git a/test/get.spec.js b/test/get.spec.js index 66cc477be..f401235d1 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -25,12 +25,13 @@ if (isNode) { testfileBig = fs.createReadStream(tfbPath, { bufferSize: 128 }) } -describe('.get', () => { +describe('.get', function () { + this.timeout(80 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() @@ -42,6 +43,8 @@ describe('.get', () => { after((done) => fc.dismantle(done)) describe('Callback API', () => { + this.timeout(80 * 1000) + it('add file for testing', (done) => { const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' @@ -190,6 +193,8 @@ describe('.get', () => { }) describe('Promise API', () => { + this.timeout(80 * 1000) + it('get', (done) => { ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((files) => { @@ -206,9 +211,9 @@ describe('.get', () => { }) }) }) - .catch((err) => { - expect(err).to.not.exist() - }) + .catch((err) => { + expect(err).to.not.exist() + }) }) }) }) diff --git a/test/ipfs-factory/client.js b/test/ipfs-factory/client.js index 5d2685b5c..d30b08966 100644 --- a/test/ipfs-factory/client.js +++ b/test/ipfs-factory/client.js @@ -49,7 +49,11 @@ function Factory () { } this.dismantle = function (callback) { - ioC.once('fc-nodes-shutdown', callback) + ioC.once('fc-nodes-shutdown', (err) => { + ioC.disconnect() + sioConnected = false + callback(err) + }) ioC.emit('fs-dismantle') } } diff --git a/test/ipfs-factory/tasks.js b/test/ipfs-factory/tasks.js index 97847273e..eca18f8f3 100644 --- a/test/ipfs-factory/tasks.js +++ b/test/ipfs-factory/tasks.js @@ -1,20 +1,22 @@ 'use strict' -const gulp = require('gulp') const factoryServer = require('./server') let factory -gulp.task('factory:start', (done) => { - factoryServer((err, http) => { - if (err) { - throw err - } - factory = http - done() - }) -}) - -gulp.task('factory:stop', (done) => { - factory.stop(done) -}) +module.exports = { + start (done) { + factoryServer((err, http) => { + if (err) { + return done(err) + } + factory = http + done() + }) + }, + stop (done) { + factory.stop({ + timeout: 1 + }, done) + } +} diff --git a/test/key.spec.js b/test/key.spec.js index 7521e9597..9942372b0 100644 --- a/test/key.spec.js +++ b/test/key.spec.js @@ -8,12 +8,13 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -describe('.key', () => { +describe('.key', function () { + this.timeout(50 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() diff --git a/test/log.spec.js b/test/log.spec.js index 4ed6b81bb..24d4fe11c 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -8,12 +8,13 @@ const expect = chai.expect chai.use(dirtyChai) const FactoryClient = require('./ipfs-factory/client') -describe('.log', () => { +describe('.log', function () { + this.timeout(100 * 1000) + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() @@ -24,7 +25,9 @@ describe('.log', () => { after((done) => fc.dismantle(done)) - describe('Callback API', () => { + describe('Callback API', function () { + this.timeout(100 * 1000) + it('.log.tail', (done) => { const req = ipfs.log.tail((err, res) => { expect(err).to.not.exist() @@ -62,7 +65,9 @@ describe('.log', () => { }) }) - describe('Promise API', () => { + describe('Promise API', function () { + this.timeout(100 * 1000) + it('.log.tail', () => { return ipfs.log.tail() .then((res) => { diff --git a/test/ls.spec.js b/test/ls.spec.js index cc7a64195..0b2bcc828 100644 --- a/test/ls.spec.js +++ b/test/ls.spec.js @@ -11,15 +11,16 @@ const path = require('path') const FactoryClient = require('./ipfs-factory/client') -describe('.ls', () => { +describe('.ls', function () { + this.timeout(50 * 1000) + if (!isNode) { return } let ipfs let fc let folder - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() waterfall([ (cb) => fc.spawnNode(cb), diff --git a/test/mount.spec.js b/test/mount.spec.js index 19dc68fa3..15f725edb 100644 --- a/test/mount.spec.js +++ b/test/mount.spec.js @@ -2,4 +2,6 @@ 'use strict' // requires FUSE to be installed, not practical for testing -describe('.mount', () => {}) +describe('.mount', () => { + it('missing') +}) diff --git a/test/name.spec.js b/test/name.spec.js index b556afe28..37af50183 100644 --- a/test/name.spec.js +++ b/test/name.spec.js @@ -14,13 +14,14 @@ const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') : loadFixture(__dirname, 'fixtures/testfile.txt') -describe('.name', () => { +describe('.name', function () { + this.timeout(50 * 1000) + let ipfs let other let fc - before(function (done) { - this.timeout(50 * 1000) // slow CI + before((done) => { fc = new FactoryClient() series([ (cb) => { diff --git a/test/pubsub-in-browser.spec.js b/test/pubsub-in-browser.spec.js index 53b50d1ec..b6efe9f5c 100644 --- a/test/pubsub-in-browser.spec.js +++ b/test/pubsub-in-browser.spec.js @@ -50,133 +50,137 @@ function spawnWithId (factory, callback) { ], callback) } -if (!isNode) { - describe('.pubsub-browser (pubsub not supported in the browsers currently)', () => { - const topic = 'pubsub-tests' +describe('.pubsub-browser (pubsub not supported in the browsers currently)', function () { + this.timeout(50 * 1000) - let factory - let ipfs1 + if (isNode) { + it('skip these in Node.js') + return + } + const topic = 'pubsub-tests' - before((done) => { - factory = new FactoryClient() + let factory + let ipfs1 - series([ - (cb) => spawnWithId(factory, cb) - ], (err, nodes) => { - if (err) { - return done(err) - } + before((done) => { + factory = new FactoryClient() - ipfs1 = nodes[0] - done() - }) - }) + series([ + (cb) => spawnWithId(factory, cb) + ], (err, nodes) => { + if (err) { + return done(err) + } - after((done) => { - factory.dismantle(done) + ipfs1 = nodes[0] + done() }) + }) - describe('everything errors', () => { - describe('Callback API', () => { - describe('.publish', () => { - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.publish(topic, 'hello friend', (err, topics) => { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - done() - }) + after((done) => { + factory.dismantle(done) + }) + + describe('everything errors', () => { + describe('Callback API', () => { + describe('.publish', () => { + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.publish(topic, 'hello friend', (err, topics) => { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + done() + }) + }) + }) + + describe('.subscribe', () => { + const handler = () => {} + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.subscribe(topic, {}, handler, (err, topics) => { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + done() + }) + }) + }) + + describe('.peers', () => { + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.peers(topic, (err, topics) => { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + done() }) }) + }) - describe('.subscribe', () => { - const handler = () => {} - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler, (err, topics) => { + describe('.ls', () => { + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.ls((err, topics) => { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + done() + }) + }) + }) + }) + + describe('Promise API', () => { + describe('.publish', () => { + it('throws an error if called in the browser', () => { + return ipfs1.pubsub.publish(topic, 'hello friend') + .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) - done() }) - }) }) + }) - describe('.peers', () => { - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic, (err, topics) => { + describe('.subscribe', () => { + const handler = () => {} + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.subscribe(topic, {}, handler) + .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() }) - }) }) + }) - describe('.ls', () => { - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.ls((err, topics) => { + describe('.peers', () => { + it('throws an error if called in the browser', (done) => { + ipfs1.pubsub.peers(topic) + .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() }) - }) }) }) - describe('Promise API', () => { - describe('.publish', () => { - it('throws an error if called in the browser', () => { - return ipfs1.pubsub.publish(topic, 'hello friend') - .catch((err) => { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - }) - }) - }) - - describe('.subscribe', () => { - const handler = () => {} - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler) - .catch((err) => { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - done() - }) - }) - }) - - describe('.peers', () => { - it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic) - .catch((err) => { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - done() - }) - }) - }) - - describe('.ls', () => { - it('throws an error if called in the browser', () => { - return ipfs1.pubsub.ls() - .catch((err) => { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - }) - }) + describe('.ls', () => { + it('throws an error if called in the browser', () => { + return ipfs1.pubsub.ls() + .catch((err) => { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + }) }) }) + }) - describe('.unsubscribe', () => { - it('throws an error if called in the browser', (done) => { - try { - ipfs1.pubsub.unsubscribe() - done('unsubscribe() didn\'t throw an error') - } catch (err) { - expect(err).to.exist() - expect(err.message).to.equal(expectedError) - done() - } - }) + describe('.unsubscribe', () => { + it('throws an error if called in the browser', (done) => { + try { + ipfs1.pubsub.unsubscribe() + done('unsubscribe() didn\'t throw an error') + } catch (err) { + expect(err).to.exist() + expect(err.message).to.equal(expectedError) + done() + } }) }) }) -} +}) diff --git a/test/refs.spec.js b/test/refs.spec.js index 7ca22d687..9faedc905 100644 --- a/test/refs.spec.js +++ b/test/refs.spec.js @@ -10,15 +10,16 @@ const waterfall = require('async/waterfall') const path = require('path') const FactoryClient = require('./ipfs-factory/client') -describe('.refs', () => { +describe('.refs', function () { + this.timeout(80 * 1000) + if (!isNode) { return } let ipfs let fc let folder - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() waterfall([ (cb) => fc.spawnNode(cb), diff --git a/test/repo.spec.js b/test/repo.spec.js index fef637e06..0af2a0001 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -7,12 +7,13 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -describe('.repo', () => { +describe('.repo', function () { + this.timeout(50 * 1000) // slow CI + let ipfs let fc - before(function (done) { - this.timeout(20 * 1000) // slow CI + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { expect(err).to.not.exist() From 83156820b0ba3d176ab86b7ab55d7dda1c7959cf Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 14:10:40 +0100 Subject: [PATCH 02/20] chore: update contributors From 6db384425dd55efb9c4cc6f409676eb439c42561 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 14:10:41 +0100 Subject: [PATCH 03/20] chore: release version v14.3.0 --- CHANGELOG.md | 242 +-------------------------------------------------- package.json | 2 +- 2 files changed, 4 insertions(+), 240 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index affd846f8..380277d9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,246 +1,10 @@ - -## [14.2.1](https://github.com/ipfs/js-ipfs-api/compare/v14.2.0...v14.2.1) (2017-09-02) - - -### Bug Fixes - -* regression caused by 322b756 ([#591](https://github.com/ipfs/js-ipfs-api/issues/591)) ([8affcfe](https://github.com/ipfs/js-ipfs-api/commit/8affcfe)) - - - - -# [14.2.0](https://github.com/ipfs/js-ipfs-api/compare/v14.1.2...v14.2.0) (2017-09-02) - - -### Features - -* Allow --cid-version option to be passed to ipfs files add ([#589](https://github.com/ipfs/js-ipfs-api/issues/589)) ([717c72f](https://github.com/ipfs/js-ipfs-api/commit/717c72f)) -* Preserve "+" in file paths. ([#588](https://github.com/ipfs/js-ipfs-api/issues/588)) ([322b756](https://github.com/ipfs/js-ipfs-api/commit/322b756)) -* test against latest go-ipfs ([#590](https://github.com/ipfs/js-ipfs-api/issues/590)) ([40c8f10](https://github.com/ipfs/js-ipfs-api/commit/40c8f10)) - - - - -## [14.1.2](https://github.com/ipfs/js-ipfs-api/compare/v14.1.1...v14.1.2) (2017-08-06) - - - - -## [14.1.1](https://github.com/ipfs/js-ipfs-api/compare/v14.1.0...v14.1.1) (2017-07-26) - - -### Bug Fixes - -* [#572](https://github.com/ipfs/js-ipfs-api/issues/572) ([3354901](https://github.com/ipfs/js-ipfs-api/commit/3354901)) - - - - -# [14.1.0](https://github.com/ipfs/js-ipfs-api/compare/v14.0.4...v14.1.0) (2017-07-22) - - -### Bug Fixes - -* circle ci, thanks victor! ([88b6705](https://github.com/ipfs/js-ipfs-api/commit/88b6705)) - - - - -## [14.0.4](https://github.com/ipfs/js-ipfs-api/compare/v14.0.3...v14.0.4) (2017-06-21) - - -### Bug Fixes - -* don't let qs mangle binary buffers ([#569](https://github.com/ipfs/js-ipfs-api/issues/569)) ([#570](https://github.com/ipfs/js-ipfs-api/issues/570)) ([6cbd89c](https://github.com/ipfs/js-ipfs-api/commit/6cbd89c)) - - - - -## [14.0.3](https://github.com/ipfs/js-ipfs-api/compare/v14.0.2...v14.0.3) (2017-05-29) - - - - -## [14.0.2](https://github.com/ipfs/js-ipfs-api/compare/v14.0.1...v14.0.2) (2017-05-19) - - -### Features - -* Use CID for api.get/api.cat ([#555](https://github.com/ipfs/js-ipfs-api/issues/555)) ([da7d0f4](https://github.com/ipfs/js-ipfs-api/commit/da7d0f4)) - - - - -## [14.0.1](https://github.com/ipfs/js-ipfs-api/compare/v14.0.0...v14.0.1) (2017-05-04) - - - - -# [14.0.0](https://github.com/ipfs/js-ipfs-api/compare/v13.0.0...v14.0.0) (2017-03-30) - - -### Features - -* new peer-info ([#542](https://github.com/ipfs/js-ipfs-api/issues/542)) ([820150c](https://github.com/ipfs/js-ipfs-api/commit/820150c)) -* **pubsub:** Add pubsub api ([#493](https://github.com/ipfs/js-ipfs-api/issues/493)) ([d2eb925](https://github.com/ipfs/js-ipfs-api/commit/d2eb925)) - - - - -# [13.0.0](https://github.com/ipfs/js-ipfs-api/compare/v12.1.7...v13.0.0) (2017-03-22) + +# [14.3.0](https://github.com/ipfs/js-ipfs-api/compare/v14.2.1...v14.3.0) (2017-09-04) ### Features -* change window to self for webworker support ([e2e3213](https://github.com/ipfs/js-ipfs-api/commit/e2e3213)) - - - - -## [12.1.7](https://github.com/ipfs/js-ipfs-api/compare/v12.1.6...v12.1.7) (2017-02-09) - - - - -## [12.1.6](https://github.com/ipfs/js-ipfs-api/compare/v12.1.5...v12.1.6) (2017-02-01) - - - - -## [12.1.5](https://github.com/ipfs/js-ipfs-api/compare/v12.1.4...v12.1.5) (2017-01-31) - - -### Bug Fixes - -* lint ([dfb07a3](https://github.com/ipfs/js-ipfs-api/commit/dfb07a3)) - - - - -## [12.1.4](https://github.com/ipfs/js-ipfs-api/compare/v12.1.3...v12.1.4) (2017-01-11) - - - - -## [12.1.3](https://github.com/ipfs/js-ipfs-api/compare/v12.1.2...v12.1.3) (2017-01-10) +* migrate to next AEgir (v12) ([9ffe848](https://github.com/ipfs/js-ipfs-api/commit/9ffe848)) - -## [12.1.2](https://github.com/ipfs/js-ipfs-api/compare/v12.1.1...v12.1.2) (2016-12-21) - - - - -## [12.1.1](https://github.com/ipfs/js-ipfs-api/compare/v12.1.0...v12.1.1) (2016-12-21) - - - - -# [12.1.0](https://github.com/ipfs/js-ipfs-api/compare/v12.0.3...v12.1.0) (2016-12-12) - - -### Features - -* **object:** add template support to object.new ([2784863](https://github.com/ipfs/js-ipfs-api/commit/2784863)) - - - - -## [12.0.3](https://github.com/ipfs/js-ipfs-api/compare/v12.0.2...v12.0.3) (2016-12-09) - - -### Bug Fixes - -* block.get supports multihash as buffers again ([b3dbe45](https://github.com/ipfs/js-ipfs-api/commit/b3dbe45)) - - - - -## [12.0.2](https://github.com/ipfs/js-ipfs-api/compare/v12.0.1...v12.0.2) (2016-12-01) - - - - -## [12.0.1](https://github.com/ipfs/js-ipfs-api/compare/v12.0.0...v12.0.1) (2016-11-28) - - - - -# [12.0.0](https://github.com/ipfs/js-ipfs-api/compare/v11.2.0...v12.0.0) (2016-11-24) - - - - -# [11.2.0](https://github.com/ipfs/js-ipfs-api/compare/v11.1.0...v11.2.0) (2016-11-24) - - -### Bug Fixes - -* handle missing daemon errors ([41c8153](https://github.com/ipfs/js-ipfs-api/commit/41c8153)) -* linting ([723b4b0](https://github.com/ipfs/js-ipfs-api/commit/723b4b0)) - - -### Features - -* **swarm:** support for new swarm.peers in 0.4.5 ([690a77c](https://github.com/ipfs/js-ipfs-api/commit/690a77c)) -* upgrade to awesome dag-pb ([1e82b8c](https://github.com/ipfs/js-ipfs-api/commit/1e82b8c)) - - - - -# [11.1.0](https://github.com/ipfs/js-ipfs-api/compare/v11.0.1...v11.1.0) (2016-11-08) - - -### Bug Fixes - -* **get:** properly handled nested content ([0731f45](https://github.com/ipfs/js-ipfs-api/commit/0731f45)) - - -### Features - -* **object:** add lru cache to object get/put ([c439f39](https://github.com/ipfs/js-ipfs-api/commit/c439f39)) -* add npm engine ([505ce8e](https://github.com/ipfs/js-ipfs-api/commit/505ce8e)) -* update interface-ipfs-core ([1191bb6](https://github.com/ipfs/js-ipfs-api/commit/1191bb6)) - - - - -## [11.0.1](https://github.com/ipfs/js-ipfs-api/compare/v11.0.0...v11.0.1) (2016-10-29) - - - - -# [11.0.0](https://github.com/ipfs/js-ipfs-api/compare/v10.0.0...v11.0.0) (2016-10-29) - - -### Bug Fixes - -* increase memory (to enable release until we got the size of the bundle shaved down ([12c9660](https://github.com/ipfs/js-ipfs-api/commit/12c9660)) - - - - -# [10.0.0](https://github.com/ipfs/js-ipfs-api/compare/v9.0.0...v10.0.0) (2016-10-28) - - -### Features - -* disable phantomJS ([b634684](https://github.com/ipfs/js-ipfs-api/commit/b634684)) -* support new CID block API ([4314815](https://github.com/ipfs/js-ipfs-api/commit/4314815)) -* update files to use async dag-pb api ([ad96d22](https://github.com/ipfs/js-ipfs-api/commit/ad96d22)) - - - - -# [9.0.0](https://github.com/ipfs/js-ipfs-api/compare/v8.0.4...v9.0.0) (2016-09-15) - - -### Bug Fixes - -* Return req from tail ([0273a3a](https://github.com/ipfs/js-ipfs-api/commit/0273a3a)) - - -### Features - -* **swarm:** make interface-ipfs-core compliant ([f245f27](https://github.com/ipfs/js-ipfs-api/commit/f245f27)) diff --git a/package.json b/package.json index 0fcdeb828..1f75100ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "14.2.1", + "version": "14.3.0", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From afdba3673f496c567f0a71ba3bc7112316c1097c Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 14:49:24 +0100 Subject: [PATCH 04/20] chore: update contributors From f3ae57c94209ad7dd8182742c936a0acd4962b8b Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 14:49:24 +0100 Subject: [PATCH 05/20] chore: release version v14.3.1 --- CHANGELOG.md | 9 ++------- package.json | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 380277d9f..85c1aaf06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,5 @@ - -# [14.3.0](https://github.com/ipfs/js-ipfs-api/compare/v14.2.1...v14.3.0) (2017-09-04) - - -### Features - -* migrate to next AEgir (v12) ([9ffe848](https://github.com/ipfs/js-ipfs-api/commit/9ffe848)) + +## [14.3.1](https://github.com/ipfs/js-ipfs-api/compare/v14.3.0...v14.3.1) (2017-09-04) diff --git a/package.json b/package.json index 1f75100ac..2c426eb86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "14.3.0", + "version": "14.3.1", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From 93ac472a048978935de9ea2f1550aefccd4bc02e Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 18:08:39 +0100 Subject: [PATCH 06/20] fix: new fixed aegir --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2c426eb86..5e0e2f043 100644 --- a/package.json +++ b/package.json @@ -60,13 +60,13 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^12.0.2", + "aegir": "^12.0.3", "chai": "^4.1.2", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.3.0", "gulp": "^3.9.1", "hapi": "^16.5.2", - "interface-ipfs-core": "~0.31.18", + "interface-ipfs-core": "~0.31.19", "ipfsd-ctl": "~0.22.0", "pre-commit": "^1.2.2", "socket.io": "^2.0.3", From b1f27d91fe5c68424e444696c84feb6699134a7e Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 18:08:51 +0100 Subject: [PATCH 07/20] chore: update contributors From c919253e2d34c30a40055b516283e02aa23bc587 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 4 Sep 2017 18:08:51 +0100 Subject: [PATCH 08/20] chore: release version v14.3.2 --- CHANGELOG.md | 9 +++++++-- package.json | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c1aaf06..19c69e526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ - -## [14.3.1](https://github.com/ipfs/js-ipfs-api/compare/v14.3.0...v14.3.1) (2017-09-04) + +## [14.3.2](https://github.com/ipfs/js-ipfs-api/compare/v14.3.1...v14.3.2) (2017-09-04) + + +### Bug Fixes + +* new fixed aegir ([93ac472](https://github.com/ipfs/js-ipfs-api/commit/93ac472)) diff --git a/package.json b/package.json index 5e0e2f043..0b065af64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "14.3.1", + "version": "14.3.2", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From 8c717b2e9d0545b7328f9e94b9a295cf00d450d9 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 6 Sep 2017 11:36:38 +0100 Subject: [PATCH 09/20] feat: support options for .add / files.add --- test/files.spec.js | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/test/files.spec.js b/test/files.spec.js index 0a597c8a6..8ea2f9f58 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -21,6 +21,8 @@ describe('.files (the MFS API part)', function () { let ipfs let fc + const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + before((done) => { fc = new FactoryClient() fc.spawnNode((err, node) => { @@ -36,8 +38,6 @@ describe('.files (the MFS API part)', function () { this.timeout(120 * 1000) it('add file for testing', (done) => { - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - ipfs.files.add(testfile, (err, res) => { expect(err).to.not.exist() @@ -49,15 +49,26 @@ describe('.files (the MFS API part)', function () { }) it('files.add with cid-version=1 and raw-leaves=false', (done) => { - const expectedHash = 'zdj7Wh9x6gXdg4UAqhRYnjBTw9eJF7hvzUU4HjpnZXHYQz9jK' + const expectedCid = 'zdj7Wh9x6gXdg4UAqhRYnjBTw9eJF7hvzUU4HjpnZXHYQz9jK' const options = { 'cid-version': 1, 'raw-leaves': false } ipfs.files.add(testfile, options, (err, res) => { expect(err).to.not.exist() expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedHash) - expect(res[0].path).to.equal(expectedHash) + expect(res[0].hash).to.equal(expectedCid) + expect(res[0].path).to.equal(expectedCid) + done() + }) + }) + + it('files.add with options', (done) => { + ipfs.files.add(testfile, { pin: false }, (err, res) => { + expect(err).to.not.exist() + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) done() }) }) @@ -189,6 +200,15 @@ describe('.files (the MFS API part)', function () { describe('Promise API', function () { this.timeout(120 * 1000) + it('files.add', () => { + return ipfs.files.add(testfile) + .then((res) => { + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) + }) + }) + it('files.add with cid-version=1 and raw-leaves=false', () => { const expectedHash = 'zdj7Wh9x6gXdg4UAqhRYnjBTw9eJF7hvzUU4HjpnZXHYQz9jK' const options = { 'cid-version': 1, 'raw-leaves': false } @@ -201,13 +221,25 @@ describe('.files (the MFS API part)', function () { }) }) + it('files.add with options', () => { + return ipfs.files.add(testfile, { pin: false }) + .then((res) => { + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) + }) + }) + it('files.mkdir', () => { return ipfs.files.mkdir('/test-folder') }) it('files.cp', () => { return ipfs.files - .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file']) + .cp([ + '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + '/test-folder/test-file' + ]) }) it('files.ls', () => { From 76358e95e74e047297b92f1e63ac200ab2d3581d Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 6 Sep 2017 13:11:46 +0100 Subject: [PATCH 10/20] chore: update deps --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0b065af64..f3b0f8935 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "is-ipfs": "^0.3.0", "is-stream": "^1.1.0", "lru-cache": "^4.1.1", - "multiaddr": "^3.0.0", + "multiaddr": "^3.0.1", "multihashes": "~0.4.9", "multipart-stream": "^2.0.1", "ndjson": "^1.5.0", @@ -60,14 +60,14 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^12.0.3", + "aegir": "^12.0.6", "chai": "^4.1.2", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.3.0", "gulp": "^3.9.1", "hapi": "^16.5.2", "interface-ipfs-core": "~0.31.19", - "ipfsd-ctl": "~0.22.0", + "ipfsd-ctl": "~0.23.0", "pre-commit": "^1.2.2", "socket.io": "^2.0.3", "socket.io-client": "^2.0.3", From 4bfc6fa572ef0110c41a80a3fa7ca9a739881fc3 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 11:46:48 +0100 Subject: [PATCH 11/20] chore: update deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f3b0f8935..c831e8a48 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "glob": "^7.1.2", "glob-escape": "0.0.2", "ipfs-block": "~0.6.0", - "ipfs-unixfs": "~0.1.12", - "ipld-dag-pb": "~0.11.0", + "ipfs-unixfs": "~0.1.13", + "ipld-dag-pb": "~0.11.2", "is-ipfs": "^0.3.0", "is-stream": "^1.1.0", "lru-cache": "^4.1.1", From 263116879e66ca49ff87244cffa16e2cee8d7be8 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 12:06:10 +0100 Subject: [PATCH 12/20] chore: update contributors From a704f9616d51dfacee419479749874144cdcba34 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 12:06:10 +0100 Subject: [PATCH 13/20] chore: release version v14.3.3 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c69e526..db0e91d2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [14.3.3](https://github.com/ipfs/js-ipfs-api/compare/v14.3.2...v14.3.3) (2017-09-07) + + +### Features + +* support options for .add / files.add ([8c717b2](https://github.com/ipfs/js-ipfs-api/commit/8c717b2)) + + + ## [14.3.2](https://github.com/ipfs/js-ipfs-api/compare/v14.3.1...v14.3.2) (2017-09-04) diff --git a/package.json b/package.json index c831e8a48..eb920362e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "14.3.2", + "version": "14.3.3", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From 487486cbcb53414a90b8a0c8ac9b7559852f33c7 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 20:47:36 +0100 Subject: [PATCH 14/20] chore: update deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb920362e..7ec308a84 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "multipart-stream": "^2.0.1", "ndjson": "^1.5.0", "once": "^1.4.0", - "peer-id": "~0.10.0", + "peer-id": "~0.10.1", "peer-info": "~0.11.0", "promisify-es6": "^1.0.3", "pump": "^1.0.2", From 0c705e4e13bded87cf4fac8b87ed11439d434a76 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 21:20:36 +0100 Subject: [PATCH 15/20] chore: update contributors From 5aa613baae107a5b8d96e95e568b6461f23f1282 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Sep 2017 21:20:36 +0100 Subject: [PATCH 16/20] chore: release version v14.3.4 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db0e91d2a..e2c2d37d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +## [14.3.4](https://github.com/ipfs/js-ipfs-api/compare/v14.3.3...v14.3.4) (2017-09-07) + + + ## [14.3.3](https://github.com/ipfs/js-ipfs-api/compare/v14.3.2...v14.3.3) (2017-09-07) diff --git a/package.json b/package.json index 7ec308a84..c58c7fefc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "14.3.3", + "version": "14.3.4", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From eb1f356feaafab3da1ba61d266d99504ec63a417 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 4 Sep 2017 10:31:31 +0100 Subject: [PATCH 17/20] WIP support support specify hash alg --- src/files/add.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/files/add.js b/src/files/add.js index d5aac24c5..459302675 100644 --- a/src/files/add.js +++ b/src/files/add.js @@ -21,7 +21,27 @@ module.exports = (send) => { return callback(new Error('"files" must be a buffer, readable stream, or array of objects')) } - const request = { path: 'add', files: files, qs: opts } + const qs = {} + + if (opts['cid-version'] != null) { + qs['cid-version'] = opts['cid-version'] + } else if (opts.cidVersion != null) { + qs['cid-version'] = opts.cidVersion + } + + if (opts['raw-leaves'] != null) { + qs['raw-leaves'] = opts['raw-version'] + } else if (opts.rawLeaves != null) { + qs['raw-leaves'] = opts.rawLeaves + } + + if (opts.hash != null) { + qs.hash = opts.hash + } else if (opts.hashAlg != null) { + qs.hash = opts.hashAlg + } + + const request = { path: 'add', files: files, qs: qs } // Transform the response stream to DAGNode values const transform = (res, callback) => DAGNodeStream.streamToValue(send, res, callback) From 1b5accc58cd56d25bbe71f5bf6486f40375d3c90 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 6 Sep 2017 10:55:50 +0100 Subject: [PATCH 18/20] Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data --- src/files/add.js | 2 +- src/utils/get-dagnode.js | 10 ++------ test/files.spec.js | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/files/add.js b/src/files/add.js index 459302675..81e8734f4 100644 --- a/src/files/add.js +++ b/src/files/add.js @@ -30,7 +30,7 @@ module.exports = (send) => { } if (opts['raw-leaves'] != null) { - qs['raw-leaves'] = opts['raw-version'] + qs['raw-leaves'] = opts['raw-leaves'] } else if (opts.rawLeaves != null) { qs['raw-leaves'] = opts.rawLeaves } diff --git a/src/utils/get-dagnode.js b/src/utils/get-dagnode.js index edb89c4d9..4bcd5d8fd 100644 --- a/src/utils/get-dagnode.js +++ b/src/utils/get-dagnode.js @@ -2,22 +2,16 @@ const DAGNode = require('ipld-dag-pb').DAGNode const parallel = require('async/parallel') -const CID = require('cids') -const mh = require('multihashes') const streamToValue = require('./stream-to-value') module.exports = function (send, hash, callback) { - // Until js-ipfs supports object/get and object/data by CID - // we need to convert our CID or multihash hash into a multihash - const multihash = mh.toB58String(new CID(hash).multihash) - // Retrieve the object and its data in parallel, then produce a DAGNode // instance using this information. parallel([ (done) => { send({ path: 'object/get', - args: multihash + args: hash }, done) }, (done) => { @@ -26,7 +20,7 @@ module.exports = function (send, hash, callback) { // See https://github.com/ipfs/go-ipfs/issues/1582 for more details. send({ path: 'object/data', - args: multihash + args: hash }, done) } ], (err, res) => { diff --git a/test/files.spec.js b/test/files.spec.js index 8ea2f9f58..629e5e9b0 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -8,6 +8,8 @@ const expect = chai.expect chai.use(dirtyChai) const isNode = require('detect-node') const loadFixture = require('aegir/fixtures') +const mh = require('multihashes') +const CID = require('cids') const FactoryClient = require('./ipfs-factory/client') @@ -15,6 +17,18 @@ const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') : loadFixture(__dirname, 'fixtures/testfile.txt') +// TODO: Test against all algorithms Object.keys(mh.names) +// This subset is known to work with both go-ipfs and js-ipfs as of 2017-09-05 +const HASH_ALGS = [ + 'sha1', + 'sha2-256', + 'sha2-512', + 'keccak-224', + 'keccak-256', + 'keccak-384', + 'keccak-512' +] + describe('.files (the MFS API part)', function () { this.timeout(120 * 1000) @@ -73,6 +87,25 @@ describe('.files (the MFS API part)', function () { }) }) + HASH_ALGS.forEach((name) => { + it(`files.add with hash=${name} and raw-leaves=false`, (done) => { + const content = String(Math.random() + Date.now()) + const file = { + path: content + '.txt', + content: Buffer.from(content) + } + const options = { hash: name, 'raw-leaves': false } + + ipfs.files.add([file], options, (err, res) => { + if (err) return done(err) + expect(res).to.have.length(1) + const cid = new CID(res[0].hash) + expect(mh.decode(cid.multihash).name).to.equal(name) + done() + }) + }) + }) + it('files.mkdir', (done) => { ipfs.files.mkdir('/test-folder', done) }) @@ -230,6 +263,24 @@ describe('.files (the MFS API part)', function () { }) }) + HASH_ALGS.forEach((name) => { + it(`files.add with hash=${name} and raw-leaves=false`, () => { + const content = String(Math.random() + Date.now()) + const file = { + path: content + '.txt', + content: Buffer.from(content) + } + const options = { hash: name, 'raw-leaves': false } + + return ipfs.files.add([file], options) + .then((res) => { + expect(res).to.have.length(1) + const cid = new CID(res[0].hash) + expect(mh.decode(cid.multihash).name).to.equal(name) + }) + }) + }) + it('files.mkdir', () => { return ipfs.files.mkdir('/test-folder') }) From 19fcd7b3871596e5c6f87ed5b9a22e3d9ce14a6e Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 7 Sep 2017 17:32:09 +0100 Subject: [PATCH 19/20] Allow object get/data to accept CID --- src/object/data.js | 13 ++++++++----- src/object/get.js | 15 +++++++++------ src/utils/get-dagnode.js | 13 +++++++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/object/data.js b/src/object/data.js index 9ba2ef100..1f0ebb55a 100644 --- a/src/object/data.js +++ b/src/object/data.js @@ -2,7 +2,7 @@ const promisify = require('promisify-es6') const streamToValue = require('../utils/stream-to-value') -const cleanMultihash = require('../utils/clean-multihash') +const CID = require('cids') const LRU = require('lru-cache') const lruOptions = { max: 128 @@ -11,7 +11,7 @@ const lruOptions = { const cache = LRU(lruOptions) module.exports = (send) => { - return promisify((multihash, options, callback) => { + return promisify((hash, options, callback) => { if (typeof options === 'function') { callback = options options = {} @@ -20,13 +20,16 @@ module.exports = (send) => { options = {} } + let cid, b58Hash + try { - multihash = cleanMultihash(multihash, options) + cid = new CID(hash) + b58Hash = cid.toBaseEncodedString() } catch (err) { return callback(err) } - const node = cache.get(multihash) + const node = cache.get(b58Hash) if (node) { return callback(null, node.data) @@ -34,7 +37,7 @@ module.exports = (send) => { send({ path: 'object/data', - args: multihash + args: b58Hash }, (err, result) => { if (err) { return callback(err) diff --git a/src/object/get.js b/src/object/get.js index 5f0f80e10..4649a9c74 100644 --- a/src/object/get.js +++ b/src/object/get.js @@ -5,7 +5,7 @@ const dagPB = require('ipld-dag-pb') const DAGNode = dagPB.DAGNode const DAGLink = dagPB.DAGLink const bs58 = require('bs58') -const cleanMultihash = require('../utils/clean-multihash') +const CID = require('cids') const LRU = require('lru-cache') const lruOptions = { max: 128 @@ -14,7 +14,7 @@ const lruOptions = { const cache = LRU(lruOptions) module.exports = (send) => { - return promisify((multihash, options, callback) => { + return promisify((hash, options, callback) => { if (typeof options === 'function') { callback = options options = {} @@ -24,13 +24,16 @@ module.exports = (send) => { options = {} } + let cid, b58Hash + try { - multihash = cleanMultihash(multihash, options) + cid = new CID(hash) + b58Hash = cid.toBaseEncodedString() } catch (err) { return callback(err) } - const node = cache.get(multihash) + const node = cache.get(b58Hash) if (node) { return callback(null, node) @@ -38,7 +41,7 @@ module.exports = (send) => { send({ path: 'object/get', - args: multihash + args: b58Hash }, (err, result) => { if (err) { return callback(err) @@ -52,7 +55,7 @@ module.exports = (send) => { if (err) { return callback(err) } - cache.set(multihash, node) + cache.set(b58Hash, node) callback(null, node) }) }) diff --git a/src/utils/get-dagnode.js b/src/utils/get-dagnode.js index 4bcd5d8fd..1cfd1dcd7 100644 --- a/src/utils/get-dagnode.js +++ b/src/utils/get-dagnode.js @@ -2,16 +2,25 @@ const DAGNode = require('ipld-dag-pb').DAGNode const parallel = require('async/parallel') +const CID = require('cids') const streamToValue = require('./stream-to-value') module.exports = function (send, hash, callback) { + let cid + + try { + cid = new CID(hash) + } catch (err) { + return callback(err) + } + // Retrieve the object and its data in parallel, then produce a DAGNode // instance using this information. parallel([ (done) => { send({ path: 'object/get', - args: hash + args: cid.toBaseEncodedString() }, done) }, (done) => { @@ -20,7 +29,7 @@ module.exports = function (send, hash, callback) { // See https://github.com/ipfs/go-ipfs/issues/1582 for more details. send({ path: 'object/data', - args: hash + args: cid.toBaseEncodedString() }, done) } ], (err, res) => { From ea96f21f5e465e892a3d39fe95c70dfb068c8a53 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 8 Sep 2017 12:31:17 +0100 Subject: [PATCH 20/20] Var naming tweaks from review --- src/object/data.js | 12 ++++++------ src/object/get.js | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/object/data.js b/src/object/data.js index 1f0ebb55a..ace3cc992 100644 --- a/src/object/data.js +++ b/src/object/data.js @@ -11,7 +11,7 @@ const lruOptions = { const cache = LRU(lruOptions) module.exports = (send) => { - return promisify((hash, options, callback) => { + return promisify((cid, options, callback) => { if (typeof options === 'function') { callback = options options = {} @@ -20,16 +20,16 @@ module.exports = (send) => { options = {} } - let cid, b58Hash + let cidB58Str try { - cid = new CID(hash) - b58Hash = cid.toBaseEncodedString() + cid = new CID(cid) + cidB58Str = cid.toBaseEncodedString() } catch (err) { return callback(err) } - const node = cache.get(b58Hash) + const node = cache.get(cidB58Str) if (node) { return callback(null, node.data) @@ -37,7 +37,7 @@ module.exports = (send) => { send({ path: 'object/data', - args: b58Hash + args: cidB58Str }, (err, result) => { if (err) { return callback(err) diff --git a/src/object/get.js b/src/object/get.js index 4649a9c74..82b21bb58 100644 --- a/src/object/get.js +++ b/src/object/get.js @@ -14,7 +14,7 @@ const lruOptions = { const cache = LRU(lruOptions) module.exports = (send) => { - return promisify((hash, options, callback) => { + return promisify((cid, options, callback) => { if (typeof options === 'function') { callback = options options = {} @@ -24,16 +24,16 @@ module.exports = (send) => { options = {} } - let cid, b58Hash + let cidB58Str try { - cid = new CID(hash) - b58Hash = cid.toBaseEncodedString() + cid = new CID(cid) + cidB58Str = cid.toBaseEncodedString() } catch (err) { return callback(err) } - const node = cache.get(b58Hash) + const node = cache.get(cidB58Str) if (node) { return callback(null, node) @@ -41,7 +41,7 @@ module.exports = (send) => { send({ path: 'object/get', - args: b58Hash + args: cidB58Str }, (err, result) => { if (err) { return callback(err) @@ -55,7 +55,7 @@ module.exports = (send) => { if (err) { return callback(err) } - cache.set(b58Hash, node) + cache.set(cidB58Str, node) callback(null, node) }) })