diff --git a/README.md b/README.md index c16ae0c086..54bee8730f 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,9 @@ class Node extends libp2p { active: false } }, + dht: { + kBucketSize: 20 + }, // Enable/Disable Experimental features EXPERIMENTAL: { // Experimental features ("behind a flag") pubsub: false, diff --git a/package.json b/package.json index d3aaee637a..4d361a7672 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ }, "homepage": "https://github.com/libp2p/js-libp2p", "browser": { - "joi": "joi-browser" + "joi": "joi-browser", + "./test/utils/bundle-nodejs": "./test/utils/bundle-browser" }, "dependencies": { "async": "^2.6.1", diff --git a/test/create.spec.js b/test/create.spec.js new file mode 100644 index 0000000000..ea07b2e21c --- /dev/null +++ b/test/create.spec.js @@ -0,0 +1,63 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +chai.use(require('dirty-chai')) +const expect = chai.expect +const series = require('async/series') +const createNode = require('./utils/create-node') +const sinon = require('sinon') + +describe('libp2p creation', () => { + it('should be able to start and stop successfully', (done) => { + createNode([], { + config: { + EXPERIMENTAL: { + dht: true, + pubsub: true + } + } + }, (err, node) => { + expect(err).to.not.exist() + + let sw = node._switch + let cm = node.connectionManager + let dht = node._dht + let pub = node._floodSub + + sinon.spy(sw, 'start') + sinon.spy(cm, 'start') + sinon.spy(dht, 'start') + sinon.spy(pub, 'start') + sinon.spy(sw, 'stop') + sinon.spy(cm, 'stop') + sinon.spy(dht, 'stop') + sinon.spy(pub, 'stop') + sinon.spy(node, 'emit') + + series([ + (cb) => node.start(cb), + (cb) => { + expect(sw.start.calledOnce).to.be.true + expect(cm.start.calledOnce).to.be.true + expect(dht.start.calledOnce).to.be.true + expect(pub.start.calledOnce).to.be.true + expect(node.emit.calledWith('start')).to.be.true + + cb() + }, + (cb) => node.stop(cb) + ], (err) => { + expect(err).to.not.exist() + + expect(sw.stop.calledOnce).to.be.true + expect(cm.stop.calledOnce).to.be.true + expect(dht.stop.calledOnce).to.be.true + expect(pub.stop.calledOnce).to.be.true + expect(node.emit.calledWith('stop')).to.be.true + + done() + }) + }) + }) +}) \ No newline at end of file diff --git a/test/utils/bundle-browser.js b/test/utils/bundle-browser.js index d90334649d..567b49f24d 100644 --- a/test/utils/bundle-browser.js +++ b/test/utils/bundle-browser.js @@ -78,6 +78,9 @@ class Node extends libp2p { active: false } }, + dht: { + kBucketSize: 20 + }, EXPERIMENTAL: { dht: false, pubsub: false