From 27062f5663c57540484719cd81112a119b083f0c Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Thu, 21 Jan 2016 17:50:57 +0800 Subject: [PATCH 01/44] added babel integration using browserify API --- package.json | 2 ++ support/browserify.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/package.json b/package.json index d24d344a..76260493 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "backo2": "1.0.2" }, "devDependencies": { + "babel-preset-es2015": "^6.3.13", + "babelify": "^7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", "concat-stream": "1.5.1", diff --git a/support/browserify.js b/support/browserify.js index ec9005b2..fa0ad014 100644 --- a/support/browserify.js +++ b/support/browserify.js @@ -7,6 +7,7 @@ var browserify = require('browserify'); var concat = require('concat-stream'); var derequire = require('derequire'); var path = require.resolve('../'); +var babelify = require("babelify"); /** * Module exports. @@ -29,6 +30,7 @@ function build(fn){ standalone: 'io' }) .exclude('ws') + .transform(babelify) .bundle(); bundle.on('error', function (err) { From c9c93441f211a58c5994dd5e3f58c0eb56558041 Mon Sep 17 00:00:00 2001 From: Zheng Weihan Date: Sun, 24 Jan 2016 16:47:07 +0800 Subject: [PATCH 02/44] gulp build system. Implemented gulp for build and test-node. --- gulpfile.js | 32 ++++++++++++++++++++++++++++++++ package.json | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..c0af6b8e --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,32 @@ +var gulp = require('gulp'); +var mocha = require('gulp-mocha'); +var file = require('gulp-file'); + +var browserify = require('./support/browserify.js'); + + +gulp.task('build', function(){ + browserify(function(err, out){ + if(err){ + throw err; + }else{ + gulp.src('') + .pipe(file('socket.io.js', out)) + .pipe(gulp.dest('./')); + } + }); +}); + +gulp.task('test-node', function(){ + gulp.src(['test/*.js', 'test/support/*.js']) + .pipe(mocha({ + reporter: 'dot' + })) + .once('error', function () { + process.exit(1); + }) + .once('end', function () { + process.exit(); + }); +}); + diff --git a/package.json b/package.json index d24d344a..636fc492 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,9 @@ "concat-stream": "1.5.1", "derequire": "2.0.3", "expect.js": "0.3.1", + "gulp": "^3.9.0", + "gulp-file": "^0.2.0", + "gulp-mocha": "^2.2.0", "has-cors": "1.1.0", "istanbul": "0.4.2", "mocha": "2.3.4", From 1abf879d013293400fa886e7e46ec494fbeea7ba Mon Sep 17 00:00:00 2001 From: Zheng Weihan Date: Mon, 25 Jan 2016 00:04:22 +0800 Subject: [PATCH 03/44] add test-cov task to gulp --- gulpfile.js | 23 +++++++++++++++++++++++ package.json | 1 + 2 files changed, 24 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index c0af6b8e..0ae969d8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,7 @@ var gulp = require('gulp'); var mocha = require('gulp-mocha'); var file = require('gulp-file'); +var istanbul = require('gulp-istanbul'); var browserify = require('./support/browserify.js'); @@ -30,3 +31,25 @@ gulp.task('test-node', function(){ }); }); +gulp.task('istanbul-pre-test', function () { + return gulp.src(['lib/**/*.js']) + // Covering files + .pipe(istanbul()) + // Force `require` to return covered files + .pipe(istanbul.hookRequire()); +}); + +gulp.task('test-cov', ['istanbul-pre-test'], function(){ + gulp.src(['test/*.js', 'test/support/*.js']) + .pipe(mocha({ + reporter: 'dot' + })) + .pipe(istanbul.writeReports()) + .once('error', function (){ + process.exit(1); + }) + .once('end', function (){ + process.exit(); + }); +}); + diff --git a/package.json b/package.json index 636fc492..00984d96 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "expect.js": "0.3.1", "gulp": "^3.9.0", "gulp-file": "^0.2.0", + "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.2.0", "has-cors": "1.1.0", "istanbul": "0.4.2", From d6492d234ec377bed397d9b5520f99350b1331ef Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Mon, 25 Jan 2016 18:49:25 +0800 Subject: [PATCH 04/44] Add webpack stream to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 00984d96..942b279b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "socket.io": "1.4.4", "text-blob-builder": "0.0.1", "uglify-js": "2.6.1", + "webpack-stream": "^3.1.0", "zuul": "3.9.0", "zuul-ngrok": "3.2.0" }, From 97591f6d6eb93bb50a416f1cc5a1a7627286643e Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Mon, 25 Jan 2016 18:59:36 +0800 Subject: [PATCH 05/44] Add gulp task for webpack --- gulpfile.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 0ae969d8..0fada027 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,9 +2,20 @@ var gulp = require('gulp'); var mocha = require('gulp-mocha'); var file = require('gulp-file'); var istanbul = require('gulp-istanbul'); +var webpack = require('webpack-stream'); -var browserify = require('./support/browserify.js'); +// var browserify = require('./support/browserify.js'); +gulp.task('webpack', function() { + return gulp.src('lib/*.js') + .pipe(webpack({ + entry: './lib/index.js', + output: { + filename: 'socket.io.js', + }, + })) + .pipe(gulp.dest('./')); +}); gulp.task('build', function(){ browserify(function(err, out){ From 3799b60d5b2c2d56d2aa2c0df358599a7febd548 Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Thu, 21 Jan 2016 17:50:57 +0800 Subject: [PATCH 06/44] added babel integration using browserify API --- package.json | 2 ++ support/browserify.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/package.json b/package.json index 00984d96..b7ad7341 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "backo2": "1.0.2" }, "devDependencies": { + "babel-preset-es2015": "^6.3.13", + "babelify": "^7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", "concat-stream": "1.5.1", diff --git a/support/browserify.js b/support/browserify.js index ec9005b2..fa0ad014 100644 --- a/support/browserify.js +++ b/support/browserify.js @@ -7,6 +7,7 @@ var browserify = require('browserify'); var concat = require('concat-stream'); var derequire = require('derequire'); var path = require.resolve('../'); +var babelify = require("babelify"); /** * Module exports. @@ -29,6 +30,7 @@ function build(fn){ standalone: 'io' }) .exclude('ws') + .transform(babelify) .bundle(); bundle.on('error', function (err) { From 94127a34656a3d959625eda12a17113a46786d0d Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Tue, 26 Jan 2016 16:16:50 +0800 Subject: [PATCH 07/44] added babel integration --- .babelrc | 1 + gulpfile.js | 8 +++++++- package.json | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..9d8d5165 --- /dev/null +++ b/.babelrc @@ -0,0 +1 @@ +{ "presets": ["es2015"] } diff --git a/gulpfile.js b/gulpfile.js index 0ae969d8..9d44457f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,9 +2,15 @@ var gulp = require('gulp'); var mocha = require('gulp-mocha'); var file = require('gulp-file'); var istanbul = require('gulp-istanbul'); - +var babel = require("gulp-babel"); var browserify = require('./support/browserify.js'); +// By default, individual js files are transformed by babel and exported to /dist +gulp.task("babel", function () { + return gulp.src("lib/*.js") + .pipe(babel()) + .pipe(gulp.dest("dist")); +}); gulp.task('build', function(){ browserify(function(err, out){ diff --git a/package.json b/package.json index b7ad7341..16be0e55 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "derequire": "2.0.3", "expect.js": "0.3.1", "gulp": "^3.9.0", + "gulp-babel": "^6.1.1", "gulp-file": "^0.2.0", "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.2.0", From 0fc23f175c39c8f8ee36b82545c6ed223a0ac872 Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Thu, 28 Jan 2016 13:23:50 +0800 Subject: [PATCH 08/44] Integrate webpack and babel in gulpfile.js and change gulp task to build-webpack --- gulpfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index cc6b4ef7..0f983980 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,8 +7,9 @@ var webpack = require('webpack-stream'); // var browserify = require('./support/browserify.js'); -gulp.task('webpack', function() { +gulp.task('build-webpack', function() { return gulp.src('lib/*.js') + .pipe(babel()) .pipe(webpack({ entry: './lib/index.js', output: { From 3ddacd9fc153dcf7226e6c050e2daf89064a2b90 Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Sat, 30 Jan 2016 09:58:33 +0800 Subject: [PATCH 09/44] Swap the order of babel and webpack --- gulpfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 0f983980..f81050e1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,14 +8,14 @@ var webpack = require('webpack-stream'); // var browserify = require('./support/browserify.js'); gulp.task('build-webpack', function() { - return gulp.src('lib/*.js') - .pipe(babel()) + return gulp.src('lib/*.js') .pipe(webpack({ entry: './lib/index.js', output: { filename: 'socket.io.js', }, })) + .pipe(babel()) .pipe(gulp.dest('./')); }); From aad48e7c491baf123d3743fd8f8eab6336a0a1d6 Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Sat, 30 Jan 2016 10:03:36 +0800 Subject: [PATCH 10/44] disable compact by default, enabled browserify --- gulpfile.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f81050e1..179af5cf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ var istanbul = require('gulp-istanbul'); var babel = require("gulp-babel"); var webpack = require('webpack-stream'); -// var browserify = require('./support/browserify.js'); +var browserify = require('./support/browserify.js'); gulp.task('build-webpack', function() { return gulp.src('lib/*.js') @@ -15,7 +15,9 @@ gulp.task('build-webpack', function() { filename: 'socket.io.js', }, })) - .pipe(babel()) + .pipe(babel({ + compact: false + })) .pipe(gulp.dest('./')); }); From fdef60a24ea3edd5f0da746f5f7a133844fe05e1 Mon Sep 17 00:00:00 2001 From: Zheng Weihan Date: Sat, 30 Jan 2016 13:29:34 +0800 Subject: [PATCH 11/44] added new task to run zuul. added a test function to replicate the same task in makefile. --- gulpfile.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 179af5cf..5bd93c85 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,6 +4,7 @@ var file = require('gulp-file'); var istanbul = require('gulp-istanbul'); var babel = require("gulp-babel"); var webpack = require('webpack-stream'); +var exec = require('child_process').exec; var browserify = require('./support/browserify.js'); @@ -40,6 +41,32 @@ gulp.task('build', function(){ }); }); +gulp.task('test', [process.env.BROWSER_NAME ? 'test-zuul' : 'test-node'], function(){ +}); + +gulp.task('test-zuul', function(){ + if(process.env.BROWSER_PLATFORM){ + exec('./node_modules/zuul/bin/zuul ' + + '--browser-name ' + process.env.BROWSER_NAME + ' ' + + '--browser-version ' + process.env.BROWSER_VERSION + ' ' + + '--browser-platform ' +process.env.BROWSER_PLATFORM + ' ' + + 'test/index.js', + function(err, stdout, stderr){ + console.log(stdout); + console.error(stderr); + }); + }else{ + exec('./node_modules/zuul/bin/zuul ' + + '--browser-name ' + process.env.BROWSER_NAME + ' ' + + '--browser-version ' + process.env.BROWSER_VERSION + ' ' + + 'test/index.js', + function(err, stdout, stderr){ + console.log(stdout); + console.error(stderr); + }); + } +}); + gulp.task('test-node', function(){ gulp.src(['test/*.js', 'test/support/*.js']) .pipe(mocha({ From fe3837c9f695e566e0db9a1a19a40c7cb452a5c0 Mon Sep 17 00:00:00 2001 From: Zheng Weihan Date: Sat, 30 Jan 2016 13:37:44 +0800 Subject: [PATCH 12/44] change npm test in package to use gulp instead of make --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3064e262..32c25f87 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "zuul-ngrok": "3.2.0" }, "scripts": { - "test": "make test" + "test": "gulp test" }, "contributors": [ { From ee72188f6dcc6f1baaf3c50866ec4aab284a5136 Mon Sep 17 00:00:00 2001 From: Zheng Weihan Date: Sun, 31 Jan 2016 10:18:14 +0800 Subject: [PATCH 13/44] remove dynamic dependencies. --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 32c25f87..2336f2b2 100644 --- a/package.json +++ b/package.json @@ -27,25 +27,25 @@ "backo2": "1.0.2" }, "devDependencies": { - "babel-preset-es2015": "^6.3.13", - "babelify": "^7.2.0", + "babel-preset-es2015": "6.3.13", + "babelify": "7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", "concat-stream": "1.5.1", "derequire": "2.0.3", "expect.js": "0.3.1", - "gulp": "^3.9.0", - "gulp-babel": "^6.1.1", - "gulp-file": "^0.2.0", - "gulp-istanbul": "^0.10.3", - "gulp-mocha": "^2.2.0", + "gulp": "3.9.0", + "gulp-babel": "6.1.1", + "gulp-file": "0.2.0", + "gulp-istanbul": "0.10.3", + "gulp-mocha": "2.2.0", "has-cors": "1.1.0", "istanbul": "0.4.2", "mocha": "2.3.4", "socket.io": "1.4.4", "text-blob-builder": "0.0.1", "uglify-js": "2.6.1", - "webpack-stream": "^3.1.0", + "webpack-stream": "3.1.0", "zuul": "3.9.0", "zuul-ngrok": "3.2.0" }, From b31f21741e7e93399521a568cbfc80fa4ff8be57 Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Sun, 31 Jan 2016 11:24:53 +0800 Subject: [PATCH 14/44] Remove babelrc file and move the settings inline to gulpfile.js --- .babelrc | 1 - gulpfile.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .babelrc diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 9d8d5165..00000000 --- a/.babelrc +++ /dev/null @@ -1 +0,0 @@ -{ "presets": ["es2015"] } diff --git a/gulpfile.js b/gulpfile.js index 5bd93c85..bf0e200a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -17,6 +17,7 @@ gulp.task('build-webpack', function() { }, })) .pipe(babel({ + presets: ['es2015'], compact: false })) .pipe(gulp.dest('./')); From a8903672c90f2f0d1daa4e1892b0f870b1916dc7 Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Sun, 31 Jan 2016 13:05:15 +0800 Subject: [PATCH 15/44] removed babel task from gulp --- gulpfile.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index bf0e200a..c7ef4a6a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,13 +23,6 @@ gulp.task('build-webpack', function() { .pipe(gulp.dest('./')); }); -// By default, individual js files are transformed by babel and exported to /dist -gulp.task("babel", function () { - return gulp.src("lib/*.js") - .pipe(babel()) - .pipe(gulp.dest("dist")); -}); - gulp.task('build', function(){ browserify(function(err, out){ if(err){ From 468200ed8ce2bb8cf9c4e4be83a86b1b2dee9170 Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Sun, 31 Jan 2016 16:33:00 +0800 Subject: [PATCH 16/44] Expose io variable to global when bundling with webpack --- gulpfile.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index bf0e200a..3fad90c7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,12 +13,13 @@ gulp.task('build-webpack', function() { .pipe(webpack({ entry: './lib/index.js', output: { + library: 'io', + libraryTarget: 'umd', filename: 'socket.io.js', }, - })) - .pipe(babel({ - presets: ['es2015'], - compact: false + externals: { + 'global': glob() + } })) .pipe(gulp.dest('./')); }); @@ -103,3 +104,14 @@ gulp.task('test-cov', ['istanbul-pre-test'], function(){ }); }); +/** + * Populates `global`. + * + * @api private + */ + +function glob(){ + return 'typeof self !== "undefined" ? self : ' + + 'typeof window !== "undefined" ? window : ' + + 'typeof global !== "undefined" ? global : {}'; +} \ No newline at end of file From 1c1ee454f540816cfffa3ce24332d7d7031745b5 Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Sun, 31 Jan 2016 16:57:31 +0800 Subject: [PATCH 17/44] move babel from standalone to webpack loader --- gulpfile.js | 13 +++++++++++-- package.json | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fe37739c..95565c2d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,6 @@ var gulp = require('gulp'); var mocha = require('gulp-mocha'); var file = require('gulp-file'); var istanbul = require('gulp-istanbul'); -var babel = require("gulp-babel"); var webpack = require('webpack-stream'); var exec = require('child_process').exec; @@ -19,7 +18,17 @@ gulp.task('build-webpack', function() { }, externals: { 'global': glob() - } + }, + module: { + loaders: [{ + test: /\.(js|jsx)?$/, + exclude: /(node_modules|bower_components)/, + loader: 'babel', // 'babel-loader' is also a legal name to reference + query: { + presets: ['react', 'es2015'] + } + }] + } })) .pipe(gulp.dest('./')); }); diff --git a/package.json b/package.json index 2336f2b2..38d31607 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,10 @@ "backo2": "1.0.2" }, "devDependencies": { - "babel-preset-es2015": "6.3.13", + "babel-core": "^6.4.5", + "babel-loader": "^6.2.1", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", "babelify": "7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", @@ -35,7 +38,6 @@ "derequire": "2.0.3", "expect.js": "0.3.1", "gulp": "3.9.0", - "gulp-babel": "6.1.1", "gulp-file": "0.2.0", "gulp-istanbul": "0.10.3", "gulp-mocha": "2.2.0", From b14018eed6a306efda4c7d7c4345de0092ce679b Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Mon, 1 Feb 2016 13:00:13 +0800 Subject: [PATCH 18/44] fixed test case --- gulpfile.js | 8 +++++--- test/socket.js | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 95565c2d..a071d503 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -74,9 +74,11 @@ gulp.task('test-zuul', function(){ gulp.task('test-node', function(){ gulp.src(['test/*.js', 'test/support/*.js']) .pipe(mocha({ - reporter: 'dot' + reporter: 'dot', + bail: true })) - .once('error', function () { + .once('error', function (err) { + console.error(err.stack); process.exit(1); }) .once('end', function () { @@ -116,4 +118,4 @@ function glob(){ return 'typeof self !== "undefined" ? self : ' + 'typeof window !== "undefined" ? window : ' + 'typeof global !== "undefined" ? global : {}'; -} \ No newline at end of file +} diff --git a/test/socket.js b/test/socket.js index 283d30c3..ac13e8e6 100644 --- a/test/socket.js +++ b/test/socket.js @@ -47,7 +47,6 @@ describe('socket', function(){ socket.once('pong', function(ms){ expect(pinged).to.be(true); expect(ms).to.be.a('number'); - expect(ms).to.be.greaterThan(0); socket.disconnect(); done(); }); From d5467efcad303a9541794f428e5b00d4d2fb7bf2 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 3 Feb 2016 17:05:35 +0800 Subject: [PATCH 19/44] removed dynamic dependencies --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 38d31607..1972d35b 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ "backo2": "1.0.2" }, "devDependencies": { - "babel-core": "^6.4.5", - "babel-loader": "^6.2.1", - "babel-preset-es2015": "^6.3.13", - "babel-preset-react": "^6.3.13", + "babel-core": "6.4.5", + "babel-loader": "6.2.1", + "babel-preset-es2015": "6.3.13", + "babel-preset-react": "6.3.13", "babelify": "7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", @@ -41,6 +41,7 @@ "gulp-file": "0.2.0", "gulp-istanbul": "0.10.3", "gulp-mocha": "2.2.0", + "gulp-task-listing": "1.0.1", "has-cors": "1.1.0", "istanbul": "0.4.2", "mocha": "2.3.4", From eb50b6c3d1a36135039094c0a3c1c35bc03424a4 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 3 Feb 2016 17:58:11 +0800 Subject: [PATCH 20/44] standardise gulpfile formatting and conventions --- .gitignore | 1 + gulpfile.js | 127 +++++++++++++++++++++++++++++----------------------- 2 files changed, 72 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 7bbe1a3f..cb5d6b14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules /coverage +/.idea \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index a071d503..9d1301d4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,20 +1,32 @@ -var gulp = require('gulp'); -var mocha = require('gulp-mocha'); -var file = require('gulp-file'); -var istanbul = require('gulp-istanbul'); -var webpack = require('webpack-stream'); -var exec = require('child_process').exec; +const gulp = require('gulp'); +const mocha = require('gulp-mocha'); +const file = require('gulp-file'); +const istanbul = require('gulp-istanbul'); +const webpack = require('webpack-stream'); +const child = require('child_process'); +const help = require("gulp-task-listing"); -var browserify = require('./support/browserify.js'); +gulp.task('help', help); -gulp.task('build-webpack', function() { - return gulp.src('lib/*.js') +gulp.task('default', ['build']); + +//////////////////////////////////////// +// BUILDING +//////////////////////////////////////// + +const BUILD_TARGET_FILENAME = 'socket.io.js'; +const BUILD_TARGET_DIR = './'; + +gulp.task('build', ['webpack']); + +gulp.task('webpack', function() { + return gulp.src('lib/*.js') .pipe(webpack({ entry: './lib/index.js', output: { library: 'io', libraryTarget: 'umd', - filename: 'socket.io.js', + filename: BUILD_TARGET_FILENAME }, externals: { 'global': glob() @@ -23,68 +35,70 @@ gulp.task('build-webpack', function() { loaders: [{ test: /\.(js|jsx)?$/, exclude: /(node_modules|bower_components)/, - loader: 'babel', // 'babel-loader' is also a legal name to reference + loader: 'babel', // 'babel-loader' is also a legal name to reference query: { presets: ['react', 'es2015'] } }] } })) - .pipe(gulp.dest('./')); + .pipe(gulp.dest(BUILD_TARGET_DIR)); }); -gulp.task('build', function(){ - browserify(function(err, out){ - if(err){ - throw err; - }else{ - gulp.src('') - .pipe(file('socket.io.js', out)) - .pipe(gulp.dest('./')); - } - }); -}); -gulp.task('test', [process.env.BROWSER_NAME ? 'test-zuul' : 'test-node'], function(){ -}); +//////////////////////////////////////// +// TESTING +//////////////////////////////////////// -gulp.task('test-zuul', function(){ - if(process.env.BROWSER_PLATFORM){ - exec('./node_modules/zuul/bin/zuul ' + - '--browser-name ' + process.env.BROWSER_NAME + ' ' + - '--browser-version ' + process.env.BROWSER_VERSION + ' ' + - '--browser-platform ' +process.env.BROWSER_PLATFORM + ' ' + - 'test/index.js', - function(err, stdout, stderr){ - console.log(stdout); - console.error(stderr); - }); - }else{ - exec('./node_modules/zuul/bin/zuul ' + - '--browser-name ' + process.env.BROWSER_NAME + ' ' + - '--browser-version ' + process.env.BROWSER_VERSION + ' ' + - 'test/index.js', - function(err, stdout, stderr){ - console.log(stdout); - console.error(stderr); - }); +const REPORTER = 'dot'; +const TEST_FILE = "./test/index.js"; +const TEST_SUPPORT_SERVER_FILE = "./test/support/server.js"; + +gulp.task('test', function() { + if (process.env.hasOwnProperty("BROWSER_NAME")) { + return testZuul(); + } else { + return testNode(); } }); -gulp.task('test-node', function(){ - gulp.src(['test/*.js', 'test/support/*.js']) - .pipe(mocha({ - reporter: 'dot', - bail: true - })) - .once('error', function (err) { +gulp.task('test-node', testNode); +gulp.task('test-zuul', testZuul); + +// runs zuul through shell process +function testZuul() { + const ZUUL_CMD = "./node_modules/zuul/bin/zuul"; + const args = [ + "--browser-name", + process.env.BROWSER_NAME, + "--browser-version", + process.env.BROWSER_VERSION + ]; + if (process.env.hasOwnProperty("BROWSER_PLATFORM")) { + args.push("--browser-platform"); + args.push(process.env.BROWSER_PLATFORM); + } + args.push(TEST_FILE); + return child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); +} + +function testNode() { + const MOCHA_OPTS = { + reporter: REPORTER, + require: [TEST_SUPPORT_SERVER_FILE], + bail: true + }; + return gulp.src(TEST_FILE, { read: false }) + .pipe(mocha(MOCHA_OPTS)) + // following lines to fix gulp-mocha not terminating (see gulp-mocha webpage) + .once("error", function(err) { console.error(err.stack); process.exit(1); }) - .once('end', function () { + .once("end", function() { process.exit(); }); -}); +} gulp.task('istanbul-pre-test', function () { return gulp.src(['lib/**/*.js']) @@ -97,10 +111,11 @@ gulp.task('istanbul-pre-test', function () { gulp.task('test-cov', ['istanbul-pre-test'], function(){ gulp.src(['test/*.js', 'test/support/*.js']) .pipe(mocha({ - reporter: 'dot' + reporter: REPORTER })) .pipe(istanbul.writeReports()) - .once('error', function (){ + .once('error', function (err){ + console.error(err); process.exit(1); }) .once('end', function (){ From 8c86b10e0cd978e7ea185277894b409aee277e71 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 3 Feb 2016 18:42:47 +0800 Subject: [PATCH 21/44] removed babelify dep --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 1972d35b..40ce4978 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "babel-loader": "6.2.1", "babel-preset-es2015": "6.3.13", "babel-preset-react": "6.3.13", - "babelify": "7.2.0", "base64-arraybuffer": "0.1.5", "browserify": "13.0.0", "concat-stream": "1.5.1", From 6c2e1c121eede89b913574cb0b0154513ca8d8db Mon Sep 17 00:00:00 2001 From: Yijin Date: Thu, 4 Feb 2016 19:21:03 +0800 Subject: [PATCH 22/44] added error code capturing for zuul child process --- gulpfile.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 9d1301d4..0af9dd40 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -79,7 +79,9 @@ function testZuul() { args.push(process.env.BROWSER_PLATFORM); } args.push(TEST_FILE); - return child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); + const zuulChield = child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); + zuulChild.on("exit", function (code) { process.exit(code); }); + return zuulChild; } function testNode() { From 97f8391f2da64b7446800013300b52849c560c99 Mon Sep 17 00:00:00 2001 From: Yijin Date: Thu, 4 Feb 2016 19:31:49 +0800 Subject: [PATCH 23/44] fix typo --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 0af9dd40..e2932703 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -79,7 +79,7 @@ function testZuul() { args.push(process.env.BROWSER_PLATFORM); } args.push(TEST_FILE); - const zuulChield = child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); + const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); zuulChild.on("exit", function (code) { process.exit(code); }); return zuulChild; } From 8e55f02c3fbd6abeb6daa476c4452f8ace6a5b82 Mon Sep 17 00:00:00 2001 From: Yijin Date: Thu, 4 Feb 2016 20:56:07 +0800 Subject: [PATCH 24/44] trigger travis rebuild --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index e2932703..c3d65270 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -135,4 +135,4 @@ function glob(){ return 'typeof self !== "undefined" ? self : ' + 'typeof window !== "undefined" ? window : ' + 'typeof global !== "undefined" ? global : {}'; -} +} \ No newline at end of file From 2b18f9fbf17ed779cdc43ef9bfcc523f2fe1b239 Mon Sep 17 00:00:00 2001 From: Yijin Date: Tue, 9 Feb 2016 17:49:49 +0800 Subject: [PATCH 25/44] updated makefile to use gulp commands --- Makefile | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 54fc2ff8..5be3ee95 100644 --- a/Makefile +++ b/Makefile @@ -4,34 +4,39 @@ REPORTER = dot build: socket.io.js socket.io.js: lib/*.js package.json - @./support/browserify.sh > socket.io.js + gulp + # @./support/browserify.sh > socket.io.js test: - @if [ "x$(BROWSER_NAME)" = "x" ]; then make test-node; else make test-zuul; fi + gulp test + # @if [ "x$(BROWSER_NAME)" = "x" ]; then make test-node; else make test-zuul; fi test-node: - @./node_modules/.bin/mocha \ - --reporter $(REPORTER) \ - --require test/support/server.js \ - test/index.js + gulp test-node + # @./node_modules/.bin/mocha \ + # --reporter $(REPORTER) \ + # --require test/support/server.js \ + # test/index.js test-zuul: - @if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \ - ./node_modules/zuul/bin/zuul \ - --browser-name $(BROWSER_NAME) \ - --browser-version $(BROWSER_VERSION) \ - test/index.js; \ - else \ - ./node_modules/zuul/bin/zuul \ - --browser-name $(BROWSER_NAME) \ - --browser-version $(BROWSER_VERSION) \ - --browser-platform "$(BROWSER_PLATFORM)" \ - test/index.js; \ - fi + gulp test-zuul + # @if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \ + # ./node_modules/zuul/bin/zuul \ + # --browser-name $(BROWSER_NAME) \ + # --browser-version $(BROWSER_VERSION) \ + # test/index.js; \ + # else \ + # ./node_modules/zuul/bin/zuul \ + # --browser-name $(BROWSER_NAME) \ + # --browser-version $(BROWSER_VERSION) \ + # --browser-platform "$(BROWSER_PLATFORM)" \ + # test/index.js; \ + # fi test-cov: - @./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \ - --reporter $(REPORTER) \ - test/ + gulp test-cov + # @./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \ + # --reporter $(REPORTER) \ + # test/ .PHONY: test From b7eeee7e7d30613a72a490db9b8b9924916e28d6 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 10 Feb 2016 12:05:24 +0800 Subject: [PATCH 26/44] removed ide-specific entries from gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cb5d6b14..b1bc6fe4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /node_modules -/coverage -/.idea \ No newline at end of file +/coverage \ No newline at end of file From ec06f7a6c386a6c26feccb546fe309b1dbee232c Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Wed, 10 Feb 2016 23:41:27 +0800 Subject: [PATCH 27/44] Refactor webpack config out to support/webpack.config.js --- gulpfile.js | 35 +---------------------------------- support/webpack.config.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 support/webpack.config.js diff --git a/gulpfile.js b/gulpfile.js index c3d65270..205172a1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,34 +14,13 @@ gulp.task('default', ['build']); // BUILDING //////////////////////////////////////// -const BUILD_TARGET_FILENAME = 'socket.io.js'; const BUILD_TARGET_DIR = './'; gulp.task('build', ['webpack']); gulp.task('webpack', function() { return gulp.src('lib/*.js') - .pipe(webpack({ - entry: './lib/index.js', - output: { - library: 'io', - libraryTarget: 'umd', - filename: BUILD_TARGET_FILENAME - }, - externals: { - 'global': glob() - }, - module: { - loaders: [{ - test: /\.(js|jsx)?$/, - exclude: /(node_modules|bower_components)/, - loader: 'babel', // 'babel-loader' is also a legal name to reference - query: { - presets: ['react', 'es2015'] - } - }] - } - })) + .pipe(webpack(require('./support/webpack.config.js'))) .pipe(gulp.dest(BUILD_TARGET_DIR)); }); @@ -124,15 +103,3 @@ gulp.task('test-cov', ['istanbul-pre-test'], function(){ process.exit(); }); }); - -/** - * Populates `global`. - * - * @api private - */ - -function glob(){ - return 'typeof self !== "undefined" ? self : ' - + 'typeof window !== "undefined" ? window : ' - + 'typeof global !== "undefined" ? global : {}'; -} \ No newline at end of file diff --git a/support/webpack.config.js b/support/webpack.config.js new file mode 100644 index 00000000..0756108f --- /dev/null +++ b/support/webpack.config.js @@ -0,0 +1,34 @@ + +module.exports = { + entry: './lib/index.js', + output: { + library: 'io', + libraryTarget: 'umd', + filename: 'socket.io.js' + }, + externals: { + global: glob() + }, + module: { + loaders: [{ + test: /\.(js|jsx)?$/, + exclude: /(node_modules|bower_components)/, + loader: 'babel', // 'babel-loader' is also a legal name to reference + query: { + presets: ['react', 'es2015'] + } + }] + } +}; + +/** + * Populates `global`. + * + * @api private + */ + +function glob(){ + return 'typeof self !== "undefined" ? self : ' + + 'typeof window !== "undefined" ? window : ' + + 'typeof global !== "undefined" ? global : {}'; +} From c4b7820cf1d96306248edb2d26ea7661e005394b Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Wed, 10 Feb 2016 23:43:05 +0800 Subject: [PATCH 28/44] Migrate zuul config from yml to js --- .zuul.yml | 8 -------- zuul.config.js | 12 ++++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) delete mode 100644 .zuul.yml create mode 100644 zuul.config.js diff --git a/.zuul.yml b/.zuul.yml deleted file mode 100644 index f4e5a977..00000000 --- a/.zuul.yml +++ /dev/null @@ -1,8 +0,0 @@ -ui: mocha-bdd -server: ./test/support/server.js -browserify: - - exclude: ws -tunnel: - type: ngrok - authtoken: 6Aw8vTgcG5EvXdQywVvbh_3fMxvd4Q7dcL2caAHAFjV - proto: tcp diff --git a/zuul.config.js b/zuul.config.js new file mode 100644 index 00000000..df894211 --- /dev/null +++ b/zuul.config.js @@ -0,0 +1,12 @@ + +module.exports = { + ui: 'mocha-bdd', + server: './test/support/server.js', + tunnel: { + type: 'ngrok', + authtoken: '6Aw8vTgcG5EvXdQywVvbh_3fMxvd4Q7dcL2caAHAFjV', + proto: 'tcp' + }, + builder: 'zuul-builder-webpack', + webpack: require('./support/webpack.config.js') +}; From 422f29ebf6115eb8b9407e713ae391007c2dcc81 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Wed, 10 Feb 2016 23:44:08 +0800 Subject: [PATCH 29/44] Remove browserify stuff, add zuul-builder-webpack devDep --- .gitignore | 2 +- package.json | 2 +- support/browserify.js | 55 ------------------------------------------- support/browserify.sh | 6 ----- 4 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 support/browserify.js delete mode 100755 support/browserify.sh diff --git a/.gitignore b/.gitignore index b1bc6fe4..7bbe1a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /node_modules -/coverage \ No newline at end of file +/coverage diff --git a/package.json b/package.json index 40ce4978..f0c831fd 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "babel-preset-es2015": "6.3.13", "babel-preset-react": "6.3.13", "base64-arraybuffer": "0.1.5", - "browserify": "13.0.0", "concat-stream": "1.5.1", "derequire": "2.0.3", "expect.js": "0.3.1", @@ -49,6 +48,7 @@ "uglify-js": "2.6.1", "webpack-stream": "3.1.0", "zuul": "3.9.0", + "zuul-builder-webpack": "1.1.0", "zuul-ngrok": "3.2.0" }, "scripts": { diff --git a/support/browserify.js b/support/browserify.js deleted file mode 100644 index fa0ad014..00000000 --- a/support/browserify.js +++ /dev/null @@ -1,55 +0,0 @@ - -/** - * Module dependencies. - */ - -var browserify = require('browserify'); -var concat = require('concat-stream'); -var derequire = require('derequire'); -var path = require.resolve('../'); -var babelify = require("babelify"); - -/** - * Module exports. - */ - -module.exports = build; - -/** - * Make the build. - * - * @api public - */ - - -function build(fn){ - var bundle = browserify({ - builtins: false, - entries: [ path ], - insertGlobalVars: { global: glob }, - standalone: 'io' - }) - .exclude('ws') - .transform(babelify) - .bundle(); - - bundle.on('error', function (err) { - fn(err); - }); - - bundle.pipe(concat({ encoding: 'string' }, function (out) { - fn(null, derequire(out)); - })); -} - -/** - * Populates `global`. - * - * @api private - */ - -function glob(){ - return 'typeof self !== "undefined" ? self : ' - + 'typeof window !== "undefined" ? window : ' - + 'typeof global !== "undefined" ? global : {}'; -} diff --git a/support/browserify.sh b/support/browserify.sh deleted file mode 100755 index 0ea6a6ad..00000000 --- a/support/browserify.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env node - -require('./browserify')(function(err, out){ - if (err) throw err; - console.log(out); -}); From 18d6873c649da0592354f033f03832574fcf55b4 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Thu, 11 Feb 2016 00:10:00 +0800 Subject: [PATCH 30/44] Makefile use gulp from node_modules instead of global --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5be3ee95..4fc9c763 100644 --- a/Makefile +++ b/Makefile @@ -4,22 +4,22 @@ REPORTER = dot build: socket.io.js socket.io.js: lib/*.js package.json - gulp + @./node_modules/.bin/gulp # @./support/browserify.sh > socket.io.js test: - gulp test + @./node_modules/.bin/gulp test # @if [ "x$(BROWSER_NAME)" = "x" ]; then make test-node; else make test-zuul; fi test-node: - gulp test-node + @./node_modules/.bin/gulp test-node # @./node_modules/.bin/mocha \ # --reporter $(REPORTER) \ # --require test/support/server.js \ # test/index.js test-zuul: - gulp test-zuul + @./node_modules/.bin/gulp test-zuul # @if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \ # ./node_modules/zuul/bin/zuul \ # --browser-name $(BROWSER_NAME) \ @@ -34,7 +34,7 @@ test-zuul: # fi test-cov: - gulp test-cov + @./node_modules/.bin/gulp test-cov # @./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \ # --reporter $(REPORTER) \ # test/ From 60fa83c345ac678fdba29c910d49d94cbc91d68d Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Fri, 12 Feb 2016 13:24:15 +0800 Subject: [PATCH 31/44] removed babel react preset --- package.json | 1 - support/webpack.config.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f0c831fd..e221fa57 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "babel-core": "6.4.5", "babel-loader": "6.2.1", "babel-preset-es2015": "6.3.13", - "babel-preset-react": "6.3.13", "base64-arraybuffer": "0.1.5", "concat-stream": "1.5.1", "derequire": "2.0.3", diff --git a/support/webpack.config.js b/support/webpack.config.js index 0756108f..2e566ded 100644 --- a/support/webpack.config.js +++ b/support/webpack.config.js @@ -11,11 +11,11 @@ module.exports = { }, module: { loaders: [{ - test: /\.(js|jsx)?$/, + test: /\.js?$/, exclude: /(node_modules|bower_components)/, loader: 'babel', // 'babel-loader' is also a legal name to reference query: { - presets: ['react', 'es2015'] + presets: ['es2015'] } }] } From 49619d99654c7f94afe28137a5383f57835d7472 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Fri, 12 Feb 2016 20:13:27 +0800 Subject: [PATCH 32/44] Remove commented make recipe --- Makefile | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Makefile b/Makefile index 4fc9c763..f4f139c9 100644 --- a/Makefile +++ b/Makefile @@ -5,38 +5,17 @@ build: socket.io.js socket.io.js: lib/*.js package.json @./node_modules/.bin/gulp - # @./support/browserify.sh > socket.io.js test: @./node_modules/.bin/gulp test - # @if [ "x$(BROWSER_NAME)" = "x" ]; then make test-node; else make test-zuul; fi test-node: @./node_modules/.bin/gulp test-node - # @./node_modules/.bin/mocha \ - # --reporter $(REPORTER) \ - # --require test/support/server.js \ - # test/index.js test-zuul: @./node_modules/.bin/gulp test-zuul - # @if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \ - # ./node_modules/zuul/bin/zuul \ - # --browser-name $(BROWSER_NAME) \ - # --browser-version $(BROWSER_VERSION) \ - # test/index.js; \ - # else \ - # ./node_modules/zuul/bin/zuul \ - # --browser-name $(BROWSER_NAME) \ - # --browser-version $(BROWSER_VERSION) \ - # --browser-platform "$(BROWSER_PLATFORM)" \ - # test/index.js; \ - # fi test-cov: @./node_modules/.bin/gulp test-cov - # @./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \ - # --reporter $(REPORTER) \ - # test/ .PHONY: test From c7deec13cb32dfd6042f3c2f730d31a715c28a55 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Fri, 12 Feb 2016 20:13:58 +0800 Subject: [PATCH 33/44] Rename gulp task webpack to build --- gulpfile.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 205172a1..1b3093cd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,9 +16,7 @@ gulp.task('default', ['build']); const BUILD_TARGET_DIR = './'; -gulp.task('build', ['webpack']); - -gulp.task('webpack', function() { +gulp.task('build', function() { return gulp.src('lib/*.js') .pipe(webpack(require('./support/webpack.config.js'))) .pipe(gulp.dest(BUILD_TARGET_DIR)); From 8725d6e5cb571fdc8f460fad62c089edb07c049b Mon Sep 17 00:00:00 2001 From: Zhu Liang Date: Mon, 15 Feb 2016 13:34:25 +0800 Subject: [PATCH 34/44] fixed regex --- support/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/webpack.config.js b/support/webpack.config.js index 2e566ded..7ae2077e 100644 --- a/support/webpack.config.js +++ b/support/webpack.config.js @@ -11,7 +11,7 @@ module.exports = { }, module: { loaders: [{ - test: /\.js?$/, + test: /\.js$/, exclude: /(node_modules|bower_components)/, loader: 'babel', // 'babel-loader' is also a legal name to reference query: { From 280d803d46a1b01499bbd4943d5ef7bc11622326 Mon Sep 17 00:00:00 2001 From: Michael Limantara Date: Sun, 31 Jan 2016 16:57:14 +0800 Subject: [PATCH 35/44] Add eslint to gulpfile and create gulp task default --- .eslintrc.json | 11 +++++++++++ gulpfile.js | 8 +++++++- package.json | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..93ede1f8 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "extends": "standard", + "parser": "babel-eslint", + "rules": { + "yoda": 0, + "semi": [2, "always"], + "no-extra-semi": 2, + "semi-spacing": [2, { "before": false, "after": true }] + } + } + \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 1b3093cd..d2e68e5c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,10 +5,11 @@ const istanbul = require('gulp-istanbul'); const webpack = require('webpack-stream'); const child = require('child_process'); const help = require("gulp-task-listing"); +var eslint = require('gulp-eslint'); gulp.task('help', help); -gulp.task('default', ['build']); +gulp.task('default', ['lint', 'build']); //////////////////////////////////////// // BUILDING @@ -22,6 +23,11 @@ gulp.task('build', function() { .pipe(gulp.dest(BUILD_TARGET_DIR)); }); +gulp.task('lint', function() { + return gulp.src(['**/*.js', '!node_modules/**']) + .pipe(eslint()) + .pipe(eslint.format()); +}); //////////////////////////////////////// // TESTING diff --git a/package.json b/package.json index 8ae91db3..bd221453 100644 --- a/package.json +++ b/package.json @@ -28,13 +28,17 @@ }, "devDependencies": { "babel-core": "6.4.5", + "babel-eslint": "4.1.6", "babel-loader": "6.2.1", "babel-preset-es2015": "6.3.13", "base64-arraybuffer": "0.1.5", "concat-stream": "1.5.1", "derequire": "2.0.3", + "eslint-config-standard": "4.4.0", + "eslint-plugin-standard": "1.3.1", "expect.js": "0.3.1", "gulp": "3.9.0", + "gulp-eslint": "1.1.1", "gulp-file": "0.2.0", "gulp-istanbul": "0.10.3", "gulp-mocha": "2.2.0", From 9e443a90e26a039c32e11d6fb94e54766bb9e5f5 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 3 Feb 2016 18:30:42 +0800 Subject: [PATCH 36/44] refactor gulpfile --- gulpfile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d2e68e5c..b1549e7f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ const istanbul = require('gulp-istanbul'); const webpack = require('webpack-stream'); const child = require('child_process'); const help = require("gulp-task-listing"); -var eslint = require('gulp-eslint'); +const eslint = require('gulp-eslint'); gulp.task('help', help); @@ -26,7 +26,8 @@ gulp.task('build', function() { gulp.task('lint', function() { return gulp.src(['**/*.js', '!node_modules/**']) .pipe(eslint()) - .pipe(eslint.format()); + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); }); //////////////////////////////////////// From 537e4cd665c0f15edb34cfe7776cfa05755dee75 Mon Sep 17 00:00:00 2001 From: Yijin Date: Wed, 3 Feb 2016 18:38:40 +0800 Subject: [PATCH 37/44] updated babel-eslint dep to 4.1.7 (4.1.6 broken) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd221453..ee348196 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "devDependencies": { "babel-core": "6.4.5", - "babel-eslint": "4.1.6", + "babel-eslint": "4.1.7", "babel-loader": "6.2.1", "babel-preset-es2015": "6.3.13", "base64-arraybuffer": "0.1.5", From c0d8e30b8a6c8ad7d55b32c6e539b0c6d4ca21e3 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Sat, 27 Feb 2016 16:25:54 +0800 Subject: [PATCH 38/44] Exclude generated files from linting - coverage/ - socket.io.js bundle --- gulpfile.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index b1549e7f..d0eb2819 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,7 +24,12 @@ gulp.task('build', function() { }); gulp.task('lint', function() { - return gulp.src(['**/*.js', '!node_modules/**']) + return gulp.src([ + '**/*.js', + '!node_modules/**', + '!coverage/**', + '!socket.io.js' + ]) .pipe(eslint()) .pipe(eslint.format()) .pipe(eslint.failAfterError()); From 51ad3c1ee0d9c26bedd4b9abc0e60b8528cafb2b Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Sat, 27 Feb 2016 20:57:48 +0800 Subject: [PATCH 39/44] Add env to eslintrc - node env at root eslintrc - mocha env at test/ eslintrc --- .eslintrc.json | 23 +++++++++++++---------- test/.eslintrc.json | 6 ++++++ 2 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 test/.eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json index 93ede1f8..1e8ee731 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,14 @@ { - "extends": "standard", - "parser": "babel-eslint", - "rules": { - "yoda": 0, - "semi": [2, "always"], - "no-extra-semi": 2, - "semi-spacing": [2, { "before": false, "after": true }] - } - } - \ No newline at end of file + "extends": "standard", + "parser": "babel-eslint", + "env": { + // Note: mocha env is defined inside test/.eslintrc.json + "node": true + }, + "rules": { + "yoda": 0, + "semi": [2, "always"], + "no-extra-semi": 2, + "semi-spacing": [2, { "before": false, "after": true }] + } +} diff --git a/test/.eslintrc.json b/test/.eslintrc.json new file mode 100644 index 00000000..8a30ebae --- /dev/null +++ b/test/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "env": { + "node": true, + "mocha": true + } +} From d1cbc68ea7c945b8b636326a20c9a0457e8a46ab Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Sat, 27 Feb 2016 20:59:44 +0800 Subject: [PATCH 40/44] Eslint autofix --- gulpfile.js | 42 +++---- lib/index.js | 4 +- lib/manager.js | 76 ++++++------- lib/on.js | 4 +- lib/socket.js | 48 ++++---- lib/url.js | 12 +- support/webpack.config.js | 2 +- test/connection.js | 224 +++++++++++++++++++------------------- test/socket.js | 46 ++++---- test/support/server.js | 50 ++++----- test/url.js | 18 +-- 11 files changed, 263 insertions(+), 263 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d0eb2819..d43af2f0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,7 +4,7 @@ const file = require('gulp-file'); const istanbul = require('gulp-istanbul'); const webpack = require('webpack-stream'); const child = require('child_process'); -const help = require("gulp-task-listing"); +const help = require('gulp-task-listing'); const eslint = require('gulp-eslint'); gulp.task('help', help); @@ -17,13 +17,13 @@ gulp.task('default', ['lint', 'build']); const BUILD_TARGET_DIR = './'; -gulp.task('build', function() { +gulp.task('build', function () { return gulp.src('lib/*.js') .pipe(webpack(require('./support/webpack.config.js'))) .pipe(gulp.dest(BUILD_TARGET_DIR)); }); -gulp.task('lint', function() { +gulp.task('lint', function () { return gulp.src([ '**/*.js', '!node_modules/**', @@ -40,11 +40,11 @@ gulp.task('lint', function() { //////////////////////////////////////// const REPORTER = 'dot'; -const TEST_FILE = "./test/index.js"; -const TEST_SUPPORT_SERVER_FILE = "./test/support/server.js"; +const TEST_FILE = './test/index.js'; +const TEST_SUPPORT_SERVER_FILE = './test/support/server.js'; -gulp.task('test', function() { - if (process.env.hasOwnProperty("BROWSER_NAME")) { +gulp.task('test', function () { + if (process.env.hasOwnProperty('BROWSER_NAME')) { return testZuul(); } else { return testNode(); @@ -55,25 +55,25 @@ gulp.task('test-node', testNode); gulp.task('test-zuul', testZuul); // runs zuul through shell process -function testZuul() { - const ZUUL_CMD = "./node_modules/zuul/bin/zuul"; +function testZuul () { + const ZUUL_CMD = './node_modules/zuul/bin/zuul'; const args = [ - "--browser-name", + '--browser-name', process.env.BROWSER_NAME, - "--browser-version", + '--browser-version', process.env.BROWSER_VERSION ]; - if (process.env.hasOwnProperty("BROWSER_PLATFORM")) { - args.push("--browser-platform"); + if (process.env.hasOwnProperty('BROWSER_PLATFORM')) { + args.push('--browser-platform'); args.push(process.env.BROWSER_PLATFORM); } args.push(TEST_FILE); - const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); - zuulChild.on("exit", function (code) { process.exit(code); }); + const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: 'inherit' }); + zuulChild.on('exit', function (code) { process.exit(code); }); return zuulChild; } -function testNode() { +function testNode () { const MOCHA_OPTS = { reporter: REPORTER, require: [TEST_SUPPORT_SERVER_FILE], @@ -82,11 +82,11 @@ function testNode() { return gulp.src(TEST_FILE, { read: false }) .pipe(mocha(MOCHA_OPTS)) // following lines to fix gulp-mocha not terminating (see gulp-mocha webpage) - .once("error", function(err) { + .once('error', function (err) { console.error(err.stack); process.exit(1); }) - .once("end", function() { + .once('end', function () { process.exit(); }); } @@ -99,17 +99,17 @@ gulp.task('istanbul-pre-test', function () { .pipe(istanbul.hookRequire()); }); -gulp.task('test-cov', ['istanbul-pre-test'], function(){ +gulp.task('test-cov', ['istanbul-pre-test'], function () { gulp.src(['test/*.js', 'test/support/*.js']) .pipe(mocha({ reporter: REPORTER })) .pipe(istanbul.writeReports()) - .once('error', function (err){ + .once('error', function (err) { console.error(err); process.exit(1); }) - .once('end', function (){ + .once('end', function () { process.exit(); }); }); diff --git a/lib/index.js b/lib/index.js index 91887e4e..6f128ceb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,8 +33,8 @@ var cache = exports.managers = {}; * @api public */ -function lookup(uri, opts) { - if (typeof uri == 'object') { +function lookup (uri, opts) { + if (typeof uri === 'object') { opts = uri; uri = undefined; } diff --git a/lib/manager.js b/lib/manager.js index 5d7f88c6..ae22ffc4 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -33,9 +33,9 @@ module.exports = Manager; * @api public */ -function Manager(uri, opts){ +function Manager (uri, opts) { if (!(this instanceof Manager)) return new Manager(uri, opts); - if (uri && ('object' == typeof uri)) { + if (uri && ('object' === typeof uri)) { opts = uri; uri = undefined; } @@ -74,7 +74,7 @@ function Manager(uri, opts){ * @api private */ -Manager.prototype.emitAll = function() { +Manager.prototype.emitAll = function () { this.emit.apply(this, arguments); for (var nsp in this.nsps) { if (has.call(this.nsps, nsp)) { @@ -89,7 +89,7 @@ Manager.prototype.emitAll = function() { * @api private */ -Manager.prototype.updateSocketIds = function(){ +Manager.prototype.updateSocketIds = function () { for (var nsp in this.nsps) { if (has.call(this.nsps, nsp)) { this.nsps[nsp].id = this.engine.id; @@ -111,7 +111,7 @@ Emitter(Manager.prototype); * @api public */ -Manager.prototype.reconnection = function(v){ +Manager.prototype.reconnection = function (v) { if (!arguments.length) return this._reconnection; this._reconnection = !!v; return this; @@ -125,7 +125,7 @@ Manager.prototype.reconnection = function(v){ * @api public */ -Manager.prototype.reconnectionAttempts = function(v){ +Manager.prototype.reconnectionAttempts = function (v) { if (!arguments.length) return this._reconnectionAttempts; this._reconnectionAttempts = v; return this; @@ -139,14 +139,14 @@ Manager.prototype.reconnectionAttempts = function(v){ * @api public */ -Manager.prototype.reconnectionDelay = function(v){ +Manager.prototype.reconnectionDelay = function (v) { if (!arguments.length) return this._reconnectionDelay; this._reconnectionDelay = v; this.backoff && this.backoff.setMin(v); return this; }; -Manager.prototype.randomizationFactor = function(v){ +Manager.prototype.randomizationFactor = function (v) { if (!arguments.length) return this._randomizationFactor; this._randomizationFactor = v; this.backoff && this.backoff.setJitter(v); @@ -161,7 +161,7 @@ Manager.prototype.randomizationFactor = function(v){ * @api public */ -Manager.prototype.reconnectionDelayMax = function(v){ +Manager.prototype.reconnectionDelayMax = function (v) { if (!arguments.length) return this._reconnectionDelayMax; this._reconnectionDelayMax = v; this.backoff && this.backoff.setMax(v); @@ -175,7 +175,7 @@ Manager.prototype.reconnectionDelayMax = function(v){ * @api public */ -Manager.prototype.timeout = function(v){ +Manager.prototype.timeout = function (v) { if (!arguments.length) return this._timeout; this._timeout = v; return this; @@ -188,7 +188,7 @@ Manager.prototype.timeout = function(v){ * @api private */ -Manager.prototype.maybeReconnectOnOpen = function() { +Manager.prototype.maybeReconnectOnOpen = function () { // Only try to reconnect if it's the first time we're connecting if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) { // keeps reconnection from firing twice for the same reconnection loop @@ -206,7 +206,7 @@ Manager.prototype.maybeReconnectOnOpen = function() { */ Manager.prototype.open = -Manager.prototype.connect = function(fn){ +Manager.prototype.connect = function (fn) { debug('readyState %s', this.readyState); if (~this.readyState.indexOf('open')) return this; @@ -218,13 +218,13 @@ Manager.prototype.connect = function(fn){ this.skipReconnect = false; // emit `open` - var openSub = on(socket, 'open', function() { + var openSub = on(socket, 'open', function () { self.onopen(); fn && fn(); }); // emit `connect_error` - var errorSub = on(socket, 'error', function(data){ + var errorSub = on(socket, 'error', function (data) { debug('connect_error'); self.cleanup(); self.readyState = 'closed'; @@ -245,7 +245,7 @@ Manager.prototype.connect = function(fn){ debug('connect attempt will timeout after %d', timeout); // set timer - var timer = setTimeout(function(){ + var timer = setTimeout(function () { debug('connect attempt timed out after %d', timeout); openSub.destroy(); socket.close(); @@ -254,7 +254,7 @@ Manager.prototype.connect = function(fn){ }, timeout); this.subs.push({ - destroy: function(){ + destroy: function () { clearTimeout(timer); } }); @@ -272,7 +272,7 @@ Manager.prototype.connect = function(fn){ * @api private */ -Manager.prototype.onopen = function(){ +Manager.prototype.onopen = function () { debug('open'); // clear old subs @@ -298,7 +298,7 @@ Manager.prototype.onopen = function(){ * @api private */ -Manager.prototype.onping = function(){ +Manager.prototype.onping = function () { this.lastPing = new Date; this.emitAll('ping'); }; @@ -309,7 +309,7 @@ Manager.prototype.onping = function(){ * @api private */ -Manager.prototype.onpong = function(){ +Manager.prototype.onpong = function () { this.emitAll('pong', new Date - this.lastPing); }; @@ -319,7 +319,7 @@ Manager.prototype.onpong = function(){ * @api private */ -Manager.prototype.ondata = function(data){ +Manager.prototype.ondata = function (data) { this.decoder.add(data); }; @@ -329,7 +329,7 @@ Manager.prototype.ondata = function(data){ * @api private */ -Manager.prototype.ondecoded = function(packet) { +Manager.prototype.ondecoded = function (packet) { this.emit('packet', packet); }; @@ -339,7 +339,7 @@ Manager.prototype.ondecoded = function(packet) { * @api private */ -Manager.prototype.onerror = function(err){ +Manager.prototype.onerror = function (err) { debug('error', err); this.emitAll('error', err); }; @@ -351,14 +351,14 @@ Manager.prototype.onerror = function(err){ * @api public */ -Manager.prototype.socket = function(nsp){ +Manager.prototype.socket = function (nsp) { var socket = this.nsps[nsp]; if (!socket) { socket = new Socket(this, nsp); this.nsps[nsp] = socket; var self = this; socket.on('connecting', onConnecting); - socket.on('connect', function(){ + socket.on('connect', function () { socket.id = self.engine.id; }); @@ -368,7 +368,7 @@ Manager.prototype.socket = function(nsp){ } } - function onConnecting() { + function onConnecting () { if (!~indexOf(self.connecting, socket)) { self.connecting.push(socket); } @@ -383,7 +383,7 @@ Manager.prototype.socket = function(nsp){ * @param {Socket} socket */ -Manager.prototype.destroy = function(socket){ +Manager.prototype.destroy = function (socket) { var index = indexOf(this.connecting, socket); if (~index) this.connecting.splice(index, 1); if (this.connecting.length) return; @@ -398,14 +398,14 @@ Manager.prototype.destroy = function(socket){ * @api private */ -Manager.prototype.packet = function(packet){ +Manager.prototype.packet = function (packet) { debug('writing packet %j', packet); var self = this; if (!self.encoding) { // encode, then write to engine with result self.encoding = true; - this.encoder.encode(packet, function(encodedPackets) { + this.encoder.encode(packet, function (encodedPackets) { for (var i = 0; i < encodedPackets.length; i++) { self.engine.write(encodedPackets[i], packet.options); } @@ -424,7 +424,7 @@ Manager.prototype.packet = function(packet){ * @api private */ -Manager.prototype.processPacketQueue = function() { +Manager.prototype.processPacketQueue = function () { if (this.packetBuffer.length > 0 && !this.encoding) { var pack = this.packetBuffer.shift(); this.packet(pack); @@ -437,7 +437,7 @@ Manager.prototype.processPacketQueue = function() { * @api private */ -Manager.prototype.cleanup = function(){ +Manager.prototype.cleanup = function () { debug('cleanup'); var sub; @@ -457,11 +457,11 @@ Manager.prototype.cleanup = function(){ */ Manager.prototype.close = -Manager.prototype.disconnect = function(){ +Manager.prototype.disconnect = function () { debug('disconnect'); this.skipReconnect = true; this.reconnecting = false; - if ('opening' == this.readyState) { + if ('opening' === this.readyState) { // `onclose` will not fire because // an open event never happened this.cleanup(); @@ -477,7 +477,7 @@ Manager.prototype.disconnect = function(){ * @api private */ -Manager.prototype.onclose = function(reason){ +Manager.prototype.onclose = function (reason) { debug('onclose'); this.cleanup(); @@ -496,7 +496,7 @@ Manager.prototype.onclose = function(reason){ * @api private */ -Manager.prototype.reconnect = function(){ +Manager.prototype.reconnect = function () { if (this.reconnecting || this.skipReconnect) return this; var self = this; @@ -511,7 +511,7 @@ Manager.prototype.reconnect = function(){ debug('will wait %dms before reconnect attempt', delay); this.reconnecting = true; - var timer = setTimeout(function(){ + var timer = setTimeout(function () { if (self.skipReconnect) return; debug('attempting reconnect'); @@ -521,7 +521,7 @@ Manager.prototype.reconnect = function(){ // check again for the case socket closed in above events if (self.skipReconnect) return; - self.open(function(err){ + self.open(function (err) { if (err) { debug('reconnect attempt error'); self.reconnecting = false; @@ -535,7 +535,7 @@ Manager.prototype.reconnect = function(){ }, delay); this.subs.push({ - destroy: function(){ + destroy: function () { clearTimeout(timer); } }); @@ -548,7 +548,7 @@ Manager.prototype.reconnect = function(){ * @api private */ -Manager.prototype.onreconnect = function(){ +Manager.prototype.onreconnect = function () { var attempt = this.backoff.attempts; this.reconnecting = false; this.backoff.reset(); diff --git a/lib/on.js b/lib/on.js index 6be286d5..fad92644 100644 --- a/lib/on.js +++ b/lib/on.js @@ -14,10 +14,10 @@ module.exports = on; * @api public */ -function on(obj, ev, fn) { +function on (obj, ev, fn) { obj.on(ev, fn); return { - destroy: function(){ + destroy: function () { obj.removeListener(ev, fn); } }; diff --git a/lib/socket.js b/lib/socket.js index 6c19a0cd..dc676cee 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -52,7 +52,7 @@ var emit = Emitter.prototype.emit; * @api public */ -function Socket(io, nsp){ +function Socket (io, nsp) { this.io = io; this.nsp = nsp; this.json = this; // compat @@ -77,7 +77,7 @@ Emitter(Socket.prototype); * @api private */ -Socket.prototype.subEvents = function() { +Socket.prototype.subEvents = function () { if (this.subs) return; var io = this.io; @@ -95,12 +95,12 @@ Socket.prototype.subEvents = function() { */ Socket.prototype.open = -Socket.prototype.connect = function(){ +Socket.prototype.connect = function () { if (this.connected) return this; this.subEvents(); this.io.open(); // ensure open - if ('open' == this.io.readyState) this.onopen(); + if ('open' === this.io.readyState) this.onopen(); this.emit('connecting'); return this; }; @@ -112,7 +112,7 @@ Socket.prototype.connect = function(){ * @api public */ -Socket.prototype.send = function(){ +Socket.prototype.send = function () { var args = toArray(arguments); args.unshift('message'); this.emit.apply(this, args); @@ -128,7 +128,7 @@ Socket.prototype.send = function(){ * @api public */ -Socket.prototype.emit = function(ev){ +Socket.prototype.emit = function (ev) { if (events.hasOwnProperty(ev)) { emit.apply(this, arguments); return this; @@ -143,7 +143,7 @@ Socket.prototype.emit = function(ev){ packet.options.compress = !this.flags || false !== this.flags.compress; // event ack callback - if ('function' == typeof args[args.length - 1]) { + if ('function' === typeof args[args.length - 1]) { debug('emitting packet with ack id %d', this.ids); this.acks[this.ids] = args.pop(); packet.id = this.ids++; @@ -167,7 +167,7 @@ Socket.prototype.emit = function(ev){ * @api private */ -Socket.prototype.packet = function(packet){ +Socket.prototype.packet = function (packet) { packet.nsp = this.nsp; this.io.packet(packet); }; @@ -178,11 +178,11 @@ Socket.prototype.packet = function(packet){ * @api private */ -Socket.prototype.onopen = function(){ +Socket.prototype.onopen = function () { debug('transport is open - connecting'); // write connect packet if necessary - if ('/' != this.nsp) { + if ('/' !== this.nsp) { this.packet({ type: parser.CONNECT }); } }; @@ -194,7 +194,7 @@ Socket.prototype.onopen = function(){ * @api private */ -Socket.prototype.onclose = function(reason){ +Socket.prototype.onclose = function (reason) { debug('close (%s)', reason); this.connected = false; this.disconnected = true; @@ -209,8 +209,8 @@ Socket.prototype.onclose = function(reason){ * @api private */ -Socket.prototype.onpacket = function(packet){ - if (packet.nsp != this.nsp) return; +Socket.prototype.onpacket = function (packet) { + if (packet.nsp !== this.nsp) return; switch (packet.type) { case parser.CONNECT: @@ -250,7 +250,7 @@ Socket.prototype.onpacket = function(packet){ * @api private */ -Socket.prototype.onevent = function(packet){ +Socket.prototype.onevent = function (packet) { var args = packet.data || []; debug('emitting event %j', args); @@ -272,10 +272,10 @@ Socket.prototype.onevent = function(packet){ * @api private */ -Socket.prototype.ack = function(id){ +Socket.prototype.ack = function (id) { var self = this; var sent = false; - return function(){ + return function () { // prevent double callbacks if (sent) return; sent = true; @@ -298,9 +298,9 @@ Socket.prototype.ack = function(id){ * @api private */ -Socket.prototype.onack = function(packet){ +Socket.prototype.onack = function (packet) { var ack = this.acks[packet.id]; - if ('function' == typeof ack) { + if ('function' === typeof ack) { debug('calling ack %s with %j', packet.id, packet.data); ack.apply(this, packet.data); delete this.acks[packet.id]; @@ -315,7 +315,7 @@ Socket.prototype.onack = function(packet){ * @api private */ -Socket.prototype.onconnect = function(){ +Socket.prototype.onconnect = function () { this.connected = true; this.disconnected = false; this.emit('connect'); @@ -328,7 +328,7 @@ Socket.prototype.onconnect = function(){ * @api private */ -Socket.prototype.emitBuffered = function(){ +Socket.prototype.emitBuffered = function () { var i; for (i = 0; i < this.receiveBuffer.length; i++) { emit.apply(this, this.receiveBuffer[i]); @@ -347,7 +347,7 @@ Socket.prototype.emitBuffered = function(){ * @api private */ -Socket.prototype.ondisconnect = function(){ +Socket.prototype.ondisconnect = function () { debug('server disconnect (%s)', this.nsp); this.destroy(); this.onclose('io server disconnect'); @@ -361,7 +361,7 @@ Socket.prototype.ondisconnect = function(){ * @api private. */ -Socket.prototype.destroy = function(){ +Socket.prototype.destroy = function () { if (this.subs) { // clean subscriptions to avoid reconnections for (var i = 0; i < this.subs.length; i++) { @@ -381,7 +381,7 @@ Socket.prototype.destroy = function(){ */ Socket.prototype.close = -Socket.prototype.disconnect = function(){ +Socket.prototype.disconnect = function () { if (this.connected) { debug('performing disconnect (%s)', this.nsp); this.packet({ type: parser.DISCONNECT }); @@ -405,7 +405,7 @@ Socket.prototype.disconnect = function(){ * @api public */ -Socket.prototype.compress = function(compress){ +Socket.prototype.compress = function (compress) { this.flags = this.flags || {}; this.flags.compress = compress; return this; diff --git a/lib/url.js b/lib/url.js index dd3982bd..f72da274 100644 --- a/lib/url.js +++ b/lib/url.js @@ -21,7 +21,7 @@ module.exports = url; * @api public */ -function url(uri, loc){ +function url (uri, loc) { var obj = uri; // default to window.location @@ -29,9 +29,9 @@ function url(uri, loc){ if (null == uri) uri = loc.protocol + '//' + loc.host; // relative path support - if ('string' == typeof uri) { - if ('/' == uri.charAt(0)) { - if ('/' == uri.charAt(1)) { + if ('string' === typeof uri) { + if ('/' === uri.charAt(0)) { + if ('/' === uri.charAt(1)) { uri = loc.protocol + uri; } else { uri = loc.host + uri; @@ -40,7 +40,7 @@ function url(uri, loc){ if (!/^(https?|wss?):\/\//.test(uri)) { debug('protocol-less url %s', uri); - if ('undefined' != typeof loc) { + if ('undefined' !== typeof loc) { uri = loc.protocol + '//' + uri; } else { uri = 'https://' + uri; @@ -70,7 +70,7 @@ function url(uri, loc){ // define unique id obj.id = obj.protocol + '://' + host + ':' + obj.port; // define href - obj.href = obj.protocol + '://' + host + (loc && loc.port == obj.port ? '' : (':' + obj.port)); + obj.href = obj.protocol + '://' + host + (loc && loc.port === obj.port ? '' : (':' + obj.port)); return obj; } diff --git a/support/webpack.config.js b/support/webpack.config.js index 7ae2077e..ddc7d78c 100644 --- a/support/webpack.config.js +++ b/support/webpack.config.js @@ -27,7 +27,7 @@ module.exports = { * @api private */ -function glob(){ +function glob () { return 'typeof self !== "undefined" ? self : ' + 'typeof window !== "undefined" ? window : ' + 'typeof global !== "undefined" ? global : {}'; diff --git a/test/connection.js b/test/connection.js index 2e4df3cc..29f6b4bf 100644 --- a/test/connection.js +++ b/test/connection.js @@ -4,25 +4,25 @@ var hasCORS = require('has-cors'); var textBlobBuilder = require('text-blob-builder'); var env = require('./support/env'); -describe('connection', function() { +describe('connection', function () { this.timeout(70000); - it('should connect to localhost', function(done){ + it('should connect to localhost', function (done) { var socket = io({ forceNew: true }); socket.emit('hi'); - socket.on('hi', function(data){ + socket.on('hi', function (data) { socket.disconnect(); done(); }); }); - it('should not connect when autoConnect option set to false', function() { + it('should not connect when autoConnect option set to false', function () { var socket = io({ forceNew: true, autoConnect: false }); expect(socket.io.engine).to.not.be.ok(); socket.disconnect(); }); - it('should start two connections with same path', function(){ + it('should start two connections with same path', function () { var s1 = io('/'); var s2 = io('/'); @@ -31,7 +31,7 @@ describe('connection', function() { s2.disconnect(); }); - it('should start two connections with same path and different querystrings', function(){ + it('should start two connections with same path and different querystrings', function () { var s1 = io('/?woot'); var s2 = io('/'); @@ -40,38 +40,38 @@ describe('connection', function() { s2.disconnect(); }); - it('should work with acks', function(done){ + it('should work with acks', function (done) { var socket = io({ forceNew: true }); socket.emit('ack'); - socket.on('ack', function(fn){ + socket.on('ack', function (fn) { fn(5, { test: true }); }); - socket.on('got it', function(){ + socket.on('got it', function () { socket.disconnect(); done(); }); }); - it('should receive date with ack', function(done){ + it('should receive date with ack', function (done) { var socket = io({ forceNew: true }); - socket.emit('getAckDate', { test: true }, function(data){ - expect(data).to.be.a('string'); - socket.disconnect(); - done(); + socket.emit('getAckDate', { test: true }, function (data) { + expect(data).to.be.a('string'); + socket.disconnect(); + done(); }); }); - it('should work with false', function(done){ + it('should work with false', function (done) { var socket = io({ forceNew: true }); socket.emit('false'); - socket.on('false', function(f){ + socket.on('false', function (f) { expect(f).to.be(false); socket.disconnect(); done(); }); }); - it('should receive utf8 multibyte characters', function(done) { + it('should receive utf8 multibyte characters', function (done) { var correct = [ 'てすと', 'Я Б Г Д Ж Й', @@ -82,10 +82,10 @@ describe('connection', function() { var socket = io({ forceNew: true }); var i = 0; - socket.on('takeUtf8', function(data) { + socket.on('takeUtf8', function (data) { expect(data).to.be(correct[i]); i++; - if (i == correct.length) { + if (i === correct.length) { socket.disconnect(); done(); } @@ -93,12 +93,12 @@ describe('connection', function() { socket.emit('getUtf8'); }); - it('should connect to a namespace after connection established', function(done) { + it('should connect to a namespace after connection established', function (done) { var manager = io.Manager(); var socket = manager.socket('/'); - socket.on('connect', function(){ + socket.on('connect', function () { var foo = manager.socket('/foo'); - foo.on('connect', function(){ + foo.on('connect', function () { foo.close(); socket.close(); manager.close(); @@ -107,14 +107,14 @@ describe('connection', function() { }); }); - it('should open a new namespace after connection gets closed', function(done){ + it('should open a new namespace after connection gets closed', function (done) { var manager = io.Manager(); var socket = manager.socket('/'); - socket.on('connect', function() { + socket.on('connect', function () { socket.disconnect(); - }).on('disconnect', function() { + }).on('disconnect', function () { var foo = manager.socket('/foo'); - foo.on('connect', function() { + foo.on('connect', function () { foo.disconnect(); manager.close(); done(); @@ -122,24 +122,24 @@ describe('connection', function() { }); }); - it('should reconnect by default', function(done){ + it('should reconnect by default', function (done) { var socket = io({ forceNew: true }); - socket.io.on('reconnect', function() { + socket.io.on('reconnect', function () { socket.disconnect(); done(); }); - setTimeout(function() { + setTimeout(function () { socket.io.engine.close(); }, 500); }); - it('should reconnect manually', function(done) { + it('should reconnect manually', function (done) { var socket = io({ forceNew: true }); - socket.once('connect', function() { + socket.once('connect', function () { socket.disconnect(); - }).once('disconnect', function() { - socket.once('connect', function() { + }).once('disconnect', function () { + socket.once('connect', function () { socket.disconnect(); done(); }); @@ -147,33 +147,33 @@ describe('connection', function() { }); }); - it('should reconnect automatically after reconnecting manually', function(done){ + it('should reconnect automatically after reconnecting manually', function (done) { var socket = io({ forceNew: true }); - socket.once('connect', function() { + socket.once('connect', function () { socket.disconnect(); - }).once('disconnect', function() { - socket.on('reconnect', function() { + }).once('disconnect', function () { + socket.on('reconnect', function () { socket.disconnect(); done(); }); socket.connect(); - setTimeout(function() { + setTimeout(function () { socket.io.engine.close(); }, 500); }); }); - it('should attempt reconnects after a failed reconnect', function(done){ + it('should attempt reconnects after a failed reconnect', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 }); var socket = manager.socket('/timeout'); - socket.once('reconnect_failed', function() { + socket.once('reconnect_failed', function () { var reconnects = 0; - var reconnectCb = function() { + var reconnectCb = function () { reconnects++; }; manager.on('reconnect_attempt', reconnectCb); - manager.on('reconnect_failed', function failed() { + manager.on('reconnect_failed', function failed () { expect(reconnects).to.be(2); socket.close(); manager.close(); @@ -183,15 +183,15 @@ describe('connection', function() { }); }); - it('reconnect delay should increase every time', function(done){ + it('reconnect delay should increase every time', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 3, reconnectionDelay: 100, randomizationFactor: 0.2 }); var socket = manager.socket('/timeout'); var reconnects = 0, increasingDelay = true, startTime, prevDelay = 0; - - socket.on('connect_error', function() { + + socket.on('connect_error', function () { startTime = new Date().getTime(); }); - socket.on('reconnect_attempt', function() { + socket.on('reconnect_attempt', function () { reconnects++; var currentTime = new Date().getTime(); var delay = currentTime - startTime; @@ -201,7 +201,7 @@ describe('connection', function() { prevDelay = delay; }); - socket.on('reconnect_failed', function failed() { + socket.on('reconnect_failed', function failed () { expect(reconnects).to.be(3); expect(increasingDelay).to.be.ok(); socket.close(); @@ -210,51 +210,51 @@ describe('connection', function() { }); }); - it('reconnect event should fire in socket', function(done){ + it('reconnect event should fire in socket', function (done) { var socket = io({ forceNew: true }); - socket.on('reconnect', function() { + socket.on('reconnect', function () { socket.disconnect(); done(); }); - setTimeout(function() { + setTimeout(function () { socket.io.engine.close(); }, 500); }); - it('should not reconnect when force closed', function(done){ + it('should not reconnect when force closed', function (done) { var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 }); - socket.on('connect_error', function() { - socket.on('reconnect_attempt', function() { + socket.on('connect_error', function () { + socket.on('reconnect_attempt', function () { expect().fail(); }); socket.disconnect(); // set a timeout to let reconnection possibly fire - setTimeout(function() { + setTimeout(function () { done(); }, 500); }); }); - it('should stop reconnecting when force closed', function(done){ + it('should stop reconnecting when force closed', function (done) { var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 }); - socket.once('reconnect_attempt', function() { - socket.on('reconnect_attempt', function() { + socket.once('reconnect_attempt', function () { + socket.on('reconnect_attempt', function () { expect().fail(); }); socket.disconnect(); // set a timeout to let reconnection possibly fire - setTimeout(function() { + setTimeout(function () { done(); }, 500); }); }); - it('should reconnect after stopping reconnection', function(done){ + it('should reconnect after stopping reconnection', function (done) { var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 }); - socket.once('reconnect_attempt', function() { - socket.on('reconnect_attempt', function() { + socket.once('reconnect_attempt', function () { + socket.on('reconnect_attempt', function () { socket.disconnect(); done(); }); @@ -263,17 +263,17 @@ describe('connection', function() { }); }); - it('should stop reconnecting on a socket and keep to reconnect on another', function(done){ + it('should stop reconnecting on a socket and keep to reconnect on another', function (done) { var manager = io.Manager(); var socket1 = manager.socket('/'); var socket2 = manager.socket('/asd'); - manager.on('reconnect_attempt', function() { - socket1.on('connect', function() { + manager.on('reconnect_attempt', function () { + socket1.on('connect', function () { expect().fail(); }); - socket2.on('connect', function() { - setTimeout(function() { + socket2.on('connect', function () { + setTimeout(function () { socket2.disconnect(); manager.disconnect(); done(); @@ -282,22 +282,22 @@ describe('connection', function() { socket1.disconnect(); }); - setTimeout(function() { + setTimeout(function () { manager.engine.close(); }, 1000); }); - it('should try to reconnect twice and fail when requested two attempts with immediate timeout and reconnect enabled', function(done) { + it('should try to reconnect twice and fail when requested two attempts with immediate timeout and reconnect enabled', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 }); var socket; var reconnects = 0; - var reconnectCb = function() { + var reconnectCb = function () { reconnects++; }; manager.on('reconnect_attempt', reconnectCb); - manager.on('reconnect_failed', function failed() { + manager.on('reconnect_failed', function failed () { expect(reconnects).to.be(2); socket.close(); manager.close(); @@ -307,18 +307,18 @@ describe('connection', function() { socket = manager.socket('/timeout'); }); - it('should fire reconnect_* events on socket', function(done) { + it('should fire reconnect_* events on socket', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 }); var socket = manager.socket('/timeout_socket'); var reconnects = 0; - var reconnectCb = function(attempts) { + var reconnectCb = function (attempts) { reconnects++; expect(attempts).to.be(reconnects); }; socket.on('reconnect_attempt', reconnectCb); - socket.on('reconnect_failed', function failed() { + socket.on('reconnect_failed', function failed () { expect(reconnects).to.be(2); socket.close(); manager.close(); @@ -326,34 +326,34 @@ describe('connection', function() { }); }); - it('should fire error on socket', function(done) { + it('should fire error on socket', function (done) { var manager = io.Manager({ reconnection: true }); var socket = manager.socket('/timeout_socket'); - socket.on('error', function(data) { + socket.on('error', function (data) { expect(data.code).to.be('test'); socket.close(); manager.close(); done(); }); - socket.on('connect', function() { + socket.on('connect', function () { manager.engine.onPacket({ type: 'error', data: 'test' }); }); }); - it('should fire reconnecting (on socket) with attempts number when reconnecting twice', function(done) { + it('should fire reconnecting (on socket) with attempts number when reconnecting twice', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 }); var socket = manager.socket('/timeout_socket'); var reconnects = 0; - var reconnectCb = function(attempts) { + var reconnectCb = function (attempts) { reconnects++; expect(attempts).to.be(reconnects); }; socket.on('reconnecting', reconnectCb); - socket.on('reconnect_failed', function failed() { + socket.on('reconnect_failed', function failed () { expect(reconnects).to.be(2); socket.close(); manager.close(); @@ -361,18 +361,18 @@ describe('connection', function() { }); }); - it('should not try to reconnect and should form a connection when connecting to correct port with default timeout', function(done) { + it('should not try to reconnect and should form a connection when connecting to correct port with default timeout', function (done) { var manager = io.Manager({ reconnection: true, reconnectionDelay: 10 }); - var cb = function() { + var cb = function () { socket.close(); expect().fail(); }; manager.on('reconnect_attempt', cb); var socket = manager.socket('/valid'); - socket.on('connect', function(){ + socket.on('connect', function () { // set a timeout to let reconnection possibly fire - setTimeout(function() { + setTimeout(function () { socket.close(); manager.close(); done(); @@ -380,10 +380,10 @@ describe('connection', function() { }); }); - it('should connect while disconnecting another socket', function(done) { + it('should connect while disconnecting another socket', function (done) { var manager = io.Manager(); var socket1 = manager.socket('/foo'); - socket1.on('connect', function() { + socket1.on('connect', function () { var socket2 = manager.socket('/asd'); socket2.on('connect', done); socket1.disconnect(); @@ -393,17 +393,17 @@ describe('connection', function() { // Ignore incorrect connection test for old IE due to no support for // `script.onerror` (see: http://requirejs.org/docs/api.html#ieloadfail) if (!global.document || hasCORS) { - it('should try to reconnect twice and fail when requested two attempts with incorrect address and reconnect enabled', function(done) { + it('should try to reconnect twice and fail when requested two attempts with incorrect address and reconnect enabled', function (done) { var manager = io.Manager('http://localhost:3940', { reconnection: true, reconnectionAttempts: 2, reconnectionDelay: 10 }); var socket = manager.socket('/asd'); var reconnects = 0; - var cb = function() { + var cb = function () { reconnects++; }; manager.on('reconnect_attempt', cb); - manager.on('reconnect_failed', function() { + manager.on('reconnect_failed', function () { expect(reconnects).to.be(2); socket.disconnect(); manager.close(); @@ -411,17 +411,17 @@ describe('connection', function() { }); }); - it('should not try to reconnect with incorrect port when reconnection disabled', function(done) { + it('should not try to reconnect with incorrect port when reconnection disabled', function (done) { var manager = io.Manager('http://localhost:9823', { reconnection: false }); - var cb = function() { + var cb = function () { socket.close(); expect().fail(); }; manager.on('reconnect_attempt', cb); - manager.on('connect_error', function(){ + manager.on('connect_error', function () { // set a timeout to let reconnection possibly fire - setTimeout(function() { + setTimeout(function () { socket.disconnect(); manager.close(); done(); @@ -432,9 +432,9 @@ describe('connection', function() { }); } - it('should emit date as string', function(done){ + it('should emit date as string', function (done) { var socket = io({ forceNew: true }); - socket.on('takeDate', function(data) { + socket.on('takeDate', function (data) { socket.close(); expect(data).to.be.a('string'); done(); @@ -442,9 +442,9 @@ describe('connection', function() { socket.emit('getDate'); }); - it('should emit date in object', function(done){ + it('should emit date in object', function (done) { var socket = io({ forceNew: true }); - socket.on('takeDateObj', function(data) { + socket.on('takeDateObj', function (data) { socket.close(); expect(data).to.be.an('object'); expect(data.date).to.be.a('string'); @@ -454,9 +454,9 @@ describe('connection', function() { }); if (!global.Blob && !global.ArrayBuffer) { - it('should get base64 data as a last resort', function(done) { + it('should get base64 data as a last resort', function (done) { var socket = io({ forceNew: true }); - socket.on('takebin', function(a) { + socket.on('takebin', function (a) { socket.disconnect(); expect(a.base64).to.be(true); expect(a.data).to.eql('YXNkZmFzZGY='); @@ -469,22 +469,22 @@ describe('connection', function() { if (global.ArrayBuffer) { var base64 = require('base64-arraybuffer'); - it('should get binary data (as an ArrayBuffer)', function(done){ + it('should get binary data (as an ArrayBuffer)', function (done) { var socket = io({ forceNew: true }); if (env.node) { socket.io.engine.binaryType = 'arraybuffer'; } socket.emit('doge'); - socket.on('doge', function(buffer){ + socket.on('doge', function (buffer) { expect(buffer instanceof ArrayBuffer).to.be(true); socket.disconnect(); done(); }); }); - it('should send binary data (as an ArrayBuffer)', function(done){ + it('should send binary data (as an ArrayBuffer)', function (done) { var socket = io({ forceNew: true }); - socket.on('buffack', function(){ + socket.on('buffack', function () { socket.disconnect(); done(); }); @@ -492,9 +492,9 @@ describe('connection', function() { socket.emit('buffa', buf); }); - it('should send binary data (as an ArrayBuffer) mixed with json', function(done) { + it('should send binary data (as an ArrayBuffer) mixed with json', function (done) { var socket = io({ forceNew: true }); - socket.on('jsonbuff-ack', function() { + socket.on('jsonbuff-ack', function () { socket.disconnect(); done(); }); @@ -502,9 +502,9 @@ describe('connection', function() { socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'}); }); - it('should send events with ArrayBuffers in the correct order', function(done) { + it('should send events with ArrayBuffers in the correct order', function (done) { var socket = io({ forceNew: true }); - socket.on('abuff2-ack', function() { + socket.on('abuff2-ack', function () { socket.disconnect(); done(); }); @@ -515,9 +515,9 @@ describe('connection', function() { } if (global.Blob && null != textBlobBuilder('xxx')) { - it('should send binary data (as a Blob)', function(done){ + it('should send binary data (as a Blob)', function (done) { var socket = io({ forceNew: true }); - socket.on('back', function(){ + socket.on('back', function () { socket.disconnect(); done(); }); @@ -525,9 +525,9 @@ describe('connection', function() { socket.emit('blob', blob); }); - it('should send binary data (as a Blob) mixed with json', function(done) { + it('should send binary data (as a Blob) mixed with json', function (done) { var socket = io({ forceNew: true }); - socket.on('jsonblob-ack', function() { + socket.on('jsonblob-ack', function () { socket.disconnect(); done(); }); @@ -535,9 +535,9 @@ describe('connection', function() { socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'}); }); - it('should send events with Blobs in the correct order', function(done) { + it('should send events with Blobs in the correct order', function (done) { var socket = io({ forceNew: true }); - socket.on('blob3-ack', function() { + socket.on('blob3-ack', function () { socket.disconnect(); done(); }); diff --git a/test/socket.js b/test/socket.js index ac13e8e6..a5597204 100644 --- a/test/socket.js +++ b/test/socket.js @@ -1,12 +1,12 @@ var expect = require('expect.js'); var io = require('../'); -describe('socket', function(){ +describe('socket', function () { this.timeout(70000); - it('should have an accessible socket id equal to the engine.io socket id', function(done) { + it('should have an accessible socket id equal to the engine.io socket id', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ + socket.on('connect', function () { expect(socket.id).to.be.ok(); expect(socket.id).to.eql(socket.io.engine.id); socket.disconnect(); @@ -14,10 +14,10 @@ describe('socket', function(){ }); }); - it('clears socket.id upon disconnection', function(done){ + it('clears socket.id upon disconnection', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ - socket.on('disconnect', function(){ + socket.on('connect', function () { + socket.on('disconnect', function () { expect(socket.id).to.not.be.ok(); done(); }); @@ -26,25 +26,25 @@ describe('socket', function(){ }); }); - it('doesn\'t fire a connect_error if we force disconnect in opening state', function(done){ + it('doesn\'t fire a connect_error if we force disconnect in opening state', function (done) { var socket = io({ forceNew: true, timeout: 100 }); socket.disconnect(); - socket.on('connect_error', function(){ + socket.on('connect_error', function () { throw new Error('Unexpected'); }); - setTimeout(function(){ + setTimeout(function () { done(); }, 300); }); - it('should ping and pong with latency', function(done){ + it('should ping and pong with latency', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ + socket.on('connect', function () { var pinged; - socket.once('ping', function(){ + socket.once('ping', function () { pinged = true; }); - socket.once('pong', function(ms){ + socket.once('pong', function (ms) { expect(pinged).to.be(true); expect(ms).to.be.a('number'); socket.disconnect(); @@ -53,16 +53,16 @@ describe('socket', function(){ }); }); - it('should change socket.id upon reconnection', function(done){ + it('should change socket.id upon reconnection', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ + socket.on('connect', function () { var id = socket.id; - socket.on('reconnect_attempt', function(){ + socket.on('reconnect_attempt', function () { expect(socket.id).to.not.be.ok(); }); - socket.on('reconnect', function() { + socket.on('reconnect', function () { expect(socket.id).to.not.eql(id); socket.disconnect(); done(); @@ -72,10 +72,10 @@ describe('socket', function(){ }); }); - it('should enable compression by default', function(done){ + it('should enable compression by default', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ - socket.io.engine.once('packetCreate', function(packet){ + socket.on('connect', function () { + socket.io.engine.once('packetCreate', function (packet) { expect(packet.options.compress).to.be(true); socket.disconnect(); done(); @@ -84,10 +84,10 @@ describe('socket', function(){ }); }); - it('should disable compression', function(done){ + it('should disable compression', function (done) { var socket = io({ forceNew: true }); - socket.on('connect', function(){ - socket.io.engine.once('packetCreate', function(packet){ + socket.on('connect', function () { + socket.io.engine.once('packetCreate', function (packet) { expect(packet.options.compress).to.be(false); socket.disconnect(); done(); diff --git a/test/support/server.js b/test/support/server.js index 08f55d03..bc871b0c 100644 --- a/test/support/server.js +++ b/test/support/server.js @@ -5,50 +5,50 @@ var io = require('socket.io'); var server = io(process.env.ZUUL_PORT || 3210, { pingInterval: 2000 }); var expect = require('expect.js'); -server.of('/foo').on('connection', function(){ +server.of('/foo').on('connection', function () { // register namespace }); -server.of('/timeout_socket').on('connection', function(){ +server.of('/timeout_socket').on('connection', function () { // register namespace }); -server.of('/valid').on('connection', function(){ +server.of('/valid').on('connection', function () { // register namespace }); -server.of('/asd').on('connection', function(){ +server.of('/asd').on('connection', function () { // register namespace }); -server.on('connection', function(socket){ +server.on('connection', function (socket) { // simple test - socket.on('hi', function(){ + socket.on('hi', function () { socket.emit('hi'); }); // ack tests - socket.on('ack', function(){ - socket.emit('ack', function(a, b){ - if (a == 5 && b.test) { + socket.on('ack', function () { + socket.emit('ack', function (a, b) { + if (a === 5 && b.test) { socket.emit('got it'); } }); }); - socket.on('getAckDate', function(data, cb){ + socket.on('getAckDate', function (data, cb) { cb(new Date()); }); - socket.on('getDate', function(){ + socket.on('getDate', function () { socket.emit('takeDate', new Date()); }); - socket.on('getDateObj', function(){ + socket.on('getDateObj', function () { socket.emit('takeDateObj', { date: new Date() }); }); - socket.on('getUtf8', function() { + socket.on('getUtf8', function () { socket.emit('takeUtf8', 'てすと'); socket.emit('takeUtf8', 'Я Б Г Д Ж Й'); socket.emit('takeUtf8', 'Ä ä Ü ü ß'); @@ -57,23 +57,23 @@ server.on('connection', function(socket){ }); // false test - socket.on('false', function(){ + socket.on('false', function () { socket.emit('false', false); }); // binary test - socket.on('doge', function(){ + socket.on('doge', function () { var buf = new Buffer('asdfasdf', 'utf8'); socket.emit('doge', buf); }); // expect receiving binary to be buffer - socket.on('buffa', function(a){ + socket.on('buffa', function (a) { if (Buffer.isBuffer(a)) socket.emit('buffack'); }); // expect receiving binary with mixed JSON - socket.on('jsonbuff', function(a) { + socket.on('jsonbuff', function (a) { expect(a.hello).to.eql('lol'); expect(Buffer.isBuffer(a.message)).to.be(true); expect(a.goodbye).to.eql('gotcha'); @@ -82,22 +82,22 @@ server.on('connection', function(socket){ // expect receiving buffers in order var receivedAbuff1 = false; - socket.on('abuff1', function(a) { + socket.on('abuff1', function (a) { expect(Buffer.isBuffer(a)).to.be(true); receivedAbuff1 = true; }); - socket.on('abuff2', function(a) { + socket.on('abuff2', function (a) { expect(receivedAbuff1).to.be(true); socket.emit('abuff2-ack'); }); // expect sent blob to be buffer - socket.on('blob', function(a){ + socket.on('blob', function (a) { if (Buffer.isBuffer(a)) socket.emit('back'); }); // expect sent blob mixed with json to be buffer - socket.on('jsonblob', function(a) { + socket.on('jsonblob', function (a) { expect(a.hello).to.eql('lol'); expect(Buffer.isBuffer(a.message)).to.be(true); expect(a.goodbye).to.eql('gotcha'); @@ -107,16 +107,16 @@ server.on('connection', function(socket){ // expect blobs sent in order to arrive in correct order var receivedblob1 = false; var receivedblob2 = false; - socket.on('blob1', function(a) { + socket.on('blob1', function (a) { expect(Buffer.isBuffer(a)).to.be(true); receivedblob1 = true; }); - socket.on('blob2', function(a) { + socket.on('blob2', function (a) { expect(receivedblob1).to.be(true); expect(a).to.eql('second'); receivedblob2 = true; }); - socket.on('blob3', function(a) { + socket.on('blob3', function (a) { expect(Buffer.isBuffer(a)).to.be(true); expect(receivedblob1).to.be(true); expect(receivedblob2).to.be(true); @@ -124,7 +124,7 @@ server.on('connection', function(socket){ }); // emit buffer to base64 receiving browsers - socket.on('getbin', function() { + socket.on('getbin', function () { var buf = new Buffer('asdfasdf', 'utf8'); socket.emit('takebin', buf); }); diff --git a/test/url.js b/test/url.js index cf27ccb8..5b374f29 100644 --- a/test/url.js +++ b/test/url.js @@ -3,9 +3,9 @@ var loc = {}; var url = require('../lib/url'); var expect = require('expect.js'); -describe('url', function(){ +describe('url', function () { - it('works with undefined', function(){ + it('works with undefined', function () { loc.hostname = 'woot.com'; loc.protocol = 'https:'; loc.port = 4005; @@ -16,7 +16,7 @@ describe('url', function(){ expect(parsed.port).to.be('4005'); }); - it('works with relative paths', function(){ + it('works with relative paths', function () { loc.hostname = 'woot.com'; loc.protocol = 'https:'; loc.port = 3000; @@ -27,7 +27,7 @@ describe('url', function(){ expect(parsed.port).to.be('3000'); }); - it('works with no protocol', function(){ + it('works with no protocol', function () { loc.protocol = 'http:'; var parsed = url('localhost:3000', loc); expect(parsed.host).to.be('localhost'); @@ -35,7 +35,7 @@ describe('url', function(){ expect(parsed.protocol).to.be('http'); }); - it('works with no schema', function(){ + it('works with no schema', function () { loc.protocol = 'http:'; var parsed = url('//localhost:3000', loc); expect(parsed.host).to.be('localhost'); @@ -43,7 +43,7 @@ describe('url', function(){ expect(parsed.protocol).to.be('http'); }); - it('forces ports for unique url ids', function(){ + it('forces ports for unique url ids', function () { var id1 = url('http://google.com:80/'); var id2 = url('http://google.com/'); var id3 = url('https://google.com/'); @@ -52,7 +52,7 @@ describe('url', function(){ expect(id2.id).to.not.be(id3.id); }); - it('identifies the namespace', function(){ + it('identifies the namespace', function () { loc.protocol = 'http:'; loc.hostname = 'woot.com'; @@ -61,7 +61,7 @@ describe('url', function(){ expect(url('http://google.com/').path).to.be('/'); }); - it('works with ipv6', function(){ + it('works with ipv6', function () { var parsed = url('http://[::1]'); expect(parsed.protocol).to.be('http'); expect(parsed.host).to.be('::1'); @@ -69,7 +69,7 @@ describe('url', function(){ expect(parsed.id).to.be('http://[::1]:80'); }); - it('works with ipv6 location', function(){ + it('works with ipv6 location', function () { loc.protocol = 'http:'; loc.hostname = '[::1]'; loc.port = ''; From c51a930a2ced45ff0eb6debf422210255ff5f3f5 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Sat, 27 Feb 2016 21:07:26 +0800 Subject: [PATCH 41/44] ESlint manual fix --- gulpfile.js | 9 ++++----- lib/manager.js | 12 +++++++----- lib/url.js | 5 ++--- support/webpack.config.js | 6 +++--- test/connection.js | 5 ++++- test/url.js | 1 - 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d43af2f0..3fbc9929 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,5 @@ const gulp = require('gulp'); const mocha = require('gulp-mocha'); -const file = require('gulp-file'); const istanbul = require('gulp-istanbul'); const webpack = require('webpack-stream'); const child = require('child_process'); @@ -11,9 +10,9 @@ gulp.task('help', help); gulp.task('default', ['lint', 'build']); -//////////////////////////////////////// +// ////////////////////////////////////// // BUILDING -//////////////////////////////////////// +// ////////////////////////////////////// const BUILD_TARGET_DIR = './'; @@ -35,9 +34,9 @@ gulp.task('lint', function () { .pipe(eslint.failAfterError()); }); -//////////////////////////////////////// +// ////////////////////////////////////// // TESTING -//////////////////////////////////////// +// ////////////////////////////////////// const REPORTER = 'dot'; const TEST_FILE = './test/index.js'; diff --git a/lib/manager.js b/lib/manager.js index ae22ffc4..4efb31ea 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -196,7 +196,6 @@ Manager.prototype.maybeReconnectOnOpen = function () { } }; - /** * Sets the current transport `socket`. * @@ -299,7 +298,7 @@ Manager.prototype.onopen = function () { */ Manager.prototype.onping = function () { - this.lastPing = new Date; + this.lastPing = new Date(); this.emitAll('ping'); }; @@ -310,7 +309,7 @@ Manager.prototype.onping = function () { */ Manager.prototype.onpong = function () { - this.emitAll('pong', new Date - this.lastPing); + this.emitAll('pong', new Date() - this.lastPing); }; /** @@ -440,8 +439,11 @@ Manager.prototype.processPacketQueue = function () { Manager.prototype.cleanup = function () { debug('cleanup'); - var sub; - while (sub = this.subs.shift()) sub.destroy(); + var subsLength = this.subs.length; + for (var i = 0; i < subsLength; i++) { + var sub = this.subs.shift(); + sub.destroy(); + } this.packetBuffer = []; this.encoding = false; diff --git a/lib/url.js b/lib/url.js index f72da274..8bac5429 100644 --- a/lib/url.js +++ b/lib/url.js @@ -25,7 +25,7 @@ function url (uri, loc) { var obj = uri; // default to window.location - var loc = loc || global.location; + loc = loc || global.location; if (null == uri) uri = loc.protocol + '//' + loc.host; // relative path support @@ -56,8 +56,7 @@ function url (uri, loc) { if (!obj.port) { if (/^(http|ws)$/.test(obj.protocol)) { obj.port = '80'; - } - else if (/^(http|ws)s$/.test(obj.protocol)) { + } else if (/^(http|ws)s$/.test(obj.protocol)) { obj.port = '443'; } } diff --git a/support/webpack.config.js b/support/webpack.config.js index ddc7d78c..4cd2bfc2 100644 --- a/support/webpack.config.js +++ b/support/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { */ function glob () { - return 'typeof self !== "undefined" ? self : ' - + 'typeof window !== "undefined" ? window : ' - + 'typeof global !== "undefined" ? global : {}'; + return 'typeof self !== "undefined" ? self : ' + + 'typeof window !== "undefined" ? window : ' + + 'typeof global !== "undefined" ? global : {}'; } diff --git a/test/connection.js b/test/connection.js index 29f6b4bf..be49f21b 100644 --- a/test/connection.js +++ b/test/connection.js @@ -186,7 +186,10 @@ describe('connection', function () { it('reconnect delay should increase every time', function (done) { var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 3, reconnectionDelay: 100, randomizationFactor: 0.2 }); var socket = manager.socket('/timeout'); - var reconnects = 0, increasingDelay = true, startTime, prevDelay = 0; + var reconnects = 0; + var increasingDelay = true; + var startTime; + var prevDelay = 0; socket.on('connect_error', function () { startTime = new Date().getTime(); diff --git a/test/url.js b/test/url.js index 5b374f29..ce3dfc6d 100644 --- a/test/url.js +++ b/test/url.js @@ -4,7 +4,6 @@ var url = require('../lib/url'); var expect = require('expect.js'); describe('url', function () { - it('works with undefined', function () { loc.hostname = 'woot.com'; loc.protocol = 'https:'; From c5ee450638d856d183512aee2ceca84fbda0d335 Mon Sep 17 00:00:00 2001 From: Diga Widyaprana Date: Sun, 28 Feb 2016 21:19:29 +0800 Subject: [PATCH 42/44] Run lint before test instead of before build --- gulpfile.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3fbc9929..6aaa94d8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,7 +8,7 @@ const eslint = require('gulp-eslint'); gulp.task('help', help); -gulp.task('default', ['lint', 'build']); +gulp.task('default', ['build']); // ////////////////////////////////////// // BUILDING @@ -22,18 +22,6 @@ gulp.task('build', function () { .pipe(gulp.dest(BUILD_TARGET_DIR)); }); -gulp.task('lint', function () { - return gulp.src([ - '**/*.js', - '!node_modules/**', - '!coverage/**', - '!socket.io.js' - ]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); -}); - // ////////////////////////////////////// // TESTING // ////////////////////////////////////// @@ -42,7 +30,7 @@ const REPORTER = 'dot'; const TEST_FILE = './test/index.js'; const TEST_SUPPORT_SERVER_FILE = './test/support/server.js'; -gulp.task('test', function () { +gulp.task('test', ['lint'], function () { if (process.env.hasOwnProperty('BROWSER_NAME')) { return testZuul(); } else { @@ -53,6 +41,18 @@ gulp.task('test', function () { gulp.task('test-node', testNode); gulp.task('test-zuul', testZuul); +gulp.task('lint', function () { + return gulp.src([ + '**/*.js', + '!node_modules/**', + '!coverage/**', + '!socket.io.js' + ]) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + // runs zuul through shell process function testZuul () { const ZUUL_CMD = './node_modules/zuul/bin/zuul'; From 7b8db005da6a9a9dd0f8955ce44f8943aa8051d9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Apr 2016 11:40:02 +0200 Subject: [PATCH 43/44] Remove jspm browser config --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index ee348196..d17b7029 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,6 @@ "client" ], "main": "./lib/index", - "jspm": { - "main": "socket.io.js" - }, "dependencies": { "debug": "2.2.0", "engine.io-client": "1.6.8", From 827d0ce3f83d91e32bc1286a4a6dceb7354b307a Mon Sep 17 00:00:00 2001 From: nkzawa Date: Mon, 11 Apr 2016 18:20:24 +0900 Subject: [PATCH 44/44] bump zuul --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee348196..fe54eac4 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "text-blob-builder": "0.0.1", "uglify-js": "2.6.1", "webpack-stream": "3.1.0", - "zuul": "3.9.0", + "zuul": "3.10.1", "zuul-builder-webpack": "1.1.0", "zuul-ngrok": "3.2.0" },