diff --git a/test/browser.js b/test/browser.js index fab499f9eb..9e2051e8ec 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,3 +1,3 @@ 'use strict' -require('./core-tests/browser') +require('./core/browser') diff --git a/test/cli-tests/index.js b/test/cli/index.js similarity index 100% rename from test/cli-tests/index.js rename to test/cli/index.js diff --git a/test/cli-tests/test-bitswap.js b/test/cli/test-bitswap.js similarity index 100% rename from test/cli-tests/test-bitswap.js rename to test/cli/test-bitswap.js diff --git a/test/cli-tests/test-block.js b/test/cli/test-block.js similarity index 100% rename from test/cli-tests/test-block.js rename to test/cli/test-block.js diff --git a/test/cli-tests/test-bootstrap.js b/test/cli/test-bootstrap.js similarity index 100% rename from test/cli-tests/test-bootstrap.js rename to test/cli/test-bootstrap.js diff --git a/test/cli-tests/test-commands.js b/test/cli/test-commands.js similarity index 100% rename from test/cli-tests/test-commands.js rename to test/cli/test-commands.js diff --git a/test/cli-tests/test-config.js b/test/cli/test-config.js similarity index 100% rename from test/cli-tests/test-config.js rename to test/cli/test-config.js diff --git a/test/cli-tests/test-files.js b/test/cli/test-files.js similarity index 100% rename from test/cli-tests/test-files.js rename to test/cli/test-files.js diff --git a/test/cli-tests/test-id.js b/test/cli/test-id.js similarity index 100% rename from test/cli-tests/test-id.js rename to test/cli/test-id.js diff --git a/test/cli-tests/test-init.js b/test/cli/test-init.js similarity index 100% rename from test/cli-tests/test-init.js rename to test/cli/test-init.js diff --git a/test/cli-tests/test-object.js b/test/cli/test-object.js similarity index 100% rename from test/cli-tests/test-object.js rename to test/cli/test-object.js diff --git a/test/cli-tests/test-swarm.js b/test/cli/test-swarm.js similarity index 100% rename from test/cli-tests/test-swarm.js rename to test/cli/test-swarm.js diff --git a/test/cli-tests/test-version.js b/test/cli/test-version.js similarity index 100% rename from test/cli-tests/test-version.js rename to test/cli/test-version.js diff --git a/test/core/both/index.js b/test/core/both/index.js new file mode 100644 index 0000000000..9c5c515fcf --- /dev/null +++ b/test/core/both/index.js @@ -0,0 +1,18 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') + +describe('--both', () => { + 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-tests/test-bitswap.js b/test/core/both/test-bitswap.js similarity index 98% rename from test/core-tests/test-bitswap.js rename to test/core/both/test-bitswap.js index a1be338a5a..a104a0c3b3 100644 --- a/test/core-tests/test-bitswap.js +++ b/test/core/both/test-bitswap.js @@ -12,7 +12,7 @@ const bl = require('bl') const API = require('ipfs-api') const multiaddr = require('multiaddr') -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') function makeBlock () { return new Block(`IPFS is awesome ${Math.random()}`) @@ -22,7 +22,7 @@ describe('bitswap', () => { let ipfs beforeEach((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core-tests/test-block.js b/test/core/both/test-block.js similarity index 83% rename from test/core-tests/test-block.js rename to test/core/both/test-block.js index cc59437f69..d9d9d04839 100644 --- a/test/core-tests/test-block.js +++ b/test/core/both/test-block.js @@ -4,22 +4,22 @@ const expect = require('chai').expect const base58 = require('bs58') const fs = require('fs') -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') const Block = require('ipfs-block') const path = require('path') const isNode = require('detect-node') const fileA = isNode - ? fs.readFileSync(path.join(__dirname, '../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) - : require('buffer!./../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') + ? fs.readFileSync(path.join(__dirname, '../../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) + : require('buffer!./../../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') // TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed describe('block', function () { var ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core-tests/test-bootstrap.js b/test/core/both/test-bootstrap.js similarity index 96% rename from test/core-tests/test-bootstrap.js rename to test/core/both/test-bootstrap.js index 255c548a66..e7f5c4ee93 100644 --- a/test/core-tests/test-bootstrap.js +++ b/test/core/both/test-bootstrap.js @@ -3,13 +3,13 @@ const expect = require('chai').expect -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') describe('bootstrap', () => { var ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core-tests/test-config.js b/test/core/both/test-config.js similarity index 93% rename from test/core-tests/test-config.js rename to test/core/both/test-config.js index a8afea02a3..649fbd2c6a 100644 --- a/test/core-tests/test-config.js +++ b/test/core/both/test-config.js @@ -2,7 +2,7 @@ 'use strict' const expect = require('chai').expect -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') describe('config', () => { var defaultConfig = { @@ -68,7 +68,7 @@ describe('config', () => { var ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) @@ -81,7 +81,7 @@ describe('config', () => { }) it('replace', (done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.config.replace({}, (err) => { expect(err).to.not.exist ipfs.config.show((err, config) => { @@ -94,13 +94,4 @@ describe('config', () => { }) }) }) - -// cli only feature built with show and replace -// it.skip('edit', (done) => { -// ipfs = new IPFS(require('./repo-pathe')) -// ipfs.config((err, config) => { -// expect(err).to.not.exist -// done() -// }) -// }) }) diff --git a/test/core-tests/test-files.js b/test/core/both/test-files.js similarity index 94% rename from test/core-tests/test-files.js rename to test/core/both/test-files.js index 3be2be1530..353b75a273 100644 --- a/test/core-tests/test-files.js +++ b/test/core/both/test-files.js @@ -6,13 +6,13 @@ const expect = require('chai').expect const Readable = require('stream').Readable const bs58 = require('bs58') -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') describe('files', () => { let ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core-tests/test-id.js b/test/core/both/test-id.js similarity index 91% rename from test/core-tests/test-id.js rename to test/core/both/test-id.js index 0e0d04f2c5..f1fe6218de 100644 --- a/test/core-tests/test-id.js +++ b/test/core/both/test-id.js @@ -3,13 +3,13 @@ const expect = require('chai').expect -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') describe('id', () => { var ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core-tests/test-init.js b/test/core/both/test-init.js similarity index 93% rename from test/core-tests/test-init.js rename to test/core/both/test-init.js index 63865815e8..0a32831f53 100644 --- a/test/core-tests/test-init.js +++ b/test/core/both/test-init.js @@ -2,8 +2,8 @@ 'use strict' const expect = require('chai').expect -const IPFS = require('../../src/core') -const createTempRepo = require('../utils/temp-repo') +const IPFS = require('../../../src/core') +const createTempRepo = require('../../utils/temp-repo') describe('init', function () { this.timeout(50 * 1000) diff --git a/test/core-tests/test-object.js b/test/core/both/test-object.js similarity index 70% rename from test/core-tests/test-object.js rename to test/core/both/test-object.js index b646f7699b..f5daa46cc6 100644 --- a/test/core-tests/test-object.js +++ b/test/core/both/test-object.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') const common = { setup: function (cb) { - const ipfs = new IPFS(require('./repo-path')) + const ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(() => { cb(null, ipfs) }) diff --git a/test/core-tests/test-version.js b/test/core/both/test-version.js similarity index 77% rename from test/core-tests/test-version.js rename to test/core/both/test-version.js index 7e67007dd8..2a4303b8b3 100644 --- a/test/core-tests/test-version.js +++ b/test/core/both/test-version.js @@ -3,13 +3,13 @@ const expect = require('chai').expect -const IPFS = require('../../src/core') +const IPFS = require('../../../src/core') describe('version', () => { var ipfs before((done) => { - ipfs = new IPFS(require('./repo-path')) + ipfs = new IPFS(require('../../utils/repo-path')) ipfs.load(done) }) diff --git a/test/core/browser-only/index.js b/test/core/browser-only/index.js new file mode 100644 index 0000000000..b96b9bbcdb --- /dev/null +++ b/test/core/browser-only/index.js @@ -0,0 +1,17 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') + +describe('--browser only', () => { + 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-tests/test-swarm-browser.js b/test/core/browser-only/test-swarm.js similarity index 92% rename from test/core-tests/test-swarm-browser.js rename to test/core/browser-only/test-swarm.js index b7ff1bce28..ccacec309b 100644 --- a/test/core-tests/test-swarm-browser.js +++ b/test/core/browser-only/test-swarm.js @@ -1,2 +1 @@ 'use strict' - diff --git a/test/core-tests/browser.js b/test/core/browser.js similarity index 76% rename from test/core-tests/browser.js rename to test/core/browser.js index 52a62e1368..9f5e55f6f3 100644 --- a/test/core-tests/browser.js +++ b/test/core/browser.js @@ -15,7 +15,7 @@ const idb = window.indexedDB || idb.deleteDatabase('ipfs') idb.deleteDatabase('ipfs/blocks') -describe('IPFS Repo Tests on the Browser', function () { +describe('core', function () { this.timeout(10000) before(function (done) { var repoData = [] @@ -44,15 +44,6 @@ describe('IPFS Repo Tests on the Browser', function () { }), done) }) - it('--', () => { - const testsContext = require.context('.', true, /test-*/) - testsContext - .keys() - .filter((key) => { - return !(key.endsWith('-node.js') || key.endsWith('-node')) - }) - .forEach((key) => { - testsContext(key) - }) - }) + require('./both') + require('./browser-only') }) diff --git a/test/core/node-only/index.js b/test/core/node-only/index.js new file mode 100644 index 0000000000..a11396620b --- /dev/null +++ b/test/core/node-only/index.js @@ -0,0 +1,36 @@ +/* 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-tests/test-init-node.js b/test/core/node-only/test-init.js similarity index 92% rename from test/core-tests/test-init-node.js rename to test/core/node-only/test-init.js index ee65c3e83e..a341099cc5 100644 --- a/test/core-tests/test-init-node.js +++ b/test/core/node-only/test-init.js @@ -2,8 +2,8 @@ 'use strict' const expect = require('chai').expect -const IPFS = require('../../src/core') -const createTempRepo = require('../utils/temp-repo') +const IPFS = require('../../../src/core') +const createTempRepo = require('../../utils/temp-repo') describe('init (Node.js specific)', function () { this.timeout(10000) diff --git a/test/core-tests/test-swarm-node.js b/test/core/node-only/test-swarm.js similarity index 96% rename from test/core-tests/test-swarm-node.js rename to test/core/node-only/test-swarm.js index 56ee09c800..9ce676fba9 100644 --- a/test/core-tests/test-swarm-node.js +++ b/test/core/node-only/test-swarm.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const createTempNode = require('../utils/temp-node') +const createTempNode = require('../../utils/temp-node') describe('swarm', function () { this.timeout(20000) diff --git a/test/core-tests/index.js b/test/core/node.js similarity index 54% rename from test/core-tests/index.js rename to test/core/node.js index 3aa065e623..ac5dbcbe55 100644 --- a/test/core-tests/index.js +++ b/test/core/node.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ 'use strict' -const fs = require('fs') const ncp = require('ncp').ncp const expect = require('chai').expect const path = require('path') @@ -9,7 +8,7 @@ const clean = require('../utils/clean') describe('core', () => { const repoExample = path.join(__dirname, '../go-ipfs-repo') - const repoTests = require('./repo-path') + const repoTests = require('../utils/repo-path') before((done) => { clean(repoTests) @@ -22,18 +21,6 @@ describe('core', () => { after(() => { clean(repoTests) }) - - describe('--all', () => { - const tests = fs.readdirSync(__dirname) - tests.filter((file) => { - if (file === 'index.js' || - file.endsWith('browser.js')) { - return false - } else { - return true - } - }).forEach((file) => { - require('./' + file) - }) - }) + require('./both') + require('./node-only') }) diff --git a/test/http-api-tests/index.js b/test/http-api/index.js similarity index 100% rename from test/http-api-tests/index.js rename to test/http-api/index.js diff --git a/test/http-api-tests/test-bitswap.js b/test/http-api/test-bitswap.js similarity index 100% rename from test/http-api-tests/test-bitswap.js rename to test/http-api/test-bitswap.js diff --git a/test/http-api-tests/test-block.js b/test/http-api/test-block.js similarity index 100% rename from test/http-api-tests/test-block.js rename to test/http-api/test-block.js diff --git a/test/http-api-tests/test-bootstrap.js b/test/http-api/test-bootstrap.js similarity index 100% rename from test/http-api-tests/test-bootstrap.js rename to test/http-api/test-bootstrap.js diff --git a/test/http-api-tests/test-config.js b/test/http-api/test-config.js similarity index 100% rename from test/http-api-tests/test-config.js rename to test/http-api/test-config.js diff --git a/test/http-api-tests/test-files.js b/test/http-api/test-files.js similarity index 100% rename from test/http-api-tests/test-files.js rename to test/http-api/test-files.js diff --git a/test/http-api-tests/test-id.js b/test/http-api/test-id.js similarity index 100% rename from test/http-api-tests/test-id.js rename to test/http-api/test-id.js diff --git a/test/http-api-tests/test-object.js b/test/http-api/test-object.js similarity index 100% rename from test/http-api-tests/test-object.js rename to test/http-api/test-object.js diff --git a/test/http-api-tests/test-repo.js b/test/http-api/test-repo.js similarity index 100% rename from test/http-api-tests/test-repo.js rename to test/http-api/test-repo.js diff --git a/test/http-api-tests/test-swarm.js b/test/http-api/test-swarm.js similarity index 100% rename from test/http-api-tests/test-swarm.js rename to test/http-api/test-swarm.js diff --git a/test/http-api-tests/test-version.js b/test/http-api/test-version.js similarity index 100% rename from test/http-api-tests/test-version.js rename to test/http-api/test-version.js diff --git a/test/node.js b/test/node.js index 6f97a986f4..7c7c66f2d4 100644 --- a/test/node.js +++ b/test/node.js @@ -23,13 +23,13 @@ if (process.env.TEST) { } if (testCore) { - require('./core-tests') + require('./core/node') } if (testHTTP) { - require('./http-api-tests') + require('./http-api') } if (testCLI) { - require('./cli-tests') + require('./cli') } diff --git a/test/core-tests/repo-path.js b/test/utils/repo-path.js similarity index 100% rename from test/core-tests/repo-path.js rename to test/utils/repo-path.js