From f86cb1bf59ce5f903b6572d971702a5f03dcef0a Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Jan 2016 17:49:03 +0100 Subject: [PATCH 1/6] add tests --- package.json | 12 ++- src/cli/commands/daemon.js | 9 ++- src/cli/commands/version.js | 8 +- src/http-api/index.js | 37 +++++++++ src/http-api/resources/index.js | 1 + src/http-api/resources/version.js | 14 ++++ src/http-api/routes/version.js | 8 ++ src/ipfs-core/index.js | 72 +++++++----------- tests/jsipfs-test.js | 57 -------------- ...c55d25f3042c22501e41d1246e7a1e9d3d8ec.data | 0 ...dcf095c1d219356cdf538ffce705a52d5738d.data | Bin ...ea3b310512d7767a9abfbd7a928a85e977173.data | 0 ...0b0d3be3528fbbcc814feb7f2fbf71ca06162.data | Bin ...60e64383755a8c5163ba3c053c3b65777ed16.data | 0 ...ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data | Bin ...223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data | 0 ...932be52c56d99c5966b65e0111239f098bbef.data | 0 ...3346a644605d7614dca53cd3a59f7385a8abb.data | 0 ...7f28fa9367ee167c312e6d65a2e02e81ab815.data | Bin ...68af3d10e1a497971629c07606bfdb812303d.data | Bin ...02a72b057d1c7f2e682d0776a5363e2cca974.data | 0 ...16cfa9a7ae5533f8e997cdab2ebadd7506340.data | 0 ...e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data | 0 ...c0f1e4947cff8e422610996e609dbcb976598.data | 0 ...62f687a00c638bcb580feae06452e0c1f20b4.data | 0 ...56baef91c7dc345e73d049ab570abe10dfbb9.data | Bin ...2fdadf9d45666c3be122a2efb5db93c1d5fa6.data | 0 ...be72a83e80f9c7bca1abcaa42298a57a33ff5.data | Bin ...fb92427ae41e4649b934ca495991b7852b855.data | 0 ...41317afc9f967abe2aa05e7c641f7bbe98a37.data | Bin ...807def07b0db2f018808620eb30b980e94011.data | 0 ...38b95dd29d31eac6433af0fb6fcd83dd80778.data | 0 tests/{test-repo => repo-example}/config | 0 .../datastore/000002.ldb | Bin .../datastore/000005.ldb | Bin .../datastore/CURRENT | 0 .../datastore/LOCK | 0 .../{test-repo => repo-example}/datastore/LOG | 0 .../datastore/LOG.old | 0 .../datastore/MANIFEST-000007 | Bin tests/{test-repo => repo-example}/version | 0 tests/test-api/test-version.js | 21 +++++ tests/test-cli-offline/test-version.js | 16 ++++ tests/test-cli/test-version.js | 16 ++++ tests/test-core/test-version.js | 17 +++++ 45 files changed, 175 insertions(+), 113 deletions(-) create mode 100644 src/http-api/resources/index.js create mode 100644 src/http-api/resources/version.js create mode 100644 src/http-api/routes/version.js delete mode 100644 tests/jsipfs-test.js rename tests/{test-repo => repo-example}/blocks/1220120f/1220120f6af601d46e10b2d2e11ed71c55d25f3042c22501e41d1246e7a1e9d3d8ec.data (100%) rename tests/{test-repo => repo-example}/blocks/122031d6/122031d6da265092f1b03fec969243fdcf095c1d219356cdf538ffce705a52d5738d.data (100%) rename tests/{test-repo => repo-example}/blocks/122031e7/122031e7a41c15d03feb8cd793c3348ea3b310512d7767a9abfbd7a928a85e977173.data (100%) rename tests/{test-repo => repo-example}/blocks/12203628/12203628a4a19525dd84bbbffe132ec0b0d3be3528fbbcc814feb7f2fbf71ca06162.data (100%) rename tests/{test-repo => repo-example}/blocks/12204a5a/12204a5a95586f52e25811cf214677160e64383755a8c5163ba3c053c3b65777ed16.data (100%) rename tests/{test-repo => repo-example}/blocks/12205200/12205200cc6b6f79e1588480d9f9016ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data (100%) rename tests/{test-repo => repo-example}/blocks/122052c6/122052c63c7775396b3f82c639977a7223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data (100%) rename tests/{test-repo => repo-example}/blocks/12205994/122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef.data (100%) rename tests/{test-repo => repo-example}/blocks/122062ce/122062ce1f2c91a13a97b596e873b5a3346a644605d7614dca53cd3a59f7385a8abb.data (100%) rename tests/{test-repo => repo-example}/blocks/12206781/122067817186b8ff365c758f387e3ae7f28fa9367ee167c312e6d65a2e02e81ab815.data (100%) rename tests/{test-repo => repo-example}/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data (100%) rename tests/{test-repo => repo-example}/blocks/1220709b/1220709b2dcc5f6a90ad64d6fe3a5d202a72b057d1c7f2e682d0776a5363e2cca974.data (100%) rename tests/{test-repo => repo-example}/blocks/12207fb8/12207fb898b5d7be46d85feb75d894e16cfa9a7ae5533f8e997cdab2ebadd7506340.data (100%) rename tests/{test-repo => repo-example}/blocks/12208b87/12208b872ca4ee517608331696dd6b3e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data (100%) rename tests/{test-repo => repo-example}/blocks/122090c0/122090c07a7795c1193510a696d1fdfc0f1e4947cff8e422610996e609dbcb976598.data (100%) rename tests/{test-repo => repo-example}/blocks/1220929a/1220929a303c39da8a0b67c09697462f687a00c638bcb580feae06452e0c1f20b4.data (100%) rename tests/{test-repo => repo-example}/blocks/1220933b/1220933b41d37fd4508cdff45930dff56baef91c7dc345e73d049ab570abe10dfbb9.data (100%) rename tests/{test-repo => repo-example}/blocks/1220a52c/1220a52c3602030cb912edfe4de97002fdadf9d45666c3be122a2efb5db93c1d5fa6.data (100%) rename tests/{test-repo => repo-example}/blocks/1220c0fc/1220c0fc6b49543d7bf04e83d2a5a7cbe72a83e80f9c7bca1abcaa42298a57a33ff5.data (100%) rename tests/{test-repo => repo-example}/blocks/1220e3b0/1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.data (100%) rename tests/{test-repo => repo-example}/blocks/1220e605/1220e605408ac3f78113ac9a7fd486441317afc9f967abe2aa05e7c641f7bbe98a37.data (100%) rename tests/{test-repo => repo-example}/blocks/1220e6a0/1220e6a045864ff8569e43e4866c0af807def07b0db2f018808620eb30b980e94011.data (100%) rename tests/{test-repo => repo-example}/blocks/1220ec5b/1220ec5b533a3218991f4377b8b8c2538b95dd29d31eac6433af0fb6fcd83dd80778.data (100%) rename tests/{test-repo => repo-example}/config (100%) rename tests/{test-repo => repo-example}/datastore/000002.ldb (100%) rename tests/{test-repo => repo-example}/datastore/000005.ldb (100%) rename tests/{test-repo => repo-example}/datastore/CURRENT (100%) rename tests/{test-repo => repo-example}/datastore/LOCK (100%) rename tests/{test-repo => repo-example}/datastore/LOG (100%) rename tests/{test-repo => repo-example}/datastore/LOG.old (100%) rename tests/{test-repo => repo-example}/datastore/MANIFEST-000007 (100%) rename tests/{test-repo => repo-example}/version (100%) create mode 100644 tests/test-api/test-version.js create mode 100644 tests/test-cli-offline/test-version.js create mode 100644 tests/test-cli/test-version.js create mode 100644 tests/test-core/test-version.js diff --git a/package.json b/package.json index 9b95b1537a..cf868b7edc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "lint": "standard", "coverage": "istanbul cover --print both -- _mocha tests/*-test.js", - "test": "mocha tests/*-test.js" + "test": "mocha tests/test-*/test-*.js" }, "pre-commit": [ "lint" @@ -29,20 +29,18 @@ "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { "chai": "^3.4.1", - "ipfsd-ctl": "^0.6.1", "istanbul": "^0.4.1", "mocha": "^2.3.4", "ncp": "^2.0.0", + "nexpect": "^0.5.0", "pre-commit": "^1.1.2", "rimraf": "^2.4.4", "standard": "^5.3.1" }, "dependencies": { - "hapi": "^11.1.4", - "ipfs-api": "^2.7.0", - "ipfs-repo": "^0.1.0", - "peer-id": "^0.4.0", - "peer-info": "^0.4.0", + "debug": "^2.2.0", + "hapi": "^12.0.0", + "ipfs-repo": "^0.2.2", "ronin": "^0.3.11" } } diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index deedf71f28..21e486080d 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -1,7 +1,12 @@ var Command = require('ronin').Command +var httpAPI = require('../../http-api') module.exports = Command.extend({ - desc: '', + desc: 'Start a long-running daemon process', - run: function (name) {} + run: function (name) { + httpAPI.start() + // start API, using core + // + } }) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 34cf53e9c5..33b021e497 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -1,5 +1,8 @@ var Command = require('ronin').Command var IPFS = require('../../ipfs-core') +var debug = require('debug') +var log = debug('cli:version') +log.error = debug('cli:version:error') module.exports = Command.extend({ desc: 'Shows IPFS version information', @@ -23,9 +26,8 @@ module.exports = Command.extend({ run: function (name) { var node = new IPFS() node.version(function (err, version) { - if (err) { - return console.error(err) - } + if (err) { return log.error(err) } + console.log(version) }) } diff --git a/src/http-api/index.js b/src/http-api/index.js index e69de29bb2..a6ca8f0666 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -0,0 +1,37 @@ +var Hapi = require('hapi') +var IPFS = require('../ipfs-core') +var debug = require('debug') +var log = debug('api') + +exports = module.exports + +exports.start = function (callback) { + // start IPFS and exports.ipfs = new IPFS() + + exports.ipfs = new IPFS() + + var server = exports.server = new Hapi.Server({ + connections: { + routes: { + cors: true + } + } + }) + + server.connection({ + port: 9000 + }) + + // load routes + require('./routes/version.js') + + server.start(function (err) { + if (err) { return callback(err) } + log('server started: ' + server.info.uri) + callback() + }) +} + +exports.stop = function () { + +} diff --git a/src/http-api/resources/index.js b/src/http-api/resources/index.js new file mode 100644 index 0000000000..85867b265c --- /dev/null +++ b/src/http-api/resources/index.js @@ -0,0 +1 @@ +exports.version = require('./version') diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js new file mode 100644 index 0000000000..a6c37d28ec --- /dev/null +++ b/src/http-api/resources/version.js @@ -0,0 +1,14 @@ +var ipfs = require('./../index.js').ipfs +var boom = require('boom') + +exports = module.exports + +exports.get = function handler (request, reply) { + ipfs.version(function (err, version) { + if (err) { + return reply(boom.badRequest(err)) + } + return reply(version) + }) +} + diff --git a/src/http-api/routes/version.js b/src/http-api/routes/version.js new file mode 100644 index 0000000000..5599a7dee4 --- /dev/null +++ b/src/http-api/routes/version.js @@ -0,0 +1,8 @@ +var server = require('./../index.js').server +var resources = require('./../resources') + +server.route({ + method: 'GET', + path: '/api/v0/version', + handler: resources.version.get +}) diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 4fa57991bf..7f295ec032 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -1,7 +1,3 @@ -// var ipfsAPIclt = require('ipfs-api') -// var extend = require('extend') -// var PeerId = require('peer-id') -// var PeerInfo = require('peer-info') var config = require('./config') var IPFSRepo = require('ipfs-repo') @@ -15,21 +11,6 @@ function IPFS () { throw new Error('Must be instantiated with new') } - var opts = { - url: 'public-writable-node' - } - - if (process.env.NODE_ENV === 'dev') { - opts.url = '/ip4/127.0.0.1/tcp/5001' - } - - if (process.env.NODE_ENV === 'test') { - opts.url = process.env.APIURL - } - - // var api = ipfsAPIclt(config.url) - // extend(self, api) - var repo = new IPFSRepo(config.repoPath) self.daemon = function (callback) { @@ -41,13 +22,15 @@ function IPFS () { callback = opts opts = {} } - repoExists(callback) - repo.config.read(function (err, config) { - if (err) { - return callback(err) - } - callback(null, config.Version.Current) + repo.exists(function (err, exists) { + if (err) { return callback(err) } + + repo.config.get(function (err, config) { + if (err) { return callback(err) } + + callback(null, config.Version.Current) + }) }) } @@ -56,19 +39,23 @@ function IPFS () { callback = opts opts = {} } - repoExists(callback) - - repo.config.read(function (err, config) { + repo.exists(function (err, exists) { if (err) { return callback(err) } - callback(null, { - ID: config.Identity.PeerID, - // TODO needs https://github.com/diasdavid/js-peer-id/blob/master/src/index.js#L76 - PublicKey: '', - Addresses: config.Addresses, - AgentVersion: 'js-ipfs', - ProtocolVersion: '9000' + + repo.config.read(function (err, config) { + if (err) { + return callback(err) + } + callback(null, { + ID: config.Identity.PeerID, + // TODO needs https://github.com/diasdavid/js-peer-id/blob/master/src/index.js#L76 + PublicKey: '', + Addresses: config.Addresses, + AgentVersion: 'js-ipfs', + ProtocolVersion: '9000' + }) }) }) } @@ -83,17 +70,14 @@ function IPFS () { callback = opts opts = {} } - repoExists(callback) - - repo.version.read(callback) + repo.exists(function (err, res) { + if (err) { + return callback(err) + } + repo.version.read(callback) + }) }, gc: function () {} } - - function repoExists (callback) { - if (!repo.exists()) { - callback(new Error('Repo does not exist, you must init repo first')) - } else { repo.load() } - } } diff --git a/tests/jsipfs-test.js b/tests/jsipfs-test.js deleted file mode 100644 index 49ac1f0bd1..0000000000 --- a/tests/jsipfs-test.js +++ /dev/null @@ -1,57 +0,0 @@ -/* globals describe, before, after, it*/ - -var expect = require('chai').expect -var ncp = require('ncp').ncp -var rimraf = require('rimraf') - -// var IPFS = require('../src/ipfs-core') - -describe('IPFS Repo Tests', function () { - var testRepoPath = __dirname + '/test-repo' - var date = Date.now().toString() - var repoPath = testRepoPath + date - var node - - before(function (done) { - ncp(testRepoPath, repoPath, function (err) { - if (err) { - expect(err).to.equal(null) - } - done() - }) - }) - - after(function (done) { - rimraf(repoPath, function (err) { - if (err) { - expect(err).to.equal(null) - } - done() - }) - }) - - it('start a new node', function (done) { - process.env.IPFS_PATH = repoPath - var IPFS = require('../src/ipfs-core') - - node = new IPFS() - done() - }) - - it('check repo version', function (done) { - node.repo.version(function (err, version) { - expect(err).to.equal(null) - expect(version).to.be.a('string') - expect(Number(version)).to.be.a('number') - done() - }) - }) - - it('check id info', function (done) { - node.id(function (err, id) { - expect(err).to.equal(null) - expect(id).to.be.a('object') - done() - }) - }) -}) diff --git a/tests/test-repo/blocks/1220120f/1220120f6af601d46e10b2d2e11ed71c55d25f3042c22501e41d1246e7a1e9d3d8ec.data b/tests/repo-example/blocks/1220120f/1220120f6af601d46e10b2d2e11ed71c55d25f3042c22501e41d1246e7a1e9d3d8ec.data similarity index 100% rename from tests/test-repo/blocks/1220120f/1220120f6af601d46e10b2d2e11ed71c55d25f3042c22501e41d1246e7a1e9d3d8ec.data rename to tests/repo-example/blocks/1220120f/1220120f6af601d46e10b2d2e11ed71c55d25f3042c22501e41d1246e7a1e9d3d8ec.data diff --git a/tests/test-repo/blocks/122031d6/122031d6da265092f1b03fec969243fdcf095c1d219356cdf538ffce705a52d5738d.data b/tests/repo-example/blocks/122031d6/122031d6da265092f1b03fec969243fdcf095c1d219356cdf538ffce705a52d5738d.data similarity index 100% rename from tests/test-repo/blocks/122031d6/122031d6da265092f1b03fec969243fdcf095c1d219356cdf538ffce705a52d5738d.data rename to tests/repo-example/blocks/122031d6/122031d6da265092f1b03fec969243fdcf095c1d219356cdf538ffce705a52d5738d.data diff --git a/tests/test-repo/blocks/122031e7/122031e7a41c15d03feb8cd793c3348ea3b310512d7767a9abfbd7a928a85e977173.data b/tests/repo-example/blocks/122031e7/122031e7a41c15d03feb8cd793c3348ea3b310512d7767a9abfbd7a928a85e977173.data similarity index 100% rename from tests/test-repo/blocks/122031e7/122031e7a41c15d03feb8cd793c3348ea3b310512d7767a9abfbd7a928a85e977173.data rename to tests/repo-example/blocks/122031e7/122031e7a41c15d03feb8cd793c3348ea3b310512d7767a9abfbd7a928a85e977173.data diff --git a/tests/test-repo/blocks/12203628/12203628a4a19525dd84bbbffe132ec0b0d3be3528fbbcc814feb7f2fbf71ca06162.data b/tests/repo-example/blocks/12203628/12203628a4a19525dd84bbbffe132ec0b0d3be3528fbbcc814feb7f2fbf71ca06162.data similarity index 100% rename from tests/test-repo/blocks/12203628/12203628a4a19525dd84bbbffe132ec0b0d3be3528fbbcc814feb7f2fbf71ca06162.data rename to tests/repo-example/blocks/12203628/12203628a4a19525dd84bbbffe132ec0b0d3be3528fbbcc814feb7f2fbf71ca06162.data diff --git a/tests/test-repo/blocks/12204a5a/12204a5a95586f52e25811cf214677160e64383755a8c5163ba3c053c3b65777ed16.data b/tests/repo-example/blocks/12204a5a/12204a5a95586f52e25811cf214677160e64383755a8c5163ba3c053c3b65777ed16.data similarity index 100% rename from tests/test-repo/blocks/12204a5a/12204a5a95586f52e25811cf214677160e64383755a8c5163ba3c053c3b65777ed16.data rename to tests/repo-example/blocks/12204a5a/12204a5a95586f52e25811cf214677160e64383755a8c5163ba3c053c3b65777ed16.data diff --git a/tests/test-repo/blocks/12205200/12205200cc6b6f79e1588480d9f9016ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data b/tests/repo-example/blocks/12205200/12205200cc6b6f79e1588480d9f9016ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data similarity index 100% rename from tests/test-repo/blocks/12205200/12205200cc6b6f79e1588480d9f9016ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data rename to tests/repo-example/blocks/12205200/12205200cc6b6f79e1588480d9f9016ccadfda3d8bc7d2f8cdf302aa51dae8dae9da.data diff --git a/tests/test-repo/blocks/122052c6/122052c63c7775396b3f82c639977a7223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data b/tests/repo-example/blocks/122052c6/122052c63c7775396b3f82c639977a7223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data similarity index 100% rename from tests/test-repo/blocks/122052c6/122052c63c7775396b3f82c639977a7223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data rename to tests/repo-example/blocks/122052c6/122052c63c7775396b3f82c639977a7223c2d96a9f70b5fd8b1d513f8c5b69dcaed4.data diff --git a/tests/test-repo/blocks/12205994/122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef.data b/tests/repo-example/blocks/12205994/122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef.data similarity index 100% rename from tests/test-repo/blocks/12205994/122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef.data rename to tests/repo-example/blocks/12205994/122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef.data diff --git a/tests/test-repo/blocks/122062ce/122062ce1f2c91a13a97b596e873b5a3346a644605d7614dca53cd3a59f7385a8abb.data b/tests/repo-example/blocks/122062ce/122062ce1f2c91a13a97b596e873b5a3346a644605d7614dca53cd3a59f7385a8abb.data similarity index 100% rename from tests/test-repo/blocks/122062ce/122062ce1f2c91a13a97b596e873b5a3346a644605d7614dca53cd3a59f7385a8abb.data rename to tests/repo-example/blocks/122062ce/122062ce1f2c91a13a97b596e873b5a3346a644605d7614dca53cd3a59f7385a8abb.data diff --git a/tests/test-repo/blocks/12206781/122067817186b8ff365c758f387e3ae7f28fa9367ee167c312e6d65a2e02e81ab815.data b/tests/repo-example/blocks/12206781/122067817186b8ff365c758f387e3ae7f28fa9367ee167c312e6d65a2e02e81ab815.data similarity index 100% rename from tests/test-repo/blocks/12206781/122067817186b8ff365c758f387e3ae7f28fa9367ee167c312e6d65a2e02e81ab815.data rename to tests/repo-example/blocks/12206781/122067817186b8ff365c758f387e3ae7f28fa9367ee167c312e6d65a2e02e81ab815.data diff --git a/tests/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data b/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data similarity index 100% rename from tests/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data rename to tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data diff --git a/tests/test-repo/blocks/1220709b/1220709b2dcc5f6a90ad64d6fe3a5d202a72b057d1c7f2e682d0776a5363e2cca974.data b/tests/repo-example/blocks/1220709b/1220709b2dcc5f6a90ad64d6fe3a5d202a72b057d1c7f2e682d0776a5363e2cca974.data similarity index 100% rename from tests/test-repo/blocks/1220709b/1220709b2dcc5f6a90ad64d6fe3a5d202a72b057d1c7f2e682d0776a5363e2cca974.data rename to tests/repo-example/blocks/1220709b/1220709b2dcc5f6a90ad64d6fe3a5d202a72b057d1c7f2e682d0776a5363e2cca974.data diff --git a/tests/test-repo/blocks/12207fb8/12207fb898b5d7be46d85feb75d894e16cfa9a7ae5533f8e997cdab2ebadd7506340.data b/tests/repo-example/blocks/12207fb8/12207fb898b5d7be46d85feb75d894e16cfa9a7ae5533f8e997cdab2ebadd7506340.data similarity index 100% rename from tests/test-repo/blocks/12207fb8/12207fb898b5d7be46d85feb75d894e16cfa9a7ae5533f8e997cdab2ebadd7506340.data rename to tests/repo-example/blocks/12207fb8/12207fb898b5d7be46d85feb75d894e16cfa9a7ae5533f8e997cdab2ebadd7506340.data diff --git a/tests/test-repo/blocks/12208b87/12208b872ca4ee517608331696dd6b3e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data b/tests/repo-example/blocks/12208b87/12208b872ca4ee517608331696dd6b3e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data similarity index 100% rename from tests/test-repo/blocks/12208b87/12208b872ca4ee517608331696dd6b3e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data rename to tests/repo-example/blocks/12208b87/12208b872ca4ee517608331696dd6b3e5cf3497a7845ee8f94456ccf4d1d2f6602b5.data diff --git a/tests/test-repo/blocks/122090c0/122090c07a7795c1193510a696d1fdfc0f1e4947cff8e422610996e609dbcb976598.data b/tests/repo-example/blocks/122090c0/122090c07a7795c1193510a696d1fdfc0f1e4947cff8e422610996e609dbcb976598.data similarity index 100% rename from tests/test-repo/blocks/122090c0/122090c07a7795c1193510a696d1fdfc0f1e4947cff8e422610996e609dbcb976598.data rename to tests/repo-example/blocks/122090c0/122090c07a7795c1193510a696d1fdfc0f1e4947cff8e422610996e609dbcb976598.data diff --git a/tests/test-repo/blocks/1220929a/1220929a303c39da8a0b67c09697462f687a00c638bcb580feae06452e0c1f20b4.data b/tests/repo-example/blocks/1220929a/1220929a303c39da8a0b67c09697462f687a00c638bcb580feae06452e0c1f20b4.data similarity index 100% rename from tests/test-repo/blocks/1220929a/1220929a303c39da8a0b67c09697462f687a00c638bcb580feae06452e0c1f20b4.data rename to tests/repo-example/blocks/1220929a/1220929a303c39da8a0b67c09697462f687a00c638bcb580feae06452e0c1f20b4.data diff --git a/tests/test-repo/blocks/1220933b/1220933b41d37fd4508cdff45930dff56baef91c7dc345e73d049ab570abe10dfbb9.data b/tests/repo-example/blocks/1220933b/1220933b41d37fd4508cdff45930dff56baef91c7dc345e73d049ab570abe10dfbb9.data similarity index 100% rename from tests/test-repo/blocks/1220933b/1220933b41d37fd4508cdff45930dff56baef91c7dc345e73d049ab570abe10dfbb9.data rename to tests/repo-example/blocks/1220933b/1220933b41d37fd4508cdff45930dff56baef91c7dc345e73d049ab570abe10dfbb9.data diff --git a/tests/test-repo/blocks/1220a52c/1220a52c3602030cb912edfe4de97002fdadf9d45666c3be122a2efb5db93c1d5fa6.data b/tests/repo-example/blocks/1220a52c/1220a52c3602030cb912edfe4de97002fdadf9d45666c3be122a2efb5db93c1d5fa6.data similarity index 100% rename from tests/test-repo/blocks/1220a52c/1220a52c3602030cb912edfe4de97002fdadf9d45666c3be122a2efb5db93c1d5fa6.data rename to tests/repo-example/blocks/1220a52c/1220a52c3602030cb912edfe4de97002fdadf9d45666c3be122a2efb5db93c1d5fa6.data diff --git a/tests/test-repo/blocks/1220c0fc/1220c0fc6b49543d7bf04e83d2a5a7cbe72a83e80f9c7bca1abcaa42298a57a33ff5.data b/tests/repo-example/blocks/1220c0fc/1220c0fc6b49543d7bf04e83d2a5a7cbe72a83e80f9c7bca1abcaa42298a57a33ff5.data similarity index 100% rename from tests/test-repo/blocks/1220c0fc/1220c0fc6b49543d7bf04e83d2a5a7cbe72a83e80f9c7bca1abcaa42298a57a33ff5.data rename to tests/repo-example/blocks/1220c0fc/1220c0fc6b49543d7bf04e83d2a5a7cbe72a83e80f9c7bca1abcaa42298a57a33ff5.data diff --git a/tests/test-repo/blocks/1220e3b0/1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.data b/tests/repo-example/blocks/1220e3b0/1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.data similarity index 100% rename from tests/test-repo/blocks/1220e3b0/1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.data rename to tests/repo-example/blocks/1220e3b0/1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.data diff --git a/tests/test-repo/blocks/1220e605/1220e605408ac3f78113ac9a7fd486441317afc9f967abe2aa05e7c641f7bbe98a37.data b/tests/repo-example/blocks/1220e605/1220e605408ac3f78113ac9a7fd486441317afc9f967abe2aa05e7c641f7bbe98a37.data similarity index 100% rename from tests/test-repo/blocks/1220e605/1220e605408ac3f78113ac9a7fd486441317afc9f967abe2aa05e7c641f7bbe98a37.data rename to tests/repo-example/blocks/1220e605/1220e605408ac3f78113ac9a7fd486441317afc9f967abe2aa05e7c641f7bbe98a37.data diff --git a/tests/test-repo/blocks/1220e6a0/1220e6a045864ff8569e43e4866c0af807def07b0db2f018808620eb30b980e94011.data b/tests/repo-example/blocks/1220e6a0/1220e6a045864ff8569e43e4866c0af807def07b0db2f018808620eb30b980e94011.data similarity index 100% rename from tests/test-repo/blocks/1220e6a0/1220e6a045864ff8569e43e4866c0af807def07b0db2f018808620eb30b980e94011.data rename to tests/repo-example/blocks/1220e6a0/1220e6a045864ff8569e43e4866c0af807def07b0db2f018808620eb30b980e94011.data diff --git a/tests/test-repo/blocks/1220ec5b/1220ec5b533a3218991f4377b8b8c2538b95dd29d31eac6433af0fb6fcd83dd80778.data b/tests/repo-example/blocks/1220ec5b/1220ec5b533a3218991f4377b8b8c2538b95dd29d31eac6433af0fb6fcd83dd80778.data similarity index 100% rename from tests/test-repo/blocks/1220ec5b/1220ec5b533a3218991f4377b8b8c2538b95dd29d31eac6433af0fb6fcd83dd80778.data rename to tests/repo-example/blocks/1220ec5b/1220ec5b533a3218991f4377b8b8c2538b95dd29d31eac6433af0fb6fcd83dd80778.data diff --git a/tests/test-repo/config b/tests/repo-example/config similarity index 100% rename from tests/test-repo/config rename to tests/repo-example/config diff --git a/tests/test-repo/datastore/000002.ldb b/tests/repo-example/datastore/000002.ldb similarity index 100% rename from tests/test-repo/datastore/000002.ldb rename to tests/repo-example/datastore/000002.ldb diff --git a/tests/test-repo/datastore/000005.ldb b/tests/repo-example/datastore/000005.ldb similarity index 100% rename from tests/test-repo/datastore/000005.ldb rename to tests/repo-example/datastore/000005.ldb diff --git a/tests/test-repo/datastore/CURRENT b/tests/repo-example/datastore/CURRENT similarity index 100% rename from tests/test-repo/datastore/CURRENT rename to tests/repo-example/datastore/CURRENT diff --git a/tests/test-repo/datastore/LOCK b/tests/repo-example/datastore/LOCK similarity index 100% rename from tests/test-repo/datastore/LOCK rename to tests/repo-example/datastore/LOCK diff --git a/tests/test-repo/datastore/LOG b/tests/repo-example/datastore/LOG similarity index 100% rename from tests/test-repo/datastore/LOG rename to tests/repo-example/datastore/LOG diff --git a/tests/test-repo/datastore/LOG.old b/tests/repo-example/datastore/LOG.old similarity index 100% rename from tests/test-repo/datastore/LOG.old rename to tests/repo-example/datastore/LOG.old diff --git a/tests/test-repo/datastore/MANIFEST-000007 b/tests/repo-example/datastore/MANIFEST-000007 similarity index 100% rename from tests/test-repo/datastore/MANIFEST-000007 rename to tests/repo-example/datastore/MANIFEST-000007 diff --git a/tests/test-repo/version b/tests/repo-example/version similarity index 100% rename from tests/test-repo/version rename to tests/repo-example/version diff --git a/tests/test-api/test-version.js b/tests/test-api/test-version.js new file mode 100644 index 0000000000..629032b16d --- /dev/null +++ b/tests/test-api/test-version.js @@ -0,0 +1,21 @@ +/* globals describe, it */ + +var expect = require('chai').expect + +process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' +var api = require('../../src/http-api') + +describe('api: version', function () { + it('get the version', function (done) { + api.start(err => { + expect(err).to.not.exist + api.server.inject({ + method: 'GET', + url: '/api/v0/version' + }, res => { + expect(res.result).to.equal('0.4.0-dev') + done() + }) + }) + }) +}) diff --git a/tests/test-cli-offline/test-version.js b/tests/test-cli-offline/test-version.js new file mode 100644 index 0000000000..8df6c46f20 --- /dev/null +++ b/tests/test-cli-offline/test-version.js @@ -0,0 +1,16 @@ +/* globals describe, it */ + +var expect = require('chai').expect +var nexpect = require('nexpect') + +describe('cli-offline: version', function () { + it('get the version', function (done) { + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version']) + .expect('0.4.0-dev') + .run(function (err, stdout, exitcode) { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) +}) diff --git a/tests/test-cli/test-version.js b/tests/test-cli/test-version.js new file mode 100644 index 0000000000..e229f0916a --- /dev/null +++ b/tests/test-cli/test-version.js @@ -0,0 +1,16 @@ +/* globals describe, it */ + +var expect = require('chai').expect +var nexpect = require('nexpect') + +describe('cli: version', function () { + it('get the version', function (done) { + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version']) + .expect('0.4.0-dev') + .run(function (err, stdout, exitcode) { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) +}) diff --git a/tests/test-core/test-version.js b/tests/test-core/test-version.js new file mode 100644 index 0000000000..3f038d35d5 --- /dev/null +++ b/tests/test-core/test-version.js @@ -0,0 +1,17 @@ +/* globals describe, it */ + +var expect = require('chai').expect + +process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' +var IPFS = require('../../src/ipfs-core') + +describe('core: version', function () { + it('get version', function (done) { + var ipfs = new IPFS() + ipfs.version(function (err, version) { + expect(err).to.not.exist + expect(version).to.equal('0.4.0-dev') + done() + }) + }) +}) From f7768b55fb39750056c0e7a91fb81daaff112910 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Jan 2016 18:32:55 +0100 Subject: [PATCH 2/6] es6ify --- src/cli/bin.js | 6 +++-- src/cli/commands/add.js | 6 +++-- src/cli/commands/commands.js | 6 +++-- src/cli/commands/daemon.js | 18 +++++++++----- src/cli/commands/dns.js | 6 +++-- src/cli/commands/get.js | 4 ++-- src/cli/commands/id.js | 17 ++++++------- src/cli/commands/init.js | 11 ++++----- src/cli/commands/ls.js | 6 +++-- src/cli/commands/mount.js | 6 +++-- src/cli/commands/ping.js | 6 +++-- src/cli/commands/refs.js | 6 +++-- src/cli/commands/resolve.js | 6 +++-- src/cli/commands/update.js | 6 +++-- src/cli/commands/version.js | 14 ++++++----- src/http-api/index.js | 17 +++++++------ src/http-api/resources/version.js | 14 +++++------ src/http-api/routes/version.js | 6 +++-- src/ipfs-core/config.js | 4 +++- src/ipfs-core/index.js | 40 ++++++++++++++----------------- tests/test-core/test-version.js | 14 ++++++----- 21 files changed, 125 insertions(+), 94 deletions(-) diff --git a/src/cli/bin.js b/src/cli/bin.js index 05885ce332..4e78c38bb9 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -1,8 +1,10 @@ #! /usr/bin/env node -var ronin = require('ronin') +'use strict' -var cli = ronin(__dirname) +const ronin = require('ronin') + +const cli = ronin(__dirname) cli.run() diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/add.js +++ b/src/cli/commands/add.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/commands.js b/src/cli/commands/commands.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/commands.js +++ b/src/cli/commands/commands.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 21e486080d..28e16501dd 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -1,12 +1,18 @@ -var Command = require('ronin').Command -var httpAPI = require('../../http-api') +'use strict' + +const Command = require('ronin').Command +const httpAPI = require('../../http-api') +const debug = require('debug') +let log = debug('cli:daemon') +log.error = debug('cli:damon:error') module.exports = Command.extend({ desc: 'Start a long-running daemon process', - run: function (name) { - httpAPI.start() - // start API, using core - // + run: name => { + httpAPI.start((err) => { + if (err) { return log.error(err) } + log('daemon started') + }) } }) diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/get.js b/src/cli/commands/get.js index deedf71f28..cb1b1d172f 100644 --- a/src/cli/commands/get.js +++ b/src/cli/commands/get.js @@ -1,7 +1,7 @@ -var Command = require('ronin').Command +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 52bc904f9d..497f119800 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -1,5 +1,8 @@ -var Command = require('ronin').Command -var IPFS = require('../../ipfs-core') +const Command = require('ronin').Command +const IPFS = require('../../ipfs-core') +const debug = require('debug') +let log = debug('cli:id') +log.error = debug('cli:id:error') module.exports = Command.extend({ desc: 'Shows IPFS Node ID info', @@ -11,12 +14,10 @@ module.exports = Command.extend({ } }, - run: function (name) { - var node = new IPFS() - node.id(function (err, id) { - if (err) { - return console.error(err) - } + run: name => { + let node = new IPFS() + node.id((err, id) => { + if (err) { return log.error(err) } console.log(id) }) } diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index c669732925..7c0e39e3e9 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,11 +1,10 @@ -var Command = require('ronin').Command -// var help = require('../src/help-menu.js') +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: 'Initialize ipfs local configuration', - // help: help, - options: { bits: { type: 'number', @@ -25,7 +24,5 @@ module.exports = Command.extend({ } }, - run: function (name) { - console.log('NA - https://github.com/ipfs/js-ipfs/tree/jsipfs#getting-jsipfs-ready') - } + run: name => {} }) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/mount.js b/src/cli/commands/mount.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/mount.js +++ b/src/cli/commands/mount.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/ping.js b/src/cli/commands/ping.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/ping.js +++ b/src/cli/commands/ping.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/refs.js b/src/cli/commands/refs.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/refs.js +++ b/src/cli/commands/refs.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/resolve.js b/src/cli/commands/resolve.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/resolve.js +++ b/src/cli/commands/resolve.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/update.js b/src/cli/commands/update.js index deedf71f28..160f94228c 100644 --- a/src/cli/commands/update.js +++ b/src/cli/commands/update.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command +'use strict' + +const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: function (name) {} + run: name => {} }) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 33b021e497..158bee705e 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -1,7 +1,9 @@ -var Command = require('ronin').Command -var IPFS = require('../../ipfs-core') -var debug = require('debug') -var log = debug('cli:version') +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../ipfs-core') +const debug = require('debug') +let log = debug('cli:version') log.error = debug('cli:version:error') module.exports = Command.extend({ @@ -23,9 +25,9 @@ module.exports = Command.extend({ } }, - run: function (name) { + run: (name) => { var node = new IPFS() - node.version(function (err, version) { + node.version((err, version) => { if (err) { return log.error(err) } console.log(version) diff --git a/src/http-api/index.js b/src/http-api/index.js index a6ca8f0666..01e534858e 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -1,11 +1,14 @@ -var Hapi = require('hapi') -var IPFS = require('../ipfs-core') -var debug = require('debug') -var log = debug('api') +'use strict' + +const Hapi = require('hapi') +const IPFS = require('../ipfs-core') +const debug = require('debug') +let log = debug('api') +log.error = debug('api:error') exports = module.exports -exports.start = function (callback) { +exports.start = callback => { // start IPFS and exports.ipfs = new IPFS() exports.ipfs = new IPFS() @@ -25,13 +28,13 @@ exports.start = function (callback) { // load routes require('./routes/version.js') - server.start(function (err) { + server.start(err => { if (err) { return callback(err) } log('server started: ' + server.info.uri) callback() }) } -exports.stop = function () { +exports.stop = () => { } diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js index a6c37d28ec..d598e8882e 100644 --- a/src/http-api/resources/version.js +++ b/src/http-api/resources/version.js @@ -1,13 +1,13 @@ -var ipfs = require('./../index.js').ipfs -var boom = require('boom') +'use strict' + +const ipfs = require('./../index.js').ipfs +const boom = require('boom') exports = module.exports -exports.get = function handler (request, reply) { - ipfs.version(function (err, version) { - if (err) { - return reply(boom.badRequest(err)) - } +exports.get = (request, reply) => { + ipfs.version((err, version) => { + if (err) { return reply(boom.badRequest(err)) } return reply(version) }) } diff --git a/src/http-api/routes/version.js b/src/http-api/routes/version.js index 5599a7dee4..95a878d285 100644 --- a/src/http-api/routes/version.js +++ b/src/http-api/routes/version.js @@ -1,5 +1,7 @@ -var server = require('./../index.js').server -var resources = require('./../resources') +'use strict' + +const server = require('./../index.js').server +const resources = require('./../resources') server.route({ method: 'GET', diff --git a/src/ipfs-core/config.js b/src/ipfs-core/config.js index 1bcfce9dd7..5a29168d0b 100644 --- a/src/ipfs-core/config.js +++ b/src/ipfs-core/config.js @@ -1,4 +1,6 @@ -var os = require('os') +'use strict' + +const os = require('os') exports = module.exports diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 7f295ec032..fd94efb021 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -1,32 +1,32 @@ -var config = require('./config') -var IPFSRepo = require('ipfs-repo') +'use strict' + +const config = require('./config') +const IPFSRepo = require('ipfs-repo') exports = module.exports = IPFS exports.config = config function IPFS () { - var self = this - - if (!(self instanceof IPFS)) { + if (!(this instanceof IPFS)) { throw new Error('Must be instantiated with new') } var repo = new IPFSRepo(config.repoPath) - self.daemon = function (callback) { + this.daemon = (callback) => { // 1. read repo to get peer data } - self.version = function (opts, callback) { + this.version = (opts, callback) => { if (typeof opts === 'function') { callback = opts opts = {} } - repo.exists(function (err, exists) { + repo.exists((err, exists) => { if (err) { return callback(err) } - repo.config.get(function (err, config) { + repo.config.get((err, config) => { if (err) { return callback(err) } callback(null, config.Version.Current) @@ -34,17 +34,15 @@ function IPFS () { }) } - self.id = function (opts, callback) { + this.id = (opts, callback) => { if (typeof opts === 'function') { callback = opts opts = {} } - repo.exists(function (err, exists) { - if (err) { - return callback(err) - } + repo.exists((err, exists) => { + if (err) { return callback(err) } - repo.config.read(function (err, config) { + repo.config.read((err, config) => { if (err) { return callback(err) } @@ -60,20 +58,18 @@ function IPFS () { }) } - self.repo = { - init: function (bits, force, empty, callback) { + this.repo = { + init: (bits, force, empty, callback) => { // 1. check if repo already exists }, - version: function (opts, callback) { + version: (opts, callback) => { if (typeof opts === 'function') { callback = opts opts = {} } - repo.exists(function (err, res) { - if (err) { - return callback(err) - } + repo.exists((err, res) => { + if (err) { return callback(err) } repo.version.read(callback) }) }, diff --git a/tests/test-core/test-version.js b/tests/test-core/test-version.js index 3f038d35d5..fe0f925674 100644 --- a/tests/test-core/test-version.js +++ b/tests/test-core/test-version.js @@ -1,14 +1,16 @@ /* globals describe, it */ -var expect = require('chai').expect +'use strict' + +const expect = require('chai').expect process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' -var IPFS = require('../../src/ipfs-core') +const IPFS = require('../../src/ipfs-core') -describe('core: version', function () { - it('get version', function (done) { - var ipfs = new IPFS() - ipfs.version(function (err, version) { +describe('core: version', () => { + it('get version', done => { + let ipfs = new IPFS() + ipfs.version((err, version) => { expect(err).to.not.exist expect(version).to.equal('0.4.0-dev') done() From 447f6a9f503420396a79a4e4a52df5329a0ffc6e Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Jan 2016 18:39:29 +0100 Subject: [PATCH 3/6] let -> const on id.js command file --- src/cli/commands/id.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 497f119800..063b626579 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -15,7 +15,7 @@ module.exports = Command.extend({ }, run: name => { - let node = new IPFS() + const node = new IPFS() node.id((err, id) => { if (err) { return log.error(err) } console.log(id) From 96ad02a1d6465f6b00b50d54ad80b4ac34060369 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Jan 2016 18:41:34 +0100 Subject: [PATCH 4/6] fix coverage script and update coverage value --- README.md | 2 +- package.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1615f7da97..fcb7f37bec 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ js-ipfs ======= -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/ipfs/js-ipfs.svg?style=flat-square)](https://travis-ci.org/ipfs/js-ipfs) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/ipfs/js-ipfs.svg?style=flat-square)](https://travis-ci.org/ipfs/js-ipfs) ![](https://img.shields.io/badge/coverage-75%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) > IPFS JavaScript implementation entry point and roadmap diff --git a/package.json b/package.json index cf868b7edc..6c788fe031 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,12 @@ "main": "src/index.js", "scripts": { "lint": "standard", - "coverage": "istanbul cover --print both -- _mocha tests/*-test.js", + "coverage": "istanbul cover --print both -- _mocha tests/test-*/test-*.js", "test": "mocha tests/test-*/test-*.js" }, "pre-commit": [ - "lint" + "lint", + "test" ], "repository": { "type": "git", From a4e210f3441d50662fea14ce8be6de860960c987 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 7 Jan 2016 18:47:19 +0100 Subject: [PATCH 5/6] more es6`ixing --- src/cli/commands/daemon.js | 2 +- src/cli/commands/id.js | 2 +- src/cli/commands/version.js | 2 +- src/http-api/index.js | 2 +- src/ipfs-core/index.js | 2 +- tests/test-api/test-version.js | 7 ++++--- tests/test-cli-offline/test-version.js | 12 +++++++----- tests/test-cli/test-version.js | 11 ++++++----- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 28e16501dd..f4ab32e09c 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -3,7 +3,7 @@ const Command = require('ronin').Command const httpAPI = require('../../http-api') const debug = require('debug') -let log = debug('cli:daemon') +const log = debug('cli:daemon') log.error = debug('cli:damon:error') module.exports = Command.extend({ diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 063b626579..ba477a5ffd 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -1,7 +1,7 @@ const Command = require('ronin').Command const IPFS = require('../../ipfs-core') const debug = require('debug') -let log = debug('cli:id') +const log = debug('cli:id') log.error = debug('cli:id:error') module.exports = Command.extend({ diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 158bee705e..337c2f55fa 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -3,7 +3,7 @@ const Command = require('ronin').Command const IPFS = require('../../ipfs-core') const debug = require('debug') -let log = debug('cli:version') +const log = debug('cli:version') log.error = debug('cli:version:error') module.exports = Command.extend({ diff --git a/src/http-api/index.js b/src/http-api/index.js index 01e534858e..fdf88ee32b 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -3,7 +3,7 @@ const Hapi = require('hapi') const IPFS = require('../ipfs-core') const debug = require('debug') -let log = debug('api') +const log = debug('api') log.error = debug('api:error') exports = module.exports diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index fd94efb021..bc409ef712 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -13,7 +13,7 @@ function IPFS () { var repo = new IPFSRepo(config.repoPath) - this.daemon = (callback) => { + this.daemon = callback => { // 1. read repo to get peer data } diff --git a/tests/test-api/test-version.js b/tests/test-api/test-version.js index 629032b16d..15202c193c 100644 --- a/tests/test-api/test-version.js +++ b/tests/test-api/test-version.js @@ -1,12 +1,13 @@ /* globals describe, it */ +'use strict' -var expect = require('chai').expect +const expect = require('chai').expect process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' -var api = require('../../src/http-api') +const api = require('../../src/http-api') describe('api: version', function () { - it('get the version', function (done) { + it('get the version', done => { api.start(err => { expect(err).to.not.exist api.server.inject({ diff --git a/tests/test-cli-offline/test-version.js b/tests/test-cli-offline/test-version.js index 8df6c46f20..3cc5636f7d 100644 --- a/tests/test-cli-offline/test-version.js +++ b/tests/test-cli-offline/test-version.js @@ -1,13 +1,15 @@ /* globals describe, it */ -var expect = require('chai').expect -var nexpect = require('nexpect') +'use strict' -describe('cli-offline: version', function () { - it('get the version', function (done) { +const expect = require('chai').expect +const nexpect = require('nexpect') + +describe('cli-offline: version', () => { + it('get the version', done => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version']) .expect('0.4.0-dev') - .run(function (err, stdout, exitcode) { + .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) done() diff --git a/tests/test-cli/test-version.js b/tests/test-cli/test-version.js index e229f0916a..baa493ee0a 100644 --- a/tests/test-cli/test-version.js +++ b/tests/test-cli/test-version.js @@ -1,13 +1,14 @@ /* globals describe, it */ +'use strict' -var expect = require('chai').expect -var nexpect = require('nexpect') +const expect = require('chai').expect +const nexpect = require('nexpect') -describe('cli: version', function () { - it('get the version', function (done) { +describe('cli: version', () => { + it('get the version', done => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version']) .expect('0.4.0-dev') - .run(function (err, stdout, exitcode) { + .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) done() From 258e892a0b39106b41ac6aded2ade558791438f4 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 8 Jan 2016 14:16:07 +0100 Subject: [PATCH 6/6] add missing dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6c788fe031..17123f2f27 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "standard": "^5.3.1" }, "dependencies": { + "boom": "^3.1.1", "debug": "^2.2.0", "hapi": "^12.0.0", "ipfs-repo": "^0.2.2",