diff --git a/.gitignore b/.gitignore index cb265cefb..93f136199 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ node_modules npm-debug.log -coverage.html -lib-cov/ -dist diff --git a/.travis.yml b/.travis.yml index f935fb987..cbfebefd2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: node_js node_js: - "4" - "6" - - "7" + - "8" git: depth: 1 notifications: diff --git a/Makefile b/Makefile deleted file mode 100644 index da335f66d..000000000 --- a/Makefile +++ /dev/null @@ -1,16 +0,0 @@ - -BENCHMARKS = $(shell find bench -type f ! -name 'runner.js') - -test: - @./node_modules/.bin/gulp test - -test-cov: lib-cov - EIO_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html - -lib-cov: - jscoverage --no-highlight lib lib-cov - -bench: - @node $(PROFILEFLAGS) bench/runner.js $(BENCHMARKS) - -.PHONY: test test-cov bench diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 1cd3a5d8e..000000000 --- a/gulpfile.js +++ /dev/null @@ -1,52 +0,0 @@ -const gulp = require('gulp'); -const mocha = require('gulp-mocha'); -const babel = require('gulp-babel'); -const nsp = require('gulp-nsp'); -const eslint = require('gulp-eslint'); - -const TESTS = 'test/*.js'; -const REPORTER = 'dot'; - -gulp.task('default', ['transpile']); - -gulp.task('test', ['nsp', 'lint'], function () { - if (parseInt(process.versions.node, 10) < 4 && process.env.EIO_WS_ENGINE !== 'ws') { - console.info('Node version < 4, skipping tests with uws engine'); - process.exit(); - } - return gulp.src(TESTS, {read: false}) - .pipe(mocha({ - slow: 500, - reporter: REPORTER, - bail: true - })) - .once('error', function (err) { - console.error(err.stack); - process.exit(1); - }) - .once('end', function () { - process.exit(); - }); -}); - -gulp.task('lint', function () { - return gulp.src([ - '*.js', - 'lib/**/*.js', - 'test/**/*.js' - ]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); -}); - -// By default, individual js files are transformed by babel and exported to /dist -gulp.task('transpile', function () { - return gulp.src(['lib/**/*.js'], { base: 'lib' }) - .pipe(babel({ 'presets': ['es2015'] })) - .pipe(gulp.dest('dist')); -}); - -gulp.task('nsp', function (cb) { - nsp({package: __dirname + '/package.json'}, cb); -}); diff --git a/index.js b/index.js deleted file mode 100644 index ebb4e1024..000000000 --- a/index.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = process.env.EIO_COV - ? require('./lib-cov/engine.io') - : require('./lib/engine.io'); diff --git a/lib/server.js b/lib/server.js index 09ab49ca0..57886b596 100644 --- a/lib/server.js +++ b/lib/server.js @@ -91,14 +91,6 @@ Server.errorMessages = { util.inherits(Server, EventEmitter); -/** - * Hash of open clients. - * - * @api public - */ - -Server.prototype.clients; - /** * Initialize websocket server * @@ -355,7 +347,7 @@ Server.prototype.handleUpgrade = function (req, socket, upgradeHead) { return; } - var head = new Buffer(upgradeHead.length); + var head = new Buffer(upgradeHead.length); // eslint-disable-line node/no-deprecated-api upgradeHead.copy(head); upgradeHead = null; diff --git a/lib/socket.js b/lib/socket.js index f77a4ca07..526707c26 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -91,7 +91,6 @@ Socket.prototype.onPacket = function (packet) { this.setPingTimeout(); switch (packet.type) { - case 'ping': debug('got ping'); this.sendPacket('pong'); diff --git a/lib/transports/polling.js b/lib/transports/polling.js index 6d5a20bef..6c5c0cc33 100644 --- a/lib/transports/polling.js +++ b/lib/transports/polling.js @@ -136,7 +136,7 @@ Polling.prototype.onDataRequest = function (req, res) { this.dataReq = req; this.dataRes = res; - var chunks = isBinary ? new Buffer(0) : ''; + var chunks = isBinary ? new Buffer(0) : ''; // eslint-disable-line node/no-deprecated-api var self = this; function cleanup () { @@ -162,7 +162,7 @@ Polling.prototype.onDataRequest = function (req, res) { } if (contentLength > self.maxHttpBufferSize) { - chunks = isBinary ? new Buffer(0) : ''; + chunks = isBinary ? new Buffer(0) : ''; // eslint-disable-line node/no-deprecated-api req.connection.destroy(); } } diff --git a/package.json b/package.json index 255deb076..35ba38b7f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "engine.io", "version": "3.1.0", "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server", - "main": "./lib/engine.io", + "main": "lib/engine.io", "author": "Guillermo Rauch ", "homepage": "https://github.com/socketio/engine.io", "contributors": [ @@ -33,17 +33,16 @@ "cookie": "0.3.1" }, "devDependencies": { - "babel-eslint": "5.0.0", + "babel-eslint": "^7.2.3", "babel-preset-es2015": "^6.24.0", "engine.io-client": "3.1.0", - "eslint-config-standard": "4.4.0", - "eslint-plugin-standard": "1.3.2", + "eslint": "^4.5.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-node": "^5.1.1", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", "expect.js": "^0.3.1", - "gulp": "^3.9.1", - "gulp-babel": "^6.1.2", - "gulp-eslint": "1.1.1", - "gulp-mocha": "^4.3.0", - "gulp-nsp": "^2.4.1", "mocha": "^3.2.0", "s": "0.1.1", "superagent": "0.15.4" @@ -52,14 +51,14 @@ "uws": "~0.14.4" }, "scripts": { - "test": "gulp test; EIO_WS_ENGINE=ws gulp test;" + "lint": "eslint lib/ test/ *.js", + "test": "npm run lint && mocha && EIO_WS_ENGINE=ws mocha" }, "repository": { "type": "git", "url": "git@github.com:socketio/engine.io.git" }, "files": [ - "index.js", "lib/" ] } diff --git a/test/jsonp.js b/test/jsonp.js index b0ca0d973..99f18a674 100644 --- a/test/jsonp.js +++ b/test/jsonp.js @@ -11,7 +11,7 @@ var request = require('superagent'); describe('JSONP', function () { before(function () { // we have to override the browser's functionality for JSONP - document = { // eslint-disable-line no-native-reassign, no-undef + document = { // eslint-disable-line no-global-assign body: { appendChild: function () {}, removeChild: function () {} @@ -44,10 +44,10 @@ describe('JSONP', function () { appendChild: function () {}, submit: function () { request - .post(this.action) - .type('form') - .send({ d: self.areaValue }) - .end(function () {}); + .post(this.action) + .type('form') + .send({ d: self.areaValue }) + .end(function () {}); } }; return form; @@ -156,7 +156,7 @@ describe('JSONP', function () { }); it('should arrive from server to client and back with binary data (pollingJSONP)', function (done) { - var binaryData = new Buffer(5); + var binaryData = Buffer.allocUnsafe(5); for (var i = 0; i < 5; i++) binaryData[i] = i; engine.on('connection', function (conn) { conn.on('message', function (msg) { @@ -178,7 +178,7 @@ describe('JSONP', function () { it('should trigger when server closes a client', function (done) { var engine = listen({ allowUpgrades: false, transports: ['polling'] }, function (port) { var socket = new eioc.Socket('ws://localhost:' + port, - { transports: ['polling'], forceJSONP: true, upgrade: false }); + { transports: ['polling'], forceJSONP: true, upgrade: false }); var total = 2; engine.on('connection', function (conn) { diff --git a/test/server.js b/test/server.js index 8cdfc9db8..50164b81d 100644 --- a/test/server.js +++ b/test/server.js @@ -1,3 +1,4 @@ +/* eslint-disable standard/no-callback-literal */ /** * Tests dependencies. @@ -352,18 +353,18 @@ describe('server', function () { var socket = new eioc.Socket('ws://localhost:%d'.s(port)); socket.on('open', function () { request.get('http://localhost:%d/engine.io/'.s(port)) - .set({ connection: 'close' }) - .query({ transport: 'websocket', sid: socket.id }) - .end(function (err, res) { - expect(err).to.be(null); - expect(res.status).to.be(400); - expect(res.body.code).to.be(3); - socket.send('echo'); - socket.on('message', function (msg) { - expect(msg).to.be('echo'); - done(); + .set({ connection: 'close' }) + .query({ transport: 'websocket', sid: socket.id }) + .end(function (err, res) { + expect(err).to.be(null); + expect(res.status).to.be(400); + expect(res.body.code).to.be(3); + socket.send('echo'); + socket.on('message', function (msg) { + expect(msg).to.be('echo'); + done(); + }); }); - }); }); }); }); @@ -1353,7 +1354,7 @@ describe('server', function () { }); it('should arrive when binary data is sent as Buffer (ws)', function (done) { - var binaryData = new Buffer(5); + var binaryData = Buffer.allocUnsafe(5); for (var i = 0; i < binaryData.length; i++) { binaryData.writeInt8(i, i); } @@ -1379,7 +1380,7 @@ describe('server', function () { }); it('should arrive when binary data sent as Buffer (polling)', function (done) { - var binaryData = new Buffer(5); + var binaryData = Buffer.allocUnsafe(5); for (var i = 0; i < binaryData.length; i++) { binaryData.writeInt8(i, i); } @@ -1406,7 +1407,7 @@ describe('server', function () { }); it('should arrive as ArrayBuffer if requested when binary data sent as Buffer (ws)', function (done) { - var binaryData = new Buffer(5); + var binaryData = Buffer.allocUnsafe(5); for (var i = 0; i < binaryData.length; i++) { binaryData.writeInt8(i, i); } @@ -1435,7 +1436,7 @@ describe('server', function () { }); it('should arrive as ArrayBuffer if requested when binary data sent as Buffer (polling)', function (done) { - var binaryData = new Buffer(5); + var binaryData = Buffer.allocUnsafe(5); for (var i = 0; i < binaryData.length; i++) { binaryData.writeInt8(i, i); } @@ -1516,8 +1517,8 @@ describe('server', function () { var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] }); socket.on('open', function () { for (var i = 0; i < messageCount; i++) { -// connection.send('message: ' + i); // works - connection.send(messagePayload + '|message: ' + i); // does not work + // connection.send('message: ' + i); // works + connection.send(messagePayload + '|message: ' + i); // does not work } var receivedCount = 0; socket.on('message', function (msg) { @@ -1614,7 +1615,8 @@ describe('server', function () { key: fs.readFileSync('test/fixtures/server.key'), cert: fs.readFileSync('test/fixtures/server.crt'), ca: fs.readFileSync('test/fixtures/ca.crt'), - requestCert: true + requestCert: true, + rejectUnauthorized: false }; var opts = { @@ -2309,7 +2311,7 @@ describe('server', function () { it('should compress by default', function (done) { var engine = listen({ transports: ['polling'] }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(1024); + var buf = Buffer.allocUnsafe(1024); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf); }); @@ -2337,7 +2339,7 @@ describe('server', function () { it('should compress using deflate', function (done) { var engine = listen({ transports: ['polling'] }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(1024); + var buf = Buffer.allocUnsafe(1024); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf); }); @@ -2365,7 +2367,7 @@ describe('server', function () { it('should set threshold', function (done) { var engine = listen({ transports: ['polling'], httpCompression: { threshold: 0 } }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(10); + var buf = Buffer.allocUnsafe(10); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf); }); @@ -2390,7 +2392,7 @@ describe('server', function () { it('should disable compression', function (done) { var engine = listen({ transports: ['polling'], httpCompression: false }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(1024); + var buf = Buffer.allocUnsafe(1024); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf); }); @@ -2415,7 +2417,7 @@ describe('server', function () { it('should disable compression per message', function (done) { var engine = listen({ transports: ['polling'] }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(1024); + var buf = Buffer.allocUnsafe(1024); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf, { compress: false }); }); @@ -2440,7 +2442,7 @@ describe('server', function () { it('should not compress when the byte size is below threshold', function (done) { var engine = listen({ transports: ['polling'] }, function (port) { engine.on('connection', function (conn) { - var buf = new Buffer(100); + var buf = Buffer.allocUnsafe(100); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf); }); @@ -2478,7 +2480,7 @@ describe('server', function () { done(); }; - var buf = new Buffer(100); + var buf = Buffer.allocUnsafe(100); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf, { compress: true }); }); @@ -2500,7 +2502,7 @@ describe('server', function () { done(); }; - var buf = new Buffer(100); + var buf = Buffer.allocUnsafe(100); for (var i = 0; i < buf.length; i++) buf[i] = i % 0xff; conn.send(buf, { compress: true }); });