diff --git a/.gitignore b/.gitignore index e920c16..8cb3dc0 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ node_modules # Optional REPL history .node_repl_history + +dist +lib \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a85f00e..d689c79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ sudo: false language: node_js node_js: - - "4.0" + - 4 + - 5 # Make sure we have new NPM. before_install: - npm install -g npm script: + - npm run lint - npm test addons: diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..210ecb8 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,21 @@ +'use strict' + +const gulp = require('gulp') +const multiaddr = require('multiaddr') +const WSlibp2p = require('./src') + +let ws + +gulp.task('test:browser:before', (done) => { + ws = new WSlibp2p() + const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets') + ws.createListener(mh, (socket) => { + socket.pipe(socket) + }, done) +}) + +gulp.task('test:browser:after', (done) => { + ws.close(done) +}) + +require('dignified.js/gulp')(gulp) diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 54c9fa9..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['mocha'], - - files: [ - 'tests/browser-nodejs/browser.js' - ], - - preprocessors: { - 'tests/*': ['webpack'], - 'tests/browser-nodejs/*': ['webpack'] - }, - - webpack: { - resolve: { - extensions: ['', '.js'] - }, - node: { - Buffer: true - } - }, - - webpackMiddleware: { - noInfo: true, - stats: { - colors: true - } - }, - reporters: ['spec'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: false, - browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'], - captureTimeout: 60000, - singleRun: true - }) -} diff --git a/package.json b/package.json index fc68428..53b3e3a 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,15 @@ "name": "libp2p-websockets", "version": "0.2.1", "description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec", - "main": "src/index.js", + "main": "lib/index.js", + "jsnext:main": "src/index.js", "scripts": { - "test:compliance:connection": "node tests/connection.js", - "test:compliance:transport": "node tests/transport.js", - "test:specific": "mocha tests/*-test.js", - "test:node": "npm run test:specific", - "test:browser": "node tests/browser-nodejs/test.js", - "test": "npm run test:node && npm run test:browser", - "test-2": "npm run test:specific && npm run test:compliance:transport && npm run test:compliance:connection", - "lint": "standard" + "lint": "dignified-lint", + "test": "gulp test", + "test:node": "gulp test:node", + "test:browser": "gulp test:browser", + "build": "dignified-build", + "release": "dignified-release" }, "pre-commit": [ "lint", @@ -37,19 +36,10 @@ }, "devDependencies": { "chai": "^3.5.0", + "dignified.js": "github:dignifiedquire/dignified.js", + "gulp": "^3.9.1", "interface-connection": "0.0.3", "interface-transport": "^0.1.1", - "istanbul": "^0.4.2", - "karma": "^0.13.22", - "karma-chrome-launcher": "^0.2.2", - "karma-firefox-launcher": "^0.1.7", - "karma-mocha": "^0.2.2", - "karma-spec-reporter": "0.0.24", - "karma-webpack": "^1.7.0", - "mocha": "^2.4.5", - "pre-commit": "^1.1.2", - "standard": "^6.0.7", - "tape": "^4.2.0", - "webpack": "^2.1.0-beta.4" + "pre-commit": "^1.1.2" } } diff --git a/src/index.js b/src/index.js index 6027665..3b40187 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +'use strict' + // const debug = require('debug') // const log = debug('libp2p:tcp') const SWS = require('simple-websocket') diff --git a/tests/browser-nodejs/browser.js b/test/browser.js similarity index 97% rename from tests/browser-nodejs/browser.js rename to test/browser.js index 81fc72e..d78cfec 100644 --- a/tests/browser-nodejs/browser.js +++ b/test/browser.js @@ -1,9 +1,9 @@ -'use strict' /* eslint-env mocha */ +'use strict' const expect = require('chai').expect -const WSlibp2p = require('../../src') const multiaddr = require('multiaddr') +const WSlibp2p = require('../src') describe('libp2p-websockets', function () { this.timeout(10000) diff --git a/tests/libp2p-websockets-test.js b/test/node.js similarity index 99% rename from tests/libp2p-websockets-test.js rename to test/node.js index dc43182..e026350 100644 --- a/tests/libp2p-websockets-test.js +++ b/test/node.js @@ -1,8 +1,9 @@ /* eslint-env mocha */ +'use strict' const expect = require('chai').expect -const WSlibp2p = require('../src') const multiaddr = require('multiaddr') +const WSlibp2p = require('../src') describe('libp2p-websockets', function () { this.timeout(10000) diff --git a/tests/browser-nodejs/test.js b/tests/browser-nodejs/test.js deleted file mode 100644 index 854f0c4..0000000 --- a/tests/browser-nodejs/test.js +++ /dev/null @@ -1,28 +0,0 @@ -const Server = require('karma').Server -const path = require('path') - -const WSlibp2p = require('../../src') -const multiaddr = require('multiaddr') - -var ws - -function createListener (done) { - ws = new WSlibp2p() - const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets') - ws.createListener(mh, (socket) => { - socket.pipe(socket) - }, done) -} - -function stopServer (done) { - ws.close(done) -} - -function run (done) { - new Server({ - configFile: path.join(__dirname, '/../../karma.conf.js'), - singleRun: true - }, done).start() -} - -createListener(() => run((exitCode) => stopServer(() => process.exit(exitCode))))