diff --git a/package.json b/package.json index 3480150c14..253afcbe28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs", - "version": "0.10.1", + "version": "0.10.2", "description": "JavaScript implementation of the IPFS specification", "bin": { "jsipfs": "src/cli/bin.js" @@ -60,6 +60,7 @@ "boom": "^3.1.2", "bs58": "^3.0.0", "debug": "^2.2.0", + "detect-node": "^2.0.3", "fs-blob-store": "^5.2.1", "glob": "^7.0.3", "hapi": "^13.4.1", @@ -111,13 +112,13 @@ "Felix Yan ", "Francisco Baio Dias ", "Francisco Baio Dias ", + "Friedel Ziegelmayer ", "JGAntunes ", "Juan Batiz-Benet ", "Pau Ramon Revilla ", "Richard Littauer ", "Stephen Whitmore ", "Stephen Whitmore ", - "dignifiedquire ", "greenkeeperio-bot ", "kumavis ", "nginnever " diff --git a/src/core/default-repo/browser.js b/src/core/default-repo/browser.js index ffbc8e3600..cc568f06c5 100644 --- a/src/core/default-repo/browser.js +++ b/src/core/default-repo/browser.js @@ -3,6 +3,7 @@ const idb = require('idb-plus-blob-store') const IPFSRepo = require('ipfs-repo') -module.exports = () => { - return new IPFSRepo('ipfs', {stores: idb}) +module.exports = (dir) => { + const repoPath = dir || 'ipfs' + return new IPFSRepo(repoPath, {stores: idb}) } diff --git a/src/core/default-repo/index.js b/src/core/default-repo/index.js index e4f2aec4cd..81a851149c 100644 --- a/src/core/default-repo/index.js +++ b/src/core/default-repo/index.js @@ -1,6 +1,6 @@ 'use strict' -const isNode = !global.window +const isNode = require('detect-node') module.exports = isNode ? require('./node') diff --git a/src/core/ipfs/init.js b/src/core/ipfs/init.js index e0a020919e..66c4d470c6 100644 --- a/src/core/ipfs/init.js +++ b/src/core/ipfs/init.js @@ -67,7 +67,7 @@ module.exports = function init (self) { // Add the default assets to the repo. function addDefaultAssets () { // Skip this step on the browser, or if emptyRepo was supplied. - const isNode = !global.window + const isNode = require('detect-node') if (!isNode || opts.emptyRepo) { return doneImport(null) } diff --git a/test/core-tests/repo-path.js b/test/core-tests/repo-path.js index 95341dca44..a44e93d5d1 100644 --- a/test/core-tests/repo-path.js +++ b/test/core-tests/repo-path.js @@ -1,5 +1,10 @@ 'use strict' const path = require('path') +const isNode = require('detect-node') -module.exports = path.join(__dirname, '../repo-tests-run') +if (isNode) { + module.exports = path.join(__dirname, '../repo-tests-run') +} else { + module.exports = 'ipfs' +} diff --git a/test/core-tests/test-block.js b/test/core-tests/test-block.js index eb6ab650ad..cc59437f69 100644 --- a/test/core-tests/test-block.js +++ b/test/core-tests/test-block.js @@ -8,7 +8,7 @@ const IPFS = require('../../src/core') const Block = require('ipfs-block') const path = require('path') -const isNode = !global.window +const isNode = require('detect-node') const fileA = isNode ? fs.readFileSync(path.join(__dirname, '../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) diff --git a/test/node.js b/test/node.js index 0b78c42a50..6f97a986f4 100644 --- a/test/node.js +++ b/test/node.js @@ -1,5 +1,35 @@ 'use strict' -require('./core-tests') -require('./http-api-tests') -require('./cli-tests') +let testCore = true +let testHTTP = true +let testCLI = true + +if (process.env.TEST) { + switch (process.env.TEST) { + case 'core': { + testHTTP = false + testCLI = false + } break + case 'http': { + testCore = false + testCLI = false + } break + case 'cli': { + testCore = false + testCLI = false + } break + default: break + } +} + +if (testCore) { + require('./core-tests') +} + +if (testHTTP) { + require('./http-api-tests') +} + +if (testCLI) { + require('./cli-tests') +} diff --git a/test/utils/temp-repo.js b/test/utils/temp-repo.js index 3966c10342..addb581ec9 100644 --- a/test/utils/temp-repo.js +++ b/test/utils/temp-repo.js @@ -10,7 +10,7 @@ function createTempRepo () { let store let teardown - const isNode = !global.window + const isNode = require('detect-node') if (isNode) { store = require('fs-blob-store') teardown = (done) => {