From 4d6cedf29a68bb9906935732ae7cd47b0d0d59c6 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sat, 28 Jan 2017 15:34:51 +0000 Subject: [PATCH] test: refactor for test sanity --- .aegir.js | 1 - package.json | 4 +- test/browser.js | 3 - .../{both/test-bitswap.js => bitswap.spec.js} | 37 +++++---- .../test-bootstrap.js => bootstrap.spec.js} | 20 ++++- test/core/both/index.js | 13 --- test/core/both/test-init.js | 59 -------------- test/core/browser-only/index.js | 6 -- test/core/browser-only/test-swarm.js | 1 - test/core/browser.js | 51 ------------ test/core/init.spec.js | 81 +++++++++++++++++++ .../test-block.js => interface/block.js} | 0 .../test-config.js => interface/config.js} | 0 .../test-files.js => interface/files.js} | 0 .../test-generic.js => interface/generic.js} | 0 test/core/interface/interface.spec.js | 17 ++++ .../test-object.js => interface/object.js} | 0 .../test-pubsub.js => interface/pubsub.js} | 0 .../test-swarm.js => interface/swarm.js} | 0 test/core/node-only/index.js | 36 --------- test/core/node-only/test-init.js | 50 ------------ test/core/node.js | 26 ------ test/http-api/index.js | 15 ++-- .../test-block.js | 0 .../test-config.js | 0 .../test-files.js | 0 .../test-object.js | 0 .../test-pubsub.js | 0 .../test-swarm.js | 0 .../test-bitswap.js | 0 .../test-block.js | 0 .../test-bootstrap.js | 0 .../test-config.js | 0 .../test-id.js | 0 .../test-object.js | 0 .../test-repo.js | 0 .../test-swarm.js | 0 .../test-version.js | 0 .../http-api/{inject => spec}/test-bitswap.js | 0 test/http-api/{inject => spec}/test-block.js | 0 .../{inject => spec}/test-bootstrap.js | 0 test/http-api/{inject => spec}/test-config.js | 0 test/http-api/{inject => spec}/test-files.js | 0 test/http-api/{inject => spec}/test-id.js | 0 test/http-api/{inject => spec}/test-object.js | 0 test/http-api/{inject => spec}/test-pubsub.js | 0 test/http-api/{inject => spec}/test-repo.js | 0 test/http-api/{inject => spec}/test-swarm.js | 0 .../http-api/{inject => spec}/test-version.js | 0 test/node.js | 2 +- ...repo-browser.js => create-repo-browser.js} | 0 .../{temp-repo.js => create-repo-node.js} | 2 +- test/utils/factory-core/index.js | 2 +- test/utils/on-and-off.js | 19 +++-- test/utils/repo-path.js | 10 --- test/utils/temp-node.js | 2 +- 56 files changed, 159 insertions(+), 298 deletions(-) delete mode 100644 test/browser.js rename test/core/{both/test-bitswap.js => bitswap.spec.js} (90%) rename test/core/{both/test-bootstrap.js => bootstrap.spec.js} (86%) delete mode 100644 test/core/both/index.js delete mode 100644 test/core/both/test-init.js delete mode 100644 test/core/browser-only/index.js delete mode 100644 test/core/browser-only/test-swarm.js delete mode 100644 test/core/browser.js create mode 100644 test/core/init.spec.js rename test/core/{both/test-block.js => interface/block.js} (100%) rename test/core/{both/test-config.js => interface/config.js} (100%) rename test/core/{both/test-files.js => interface/files.js} (100%) rename test/core/{both/test-generic.js => interface/generic.js} (100%) create mode 100644 test/core/interface/interface.spec.js rename test/core/{both/test-object.js => interface/object.js} (100%) rename test/core/{node-only/test-pubsub.js => interface/pubsub.js} (100%) rename test/core/{node-only/test-swarm.js => interface/swarm.js} (100%) delete mode 100644 test/core/node-only/index.js delete mode 100644 test/core/node-only/test-init.js delete mode 100644 test/core/node.js rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-block.js (100%) rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-config.js (100%) rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-files.js (100%) rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-object.js (100%) rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-pubsub.js (100%) rename test/http-api/{interface-ipfs-core-over-ipfs-api => interface}/test-swarm.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-bitswap.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-block.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-bootstrap.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-config.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-id.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-object.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-repo.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-swarm.js (100%) rename test/http-api/{custom-ipfs-api => over-ipfs-api}/test-version.js (100%) rename test/http-api/{inject => spec}/test-bitswap.js (100%) rename test/http-api/{inject => spec}/test-block.js (100%) rename test/http-api/{inject => spec}/test-bootstrap.js (100%) rename test/http-api/{inject => spec}/test-config.js (100%) rename test/http-api/{inject => spec}/test-files.js (100%) rename test/http-api/{inject => spec}/test-id.js (100%) rename test/http-api/{inject => spec}/test-object.js (100%) rename test/http-api/{inject => spec}/test-pubsub.js (100%) rename test/http-api/{inject => spec}/test-repo.js (100%) rename test/http-api/{inject => spec}/test-swarm.js (100%) rename test/http-api/{inject => spec}/test-version.js (100%) rename test/utils/{temp-repo-browser.js => create-repo-browser.js} (100%) rename test/utils/{temp-repo.js => create-repo-node.js} (93%) delete mode 100644 test/utils/repo-path.js diff --git a/.aegir.js b/.aegir.js index 92764bc6c3..06490c5f1f 100644 --- a/.aegir.js +++ b/.aegir.js @@ -10,4 +10,3 @@ module.exports = { }] } } - diff --git a/package.json b/package.json index a5799262c2..b6fb87ea1e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "libp2p-ipfs-nodejs": "libp2p-ipfs-browser", "./src/core/default-repo.js": "./src/core/default-repo-browser.js", "./src/core/components/init-assets.js": false, - "./test/utils/temp-repo.js": "./test/utils/temp-repo-browser.js", + "./test/utils/create-repo-node.js": "./test/utils/create-repo-browser.js", "stream": "readable-stream" }, "go-ipfs": { @@ -170,4 +170,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/test/browser.js b/test/browser.js deleted file mode 100644 index 9e2051e8ec..0000000000 --- a/test/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' - -require('./core/browser') diff --git a/test/core/both/test-bitswap.js b/test/core/bitswap.spec.js similarity index 90% rename from test/core/both/test-bitswap.js rename to test/core/bitswap.spec.js index 576f93d8a3..83bb63f4e5 100644 --- a/test/core/both/test-bitswap.js +++ b/test/core/bitswap.spec.js @@ -16,7 +16,11 @@ const API = require('ipfs-api') const multiaddr = require('multiaddr') const isNode = require('detect-node') -const IPFS = require('../../../src/core') +// This gets replaced by require('../utils/create-repo-browser.js') +// in the browser +const createTempRepo = require('../utils/create-repo-node.js') + +const IPFS = require('../../src/core') function makeBlock (cb) { return cb(null, new Block(`IPFS is awesome ${Math.random()}`)) @@ -27,19 +31,24 @@ describe('bitswap', () => { let swarmAddrsBak beforeEach((done) => { - inProcNode = new IPFS(require('../../utils/repo-path')) - if (!isNode) { - inProcNode.config.get('Addresses.Swarm', (err, swarmAddrs) => { - expect(err).to.not.exist - swarmAddrsBak = swarmAddrs - inProcNode.config.set('Addresses.Swarm', [], (err) => { - expect(err).to.not.exist - inProcNode.load(done) - }) - }) - } else { - inProcNode.load(done) - } + const repo = createTempRepo() + inProcNode = new IPFS(repo) + series([ + (cb) => inProcNode.init({ bits: 2048 }, cb), + (cb) => { + if (!isNode) { + inProcNode.config.get('Addresses.Swarm', (err, swarmAddrs) => { + expect(err).to.not.exist + swarmAddrsBak = swarmAddrs + inProcNode.config.set('Addresses.Swarm', [], cb) + }) + } else { + cb() + } + }, + (cb) => inProcNode.config.set('Discovery.MDNS.Enabled', false, cb), + (cb) => inProcNode.load(cb) + ], done) }) afterEach((done) => { diff --git a/test/core/both/test-bootstrap.js b/test/core/bootstrap.spec.js similarity index 86% rename from test/core/both/test-bootstrap.js rename to test/core/bootstrap.spec.js index 9e6a90d47e..729f2ec31e 100644 --- a/test/core/both/test-bootstrap.js +++ b/test/core/bootstrap.spec.js @@ -2,15 +2,27 @@ 'use strict' const expect = require('chai').expect +const isNode = require('detect-node') +const series = require('async/series') -const IPFS = require('../../../src/core') +// This gets replaced by require('../utils/create-repo-browser.js') +// in the browser +const createTempRepo = require('../utils/create-repo-node.js') + +const IPFS = require('../../src/core') describe('bootstrap', () => { - var ipfs + if (!isNode) { return } + + let ipfs before((done) => { - ipfs = new IPFS(require('../../utils/repo-path')) - ipfs.load(done) + const repo = createTempRepo() + ipfs = new IPFS(repo) + series([ + (cb) => ipfs.init({ bits: 1024 }, cb), + (cb) => ipfs.load(cb) + ], done) }) const defaultList = [ diff --git a/test/core/both/index.js b/test/core/both/index.js deleted file mode 100644 index a6dc8e5621..0000000000 --- a/test/core/both/index.js +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -describe('--both', () => { - require('./test-bitswap') - require('./test-block') - require('./test-bootstrap') - require('./test-config') - require('./test-files') - require('./test-generic') - require('./test-init') - require('./test-object') -}) diff --git a/test/core/both/test-init.js b/test/core/both/test-init.js deleted file mode 100644 index 80849ebf7d..0000000000 --- a/test/core/both/test-init.js +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const expect = require('chai').expect -const IPFS = require('../../../src/core') -const createTempRepo = require('../../utils/temp-repo') - -describe('init', function () { - this.timeout(50 * 1000) - - it('basic', (done) => { - const repo = createTempRepo() - const ipfs = new IPFS(repo) - - ipfs.init({ emptyRepo: true, bits: 1024 }, (err) => { - expect(err).to.not.exist - - repo.exists((err, res) => { - expect(err).to.not.exist - expect(res).to.equal(true) - - repo.config.get((err, config) => { - expect(err).to.not.exist - expect(config.Identity).to.exist - - repo.teardown(done) - }) - }) - }) - }) - - it('set # of bits in key', (done) => { - const repo1 = createTempRepo() - const repo2 = createTempRepo() - const ipfsShort = new IPFS(repo1) - const ipfsLong = new IPFS(repo2) - ipfsShort.init({ bits: 1024, emptyRepo: true }, (err) => { - expect(err).to.not.exist - - ipfsLong.init({ bits: 2048, emptyRepo: true }, (err) => { - expect(err).to.not.exist - - repo1.config.get((err, config1) => { - expect(err).to.not.exist - - repo2.config.get((err, config2) => { - expect(err).to.not.exist - expect(config1.Identity.PrivKey.length).is.below(config2.Identity.PrivKey.length) - - repo1.teardown(() => { - repo2.teardown(done) - }) - }) - }) - }) - }) - }) -}) diff --git a/test/core/browser-only/index.js b/test/core/browser-only/index.js deleted file mode 100644 index 97ab80c35d..0000000000 --- a/test/core/browser-only/index.js +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -describe('--browser only', () => { - require('./test-swarm') -}) diff --git a/test/core/browser-only/test-swarm.js b/test/core/browser-only/test-swarm.js deleted file mode 100644 index ccacec309b..0000000000 --- a/test/core/browser-only/test-swarm.js +++ /dev/null @@ -1 +0,0 @@ -'use strict' diff --git a/test/core/browser.js b/test/core/browser.js deleted file mode 100644 index 54731912c9..0000000000 --- a/test/core/browser.js +++ /dev/null @@ -1,51 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const series = require('async/series') -const Store = require('idb-pull-blob-store') -const _ = require('lodash') -const pull = require('pull-stream') - -const repoContext = require.context('buffer!./../go-ipfs-repo', true) - -const idb = window.indexedDB || - window.mozIndexedDB || - window.webkitIndexedDB || - window.msIndexedDB - -idb.deleteDatabase('ipfs') -idb.deleteDatabase('ipfs/blocks') - -describe('core', function () { - this.timeout(10000) - before(function (done) { - var repoData = [] - repoContext.keys().forEach(function (key) { - repoData.push({ - key: key.replace('./', ''), - value: repoContext(key) - }) - }) - - const mainBlob = new Store('ipfs') - const blocksBlob = new Store('ipfs/blocks') - - series(repoData.map((file) => (cb) => { - if (_.startsWith(file.key, 'datastore/')) { - return cb() - } - - const blocks = _.startsWith(file.key, 'blocks/') - const blob = blocks ? blocksBlob : mainBlob - const key = blocks ? file.key.replace(/^blocks\//, '') : file.key - - pull( - pull.values([file.value]), - blob.write(key, cb) - ) - }), done) - }) - - require('./both') - require('./browser-only') -}) diff --git a/test/core/init.spec.js b/test/core/init.spec.js new file mode 100644 index 0000000000..89176bbabe --- /dev/null +++ b/test/core/init.spec.js @@ -0,0 +1,81 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const isNode = require('detect-node') +const IPFS = require('../../src/core') + +// This gets replaced by require('../utils/create-repo-browser.js') +// in the browser +const createTempRepo = require('../utils/create-repo-node.js') + +describe('init', () => { + if (!isNode) { return } + + let ipfs + let repo + + beforeEach(() => { + repo = createTempRepo() + ipfs = new IPFS(repo) + }) + + afterEach((done) => repo.teardown(done)) + + it('basic', (done) => { + ipfs.init({ bits: 1024 }, (err) => { + expect(err).to.not.exist + + repo.exists((err, res) => { + expect(err).to.not.exist + expect(res).to.equal(true) + + repo.config.get((err, config) => { + expect(err).to.not.exist + expect(config.Identity).to.exist + done() + }) + }) + }) + }) + + it('set # of bits in key', (done) => { + ipfs.init({ bits: 2048 }, (err) => { + expect(err).to.not.exist + + repo.config.get((err, config) => { + expect(err).to.not.exist + expect(config.Identity.PrivKey.length).is.above(256) + done() + }) + }) + }) + + it('init docs are written', (done) => { + ipfs.init({ bits: 1024 }, (err) => { + expect(err).to.not.exist + const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') + + ipfs.object.get(multihash, {}, (err, node) => { + expect(err).to.not.exist + expect(node.links).to.exist + done() + }) + }) + }) + + it('empty repo', (done) => { + ipfs.init({ bits: 1024, emptyRepo: true }, (err) => { + expect(err).to.not.exist + + // Should not have default assets + const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') + + ipfs.object.get(multihash, {}, (err, node) => { + expect(err).to.exist + done() + }) + }) + }) +}) diff --git a/test/core/both/test-block.js b/test/core/interface/block.js similarity index 100% rename from test/core/both/test-block.js rename to test/core/interface/block.js diff --git a/test/core/both/test-config.js b/test/core/interface/config.js similarity index 100% rename from test/core/both/test-config.js rename to test/core/interface/config.js diff --git a/test/core/both/test-files.js b/test/core/interface/files.js similarity index 100% rename from test/core/both/test-files.js rename to test/core/interface/files.js diff --git a/test/core/both/test-generic.js b/test/core/interface/generic.js similarity index 100% rename from test/core/both/test-generic.js rename to test/core/interface/generic.js diff --git a/test/core/interface/interface.spec.js b/test/core/interface/interface.spec.js new file mode 100644 index 0000000000..a3cfae8350 --- /dev/null +++ b/test/core/interface/interface.spec.js @@ -0,0 +1,17 @@ +/* eslint-env mocha */ + +'use strict' + +const isNode = require('detect-node') + +describe('interface-ipfs-core tests', () => { + require('./block') + require('./config') + require('./files') + require('./generic') + require('./object') + if (isNode) { + require('./swarm') + require('./pubsub') + } +}) diff --git a/test/core/both/test-object.js b/test/core/interface/object.js similarity index 100% rename from test/core/both/test-object.js rename to test/core/interface/object.js diff --git a/test/core/node-only/test-pubsub.js b/test/core/interface/pubsub.js similarity index 100% rename from test/core/node-only/test-pubsub.js rename to test/core/interface/pubsub.js diff --git a/test/core/node-only/test-swarm.js b/test/core/interface/swarm.js similarity index 100% rename from test/core/node-only/test-swarm.js rename to test/core/interface/swarm.js diff --git a/test/core/node-only/index.js b/test/core/node-only/index.js deleted file mode 100644 index a11396620b..0000000000 --- a/test/core/node-only/index.js +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const fs = require('fs') -const ncp = require('ncp').ncp -const expect = require('chai').expect -const path = require('path') -const clean = require('../../utils/clean') - -describe('--node only', () => { - const repoExample = path.join(__dirname, '../../go-ipfs-repo') - const repoTests = require('../../utils/repo-path') - - before((done) => { - clean(repoTests) - ncp(repoExample, repoTests, (err) => { - expect(err).to.equal(null) - done() - }) - }) - - after(() => { - clean(repoTests) - }) - - const tests = fs.readdirSync(__dirname) - tests.filter((file) => { - if (file === 'index.js') { - return false - } else { - return true - } - }).forEach((file) => { - require('./' + file) - }) -}) diff --git a/test/core/node-only/test-init.js b/test/core/node-only/test-init.js deleted file mode 100644 index 918abf27ff..0000000000 --- a/test/core/node-only/test-init.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const expect = require('chai').expect -const IPFS = require('../../../src/core') -const createTempRepo = require('../../utils/temp-repo') - -describe('init (Node.js specific)', () => { - let ipfs - let repo - - beforeEach((done) => { - repo = createTempRepo() - ipfs = new IPFS(repo) - done() - }) - - afterEach((done) => { - repo.teardown(done) - }) - - it('init docs are written', (done) => { - ipfs.init({ bits: 1024 }, (err) => { - expect(err).to.not.exist - const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') - - setTimeout(() => { - ipfs.object.get(multihash, {}, (err, node) => { - expect(err).to.not.exist - expect(node.links).to.exist - done() - }) - }, 1000) - }) - }) - - it('empty repo', (done) => { - ipfs.init({ bits: 1024, emptyRepo: true }, (err) => { - expect(err).to.not.exist - - // Check for default assets - var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') - ipfs.object.get(multihash, {}, (err, node) => { - expect(err).to.exist - done() - }) - }) - }) -}) diff --git a/test/core/node.js b/test/core/node.js deleted file mode 100644 index ac5dbcbe55..0000000000 --- a/test/core/node.js +++ /dev/null @@ -1,26 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const ncp = require('ncp').ncp -const expect = require('chai').expect -const path = require('path') -const clean = require('../utils/clean') - -describe('core', () => { - const repoExample = path.join(__dirname, '../go-ipfs-repo') - const repoTests = require('../utils/repo-path') - - before((done) => { - clean(repoTests) - ncp(repoExample, repoTests, (err) => { - expect(err).to.equal(null) - done() - }) - }) - - after(() => { - clean(repoTests) - }) - require('./both') - require('./node-only') -}) diff --git a/test/http-api/index.js b/test/http-api/index.js index 243af44982..b28a805438 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -36,33 +36,32 @@ describe('HTTP API', () => { }) }) - describe('## direct tests (inject)', () => { - const tests = fs.readdirSync(path.join(__dirname, '/inject')) + describe('## http-api spec tests', () => { + const tests = fs.readdirSync(path.join(__dirname, '/spec')) tests.filter((file) => { return file.match(/test-.*\.js/) }).forEach((file) => { - require('./inject/' + file)(http) + require('./spec/' + file)(http) }) }) describe('## interface-ipfs-core tests over ipfs-api', () => { - const tests = fs.readdirSync(path.join(__dirname, - '/interface-ipfs-core-over-ipfs-api')) + const tests = fs.readdirSync(path.join(__dirname, '/interface')) tests.filter((file) => { return file.match(/test-.*\.js/) }).forEach((file) => { - require('./interface-ipfs-core-over-ipfs-api/' + file) + require('./interface/' + file) }) }) describe('## custom ipfs-api tests', () => { - const tests = fs.readdirSync(path.join(__dirname, '/custom-ipfs-api')) + const tests = fs.readdirSync(path.join(__dirname, '/over-ipfs-api')) const ctl = APIctl('/ip4/127.0.0.1/tcp/6001') tests.filter((file) => { return file.match(/test-.*\.js/) }).forEach((file) => { - require('./custom-ipfs-api/' + file)(ctl) + require('./over-ipfs-api/' + file)(ctl) }) }) }) diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-block.js b/test/http-api/interface/test-block.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-block.js rename to test/http-api/interface/test-block.js diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js b/test/http-api/interface/test-config.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js rename to test/http-api/interface/test-config.js diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js b/test/http-api/interface/test-files.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-files.js rename to test/http-api/interface/test-files.js diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-object.js b/test/http-api/interface/test-object.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-object.js rename to test/http-api/interface/test-object.js diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-pubsub.js b/test/http-api/interface/test-pubsub.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-pubsub.js rename to test/http-api/interface/test-pubsub.js diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js b/test/http-api/interface/test-swarm.js similarity index 100% rename from test/http-api/interface-ipfs-core-over-ipfs-api/test-swarm.js rename to test/http-api/interface/test-swarm.js diff --git a/test/http-api/custom-ipfs-api/test-bitswap.js b/test/http-api/over-ipfs-api/test-bitswap.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-bitswap.js rename to test/http-api/over-ipfs-api/test-bitswap.js diff --git a/test/http-api/custom-ipfs-api/test-block.js b/test/http-api/over-ipfs-api/test-block.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-block.js rename to test/http-api/over-ipfs-api/test-block.js diff --git a/test/http-api/custom-ipfs-api/test-bootstrap.js b/test/http-api/over-ipfs-api/test-bootstrap.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-bootstrap.js rename to test/http-api/over-ipfs-api/test-bootstrap.js diff --git a/test/http-api/custom-ipfs-api/test-config.js b/test/http-api/over-ipfs-api/test-config.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-config.js rename to test/http-api/over-ipfs-api/test-config.js diff --git a/test/http-api/custom-ipfs-api/test-id.js b/test/http-api/over-ipfs-api/test-id.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-id.js rename to test/http-api/over-ipfs-api/test-id.js diff --git a/test/http-api/custom-ipfs-api/test-object.js b/test/http-api/over-ipfs-api/test-object.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-object.js rename to test/http-api/over-ipfs-api/test-object.js diff --git a/test/http-api/custom-ipfs-api/test-repo.js b/test/http-api/over-ipfs-api/test-repo.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-repo.js rename to test/http-api/over-ipfs-api/test-repo.js diff --git a/test/http-api/custom-ipfs-api/test-swarm.js b/test/http-api/over-ipfs-api/test-swarm.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-swarm.js rename to test/http-api/over-ipfs-api/test-swarm.js diff --git a/test/http-api/custom-ipfs-api/test-version.js b/test/http-api/over-ipfs-api/test-version.js similarity index 100% rename from test/http-api/custom-ipfs-api/test-version.js rename to test/http-api/over-ipfs-api/test-version.js diff --git a/test/http-api/inject/test-bitswap.js b/test/http-api/spec/test-bitswap.js similarity index 100% rename from test/http-api/inject/test-bitswap.js rename to test/http-api/spec/test-bitswap.js diff --git a/test/http-api/inject/test-block.js b/test/http-api/spec/test-block.js similarity index 100% rename from test/http-api/inject/test-block.js rename to test/http-api/spec/test-block.js diff --git a/test/http-api/inject/test-bootstrap.js b/test/http-api/spec/test-bootstrap.js similarity index 100% rename from test/http-api/inject/test-bootstrap.js rename to test/http-api/spec/test-bootstrap.js diff --git a/test/http-api/inject/test-config.js b/test/http-api/spec/test-config.js similarity index 100% rename from test/http-api/inject/test-config.js rename to test/http-api/spec/test-config.js diff --git a/test/http-api/inject/test-files.js b/test/http-api/spec/test-files.js similarity index 100% rename from test/http-api/inject/test-files.js rename to test/http-api/spec/test-files.js diff --git a/test/http-api/inject/test-id.js b/test/http-api/spec/test-id.js similarity index 100% rename from test/http-api/inject/test-id.js rename to test/http-api/spec/test-id.js diff --git a/test/http-api/inject/test-object.js b/test/http-api/spec/test-object.js similarity index 100% rename from test/http-api/inject/test-object.js rename to test/http-api/spec/test-object.js diff --git a/test/http-api/inject/test-pubsub.js b/test/http-api/spec/test-pubsub.js similarity index 100% rename from test/http-api/inject/test-pubsub.js rename to test/http-api/spec/test-pubsub.js diff --git a/test/http-api/inject/test-repo.js b/test/http-api/spec/test-repo.js similarity index 100% rename from test/http-api/inject/test-repo.js rename to test/http-api/spec/test-repo.js diff --git a/test/http-api/inject/test-swarm.js b/test/http-api/spec/test-swarm.js similarity index 100% rename from test/http-api/inject/test-swarm.js rename to test/http-api/spec/test-swarm.js diff --git a/test/http-api/inject/test-version.js b/test/http-api/spec/test-version.js similarity index 100% rename from test/http-api/inject/test-version.js rename to test/http-api/spec/test-version.js diff --git a/test/node.js b/test/node.js index 839824a7e7..7c50c663cb 100644 --- a/test/node.js +++ b/test/node.js @@ -23,7 +23,7 @@ if (process.env.TEST) { } if (testCore) { - require('./core/node') + // require('./core/node') } if (testHTTP) { diff --git a/test/utils/temp-repo-browser.js b/test/utils/create-repo-browser.js similarity index 100% rename from test/utils/temp-repo-browser.js rename to test/utils/create-repo-browser.js diff --git a/test/utils/temp-repo.js b/test/utils/create-repo-node.js similarity index 93% rename from test/utils/temp-repo.js rename to test/utils/create-repo-node.js index 0fb997bba2..b1a17512e1 100644 --- a/test/utils/temp-repo.js +++ b/test/utils/create-repo-node.js @@ -14,7 +14,7 @@ function createTempRepo (repoPath) { repo.teardown = (done) => { clean(repoPath) - done() + setImmediate(() => done()) } return repo diff --git a/test/utils/factory-core/index.js b/test/utils/factory-core/index.js index 69cafdf5e8..56598e9060 100644 --- a/test/utils/factory-core/index.js +++ b/test/utils/factory-core/index.js @@ -5,7 +5,7 @@ const series = require('async/series') const defaultConfig = require('./default-config.json') const IPFS = require('../../../src/core') -const createTempRepo = require('../temp-repo') +const createTempRepo = require('../create-repo-node') module.exports = Factory diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index 531b109e44..da0bd2d7b5 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -1,24 +1,23 @@ /* eslint-env mocha */ 'use strict' -const HttpAPI = require('../../src/http-api') +const HTTPAPI = require('../../src/http-api') -module.exports = function onlineAndOffline (repoPath, tests) { - describe('api offline', () => { - tests() - }) +/* + * CLI Utility to run the tests offline (daemon off) and online (daemon on) + */ +module.exports = (repoPath, tests) => { + describe('with daemon off (requiring js-ipfs core directly)', () => tests()) - describe('api running', () => { + describe('with daemon on (contacting js-ipfs through http-api)', () => { let httpAPI before((done) => { - httpAPI = new HttpAPI(repoPath) + httpAPI = new HTTPAPI(repoPath) httpAPI.start(done) }) - after((done) => { - httpAPI.stop(done) - }) + after((done) => httpAPI.stop(done)) tests() }) diff --git a/test/utils/repo-path.js b/test/utils/repo-path.js deleted file mode 100644 index a44e93d5d1..0000000000 --- a/test/utils/repo-path.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -const path = require('path') -const isNode = require('detect-node') - -if (isNode) { - module.exports = path.join(__dirname, '../repo-tests-run') -} else { - module.exports = 'ipfs' -} diff --git a/test/utils/temp-node.js b/test/utils/temp-node.js index a61fa2a201..85fdbb5ac9 100644 --- a/test/utils/temp-node.js +++ b/test/utils/temp-node.js @@ -5,7 +5,7 @@ const leftPad = require('left-pad') const series = require('async/series') const IPFS = require('../../src/core') -const createTempRepo = require('./temp-repo') +const createTempRepo = require('./create-repo-node.js') function setAddresses (repo, num, callback) { repo.config.get((err, config) => {