From 85091999b4f5856f98c6f646d4e79c71149359dd Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Sun, 25 Sep 2016 20:45:39 +0200 Subject: [PATCH] refactor: replace run-* with async, ipfs->ipfs-exec --- gulpfile.js | 4 ++-- package.json | 1 + src/cli/commands/config/edit.js | 2 +- src/cli/commands/files/cat.js | 2 +- src/cli/commands/files/get.js | 1 + src/core/components/go-online.js | 2 +- src/core/components/object.js | 9 ++------- src/http-api/index.js | 2 +- test/cli/test-bitswap.js | 2 +- test/cli/test-block.js | 2 +- test/cli/test-bootstrap.js | 2 +- test/cli/test-commands.js | 2 +- test/cli/test-config.js | 2 +- test/cli/test-files.js | 2 +- test/cli/test-id.js | 2 +- test/cli/test-init.js | 2 +- test/cli/test-object.js | 2 +- test/cli/test-swarm.js | 2 +- test/cli/test-version.js | 2 +- test/core/both/test-bitswap.js | 6 +++--- test/core/browser.js | 2 +- test/utils/factory-core/index.js | 2 +- test/utils/factory-http/index.js | 2 +- test/utils/{ipfs.js => ipfs-exec.js} | 11 +++++++++++ test/utils/temp-node.js | 2 +- 25 files changed, 39 insertions(+), 31 deletions(-) rename test/utils/{ipfs.js => ipfs-exec.js} (58%) diff --git a/gulpfile.js b/gulpfile.js index 2fdf17efa6..3d53274daf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,8 @@ 'use strict' const gulp = require('gulp') -const parallel = require('run-parallel') -const series = require('run-series') +const parallel = require('async/parallel') +const series = require('async/series') const createTempNode = require('./test/utils/temp-node') const API = require('./src/http-api') diff --git a/package.json b/package.json index 6b9bf0a5a3..ae6ec3ef80 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "transform-loader": "^0.2.3" }, "dependencies": { + "async": "^2.0.1", "babel-runtime": "^6.11.6", "bl": "^1.1.2", "boom": "^4.0.0", diff --git a/src/cli/commands/config/edit.js b/src/cli/commands/config/edit.js index 18d6fda014..91900578ce 100644 --- a/src/cli/commands/config/edit.js +++ b/src/cli/commands/config/edit.js @@ -3,7 +3,7 @@ const spawn = require('child_process').spawn const fs = require('fs') const temp = require('temp') -const waterfall = require('run-waterfall') +const waterfall = require('async/waterfall') const debug = require('debug') const log = debug('cli:config') log.error = debug('cli:config:error') diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index 88dd96b2ea..2b804d4e34 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -1,6 +1,6 @@ 'use strict' -const waterfall = require('run-waterfall') +const waterfall = require('async/waterfall') const debug = require('debug') const utils = require('../../utils') const log = debug('cli:files') diff --git a/src/cli/commands/files/get.js b/src/cli/commands/files/get.js index dbf0a76732..bc011ff68b 100644 --- a/src/cli/commands/files/get.js +++ b/src/cli/commands/files/get.js @@ -65,6 +65,7 @@ function fileHandler (dir) { file.content.pipe(fs.createWriteStream(target)) .once('error', cb) .once('end', cb) + return } cb() }) diff --git a/src/core/components/go-online.js b/src/core/components/go-online.js index 985f307e27..403226a8e8 100644 --- a/src/core/components/go-online.js +++ b/src/core/components/go-online.js @@ -1,6 +1,6 @@ 'use strict' -const series = require('run-series') +const series = require('async/series') const Bitswap = require('ipfs-bitswap') module.exports = function goOnline (self) { diff --git a/src/core/components/object.js b/src/core/components/object.js index 8e987b4d07..87239bb6c9 100644 --- a/src/core/components/object.js +++ b/src/core/components/object.js @@ -1,7 +1,7 @@ 'use strict' const mDAG = require('ipfs-merkle-dag') -const waterfall = require('run-waterfall') +const waterfall = require('async/waterfall') const promisify = require('promisify-es6') const bs58 = require('bs58') const DAGNode = mDAG.DAGNode @@ -69,12 +69,7 @@ module.exports = function object (self) { cb(err, node) }) } - ], (err, node) => { - if (err) { - return cb(err) - } - cb(null, node) - }) + ], cb) } } diff --git a/src/http-api/index.js b/src/http-api/index.js index 848d3a00ce..0e46e0f33b 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -1,6 +1,6 @@ 'use strict' -const parallel = require('run-parallel') +const parallel = require('async/parallel') const Hapi = require('hapi') const debug = require('debug') const fs = require('fs') diff --git a/test/cli/test-bitswap.js b/test/cli/test-bitswap.js index 425640b22c..d1230c53d7 100644 --- a/test/cli/test-bitswap.js +++ b/test/cli/test-bitswap.js @@ -8,7 +8,7 @@ const bs58 = require('bs58') const HttpAPI = require('../../src/http-api') const createTempNode = require('../utils/temp-node') const repoPath = require('./index').repoPath -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('bitswap', () => { let node diff --git a/test/cli/test-block.js b/test/cli/test-block.js index c5a03eb4a1..6beb8b3076 100644 --- a/test/cli/test-block.js +++ b/test/cli/test-block.js @@ -4,7 +4,7 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath const describeOnlineAndOffline = require('../utils/on-and-off') -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('block', () => { describeOnlineAndOffline(repoPath, () => { diff --git a/test/cli/test-bootstrap.js b/test/cli/test-bootstrap.js index 766c3f6887..8c69c8486e 100644 --- a/test/cli/test-bootstrap.js +++ b/test/cli/test-bootstrap.js @@ -4,7 +4,7 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) const describeOnlineAndOffline = require('../utils/on-and-off') describe('bootstrap', () => { diff --git a/test/cli/test-commands.js b/test/cli/test-commands.js index 539c055363..da484580d1 100644 --- a/test/cli/test-commands.js +++ b/test/cli/test-commands.js @@ -3,7 +3,7 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath -const ipfsBase = require('../utils/ipfs') +const ipfsBase = require('../utils/ipfs-exec') const ipfs = ipfsBase(repoPath) const describeOnlineAndOffline = require('../utils/on-and-off') diff --git a/test/cli/test-config.js b/test/cli/test-config.js index 1027995335..fecdeb3a2e 100644 --- a/test/cli/test-config.js +++ b/test/cli/test-config.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const fs = require('fs') const path = require('path') const repoPath = require('./index').repoPath -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) const describeOnlineAndOffline = require('../utils/on-and-off') describe('config', () => { diff --git a/test/cli/test-files.js b/test/cli/test-files.js index b9edc56354..0e7aca6f7e 100644 --- a/test/cli/test-files.js +++ b/test/cli/test-files.js @@ -6,7 +6,7 @@ const repoPath = require('./index').repoPath const fs = require('fs') const path = require('path') const describeOnlineAndOffline = require('../utils/on-and-off') -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('files', () => { describeOnlineAndOffline(repoPath, () => { diff --git a/test/cli/test-id.js b/test/cli/test-id.js index cfef37e5e4..6a76170e41 100644 --- a/test/cli/test-id.js +++ b/test/cli/test-id.js @@ -4,7 +4,7 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath const describeOnlineAndOffline = require('../utils/on-and-off') -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('id', () => { describeOnlineAndOffline(repoPath, () => { diff --git a/test/cli/test-init.js b/test/cli/test-init.js index 99268e7a27..27e20bc191 100644 --- a/test/cli/test-init.js +++ b/test/cli/test-init.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const path = require('path') const fs = require('fs') const clean = require('../utils/clean') -const ipfsCmd = require('../utils/ipfs') +const ipfsCmd = require('../utils/ipfs-exec') describe('init', function () { this.timeout(60 * 1000) diff --git a/test/cli/test-object.js b/test/cli/test-object.js index 6506abb8ee..383b32457b 100644 --- a/test/cli/test-object.js +++ b/test/cli/test-object.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath const describeOnlineAndOffline = require('../utils/on-and-off') -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('object', () => { describeOnlineAndOffline(repoPath, () => { diff --git a/test/cli/test-swarm.js b/test/cli/test-swarm.js index 3426f1e982..d846337024 100644 --- a/test/cli/test-swarm.js +++ b/test/cli/test-swarm.js @@ -6,7 +6,7 @@ const expect = require('chai').expect const HttpAPI = require('../../src/http-api') const createTempNode = require('../utils/temp-node') const repoPath = require('./index').repoPath -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('swarm', function () { this.timeout(30 * 1000) diff --git a/test/cli/test-version.js b/test/cli/test-version.js index 95d104fb0d..c4e9113a29 100644 --- a/test/cli/test-version.js +++ b/test/cli/test-version.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const pkgversion = require('../../package.json').version const repoPath = require('./index').repoPath const describeOnlineAndOffline = require('../utils/on-and-off') -const ipfs = require('../utils/ipfs')(repoPath) +const ipfs = require('../utils/ipfs-exec')(repoPath) describe('version', () => { describeOnlineAndOffline(repoPath, () => { diff --git a/test/core/both/test-bitswap.js b/test/core/both/test-bitswap.js index 208b2cfca1..5ccb186d00 100644 --- a/test/core/both/test-bitswap.js +++ b/test/core/both/test-bitswap.js @@ -4,9 +4,9 @@ const expect = require('chai').expect const _ = require('lodash') -const series = require('run-series') -const waterfall = require('run-waterfall') -const parallel = require('run-parallel') +const series = require('async/series') +const waterfall = require('async/waterfall') +const parallel = require('async/parallel') const leftPad = require('left-pad') const Block = require('ipfs-block') const bs58 = require('bs58') diff --git a/test/core/browser.js b/test/core/browser.js index 02eced8342..54731912c9 100644 --- a/test/core/browser.js +++ b/test/core/browser.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const series = require('run-series') +const series = require('async/series') const Store = require('idb-pull-blob-store') const _ = require('lodash') const pull = require('pull-stream') diff --git a/test/utils/factory-core/index.js b/test/utils/factory-core/index.js index f334536795..c23b628473 100644 --- a/test/utils/factory-core/index.js +++ b/test/utils/factory-core/index.js @@ -5,7 +5,7 @@ const isNode = require('detect-node') const IPFSRepo = require('ipfs-repo') const cleanRepo = require('../clean') const IPFS = require('../../../src/core') -const series = require('run-series') +const series = require('async/series') const defaultConfig = require('./default-config.json') module.exports = Factory diff --git a/test/utils/factory-http/index.js b/test/utils/factory-http/index.js index 6582184d25..290330aa29 100644 --- a/test/utils/factory-http/index.js +++ b/test/utils/factory-http/index.js @@ -6,7 +6,7 @@ const IPFSAPI = require('ipfs-api') const IPFS = require('../../../src/core') const cleanRepo = require('../clean') const HTTPAPI = require('../../../src/http-api') -const series = require('run-series') +const series = require('async/series') const defaultConfig = require('./default-config.json') module.exports = Factory diff --git a/test/utils/ipfs.js b/test/utils/ipfs-exec.js similarity index 58% rename from test/utils/ipfs.js rename to test/utils/ipfs-exec.js index 2c8c94d718..5867e4c5d6 100644 --- a/test/utils/ipfs.js +++ b/test/utils/ipfs-exec.js @@ -4,6 +4,17 @@ const execa = require('execa') const expect = require('chai').expect const _ = require('lodash') +// This is our new test utility to easily check and execute +// ipfs cli commands. +// +// The top level export is a function that can be passed a `repoPath` +// and optional `opts` to customize the execution of the commands. +// This function returns the actual executer, which consists of +// `ipfs('files get ')` and `ipfs.fail('files get ')` +// The first one executes and asserts that the command ran successfully +// and returns a promise which is resolved to `stdout` of the command. +// The `.fail` variation asserts that the command exited with `Code > 0` +// and returns a promise that resolves to `stderr`. module.exports = (repoPath, opts) => { const env = _.clone(process.env) env.IPFS_PATH = repoPath diff --git a/test/utils/temp-node.js b/test/utils/temp-node.js index 7375d9e60b..8fbc90f86c 100644 --- a/test/utils/temp-node.js +++ b/test/utils/temp-node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect const leftPad = require('left-pad') -const series = require('run-series') +const series = require('async/series') const IPFS = require('../../src/core') const createTempRepo = require('./temp-repo')