Skip to content

Commit

Permalink
fix: remove node globals
Browse files Browse the repository at this point in the history
still work in progress, needs ipfs-repo first
  • Loading branch information
hugomrdias committed Apr 14, 2020
1 parent bb31c3b commit 5fcc4fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"browser": {
"./src/endpoint/server.js": "./src/endpoint/server.browser.js",
"./src/utils.js": "./src/utils.browser.js",
"./src/ipfsd-daemon.js": "./src/ipfsd-client.js"
"./src/ipfsd-daemon.js": "./src/ipfsd-client.js",
"go-ipfs-dep": false
},
"husky": {
"hooks": {
Expand Down
17 changes: 10 additions & 7 deletions test/controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const chaiPromise = require('chai-as-promised')
const { createFactory, createController } = require('../src')
const { repoExists } = require('../src/utils')
const { isBrowser, isWebWorker, isNode } = require('ipfs-utils/src/env')
const pathJoin = require('ipfs-utils/src/path-join')

/** @typedef {import("../src/index").ControllerOptions} ControllerOptions */

const expect = chai.expect
chai.use(dirtyChai)
Expand Down Expand Up @@ -52,14 +55,11 @@ describe('Controller API', function () {

const factory = createFactory({
test: true,
ipfsHttpModule: require('ipfs-http-client')
ipfsHttpModule: require('ipfs-http-client'),
ipfsModule: require('ipfs')
}, {
js: {
ipfsBin: require.resolve('ipfs/src/cli/bin.js'),
ipfsModule: require('ipfs')
},
proc: {
ipfsModule: require('ipfs')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
},
go: {
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined
Expand Down Expand Up @@ -238,7 +238,10 @@ describe('Controller API', function () {
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
const ctl = await factory.spawn(merge(opts, {
disposable: false,
test: true
test: true,
ipfsOptions: {
repo: await factory.tmpDir()
}
}))

await ctl.init()
Expand Down
9 changes: 5 additions & 4 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const { isNode, isBrowser, isWebWorker } = require('ipfs-utils/src/env')
const pathJoin = require('ipfs-utils/src/path-join')
const { createFactory, createController, createServer } = require('../src')
const Client = require('../src/ipfsd-client')
const Daemon = require('../src/ipfsd-daemon')
Expand All @@ -19,7 +20,7 @@ describe('`createController` should return the correct class', () => {
disposable: false,
ipfsModule: require('ipfs'),
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})

if (!isNode) {
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('`createController` should return the correct class', () => {
disposable: false,
ipfsModule: require('ipfs'),
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})

expect(f).to.be.instanceOf(Client)
Expand All @@ -70,7 +71,7 @@ const types = [{
type: 'js',
test: true,
ipfsModule: require('ipfs'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
}, {
...defaultOps,
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined,
Expand All @@ -87,7 +88,7 @@ const types = [{
test: true,
remote: true,
ipfsModule: require('ipfs'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
}, {
...defaultOps,
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined,
Expand Down
7 changes: 4 additions & 3 deletions test/factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const { isNode } = require('ipfs-utils/src/env')
const pathJoin = require('ipfs-utils/src/path-join')
const { createFactory } = require('../src')

const expect = chai.expect
Expand All @@ -18,7 +19,7 @@ const types = [{
type: 'js',
test: true,
ipfsModule: require('ipfs'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
}, {
...defaultOps,
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined,
Expand All @@ -35,7 +36,7 @@ const types = [{
remote: true,
test: true,
ipfsModule: require('ipfs'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
}, {
...defaultOps,
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined,
Expand Down Expand Up @@ -92,7 +93,7 @@ describe('`Factory spawn()` ', function () {
remote: opts.remote,
ipfsModule: require('ipfs'),
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require.resolve('ipfs/src/cli/bin.js')
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})
expect(ctl).to.exist()
expect(ctl.opts.test).to.be.true()
Expand Down

0 comments on commit 5fcc4fc

Please sign in to comment.