forked from socketio/socket.io-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request socketio#940 from nus-fboa2016-si/webpack
Webpack
- Loading branch information
Showing
9 changed files
with
165 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
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"); | ||
|
||
gulp.task('help', help); | ||
|
||
gulp.task('default', ['build']); | ||
|
||
//////////////////////////////////////// | ||
// BUILDING | ||
//////////////////////////////////////// | ||
|
||
const BUILD_TARGET_DIR = './'; | ||
|
||
gulp.task('build', function() { | ||
return gulp.src('lib/*.js') | ||
.pipe(webpack(require('./support/webpack.config.js'))) | ||
.pipe(gulp.dest(BUILD_TARGET_DIR)); | ||
}); | ||
|
||
|
||
//////////////////////////////////////// | ||
// TESTING | ||
//////////////////////////////////////// | ||
|
||
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', 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); | ||
const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: "inherit" }); | ||
zuulChild.on("exit", function (code) { process.exit(code); }); | ||
return zuulChild; | ||
} | ||
|
||
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() { | ||
process.exit(); | ||
}); | ||
} | ||
|
||
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: REPORTER | ||
})) | ||
.pipe(istanbul.writeReports()) | ||
.once('error', function (err){ | ||
console.error(err); | ||
process.exit(1); | ||
}) | ||
.once('end', function (){ | ||
process.exit(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$/, | ||
exclude: /(node_modules|bower_components)/, | ||
loader: 'babel', // 'babel-loader' is also a legal name to reference | ||
query: { | ||
presets: ['es2015'] | ||
} | ||
}] | ||
} | ||
}; | ||
|
||
/** | ||
* Populates `global`. | ||
* | ||
* @api private | ||
*/ | ||
|
||
function glob(){ | ||
return 'typeof self !== "undefined" ? self : ' | ||
+ 'typeof window !== "undefined" ? window : ' | ||
+ 'typeof global !== "undefined" ? global : {}'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
}; |