Skip to content

Commit

Permalink
Merge pull request #458 from nus-fboa2016-si/eslint-rebased
Browse files Browse the repository at this point in the history
Add ESLint
  • Loading branch information
rauchg committed Mar 2, 2016
2 parents 9748f6b + a526395 commit 6045ccf
Show file tree
Hide file tree
Showing 29 changed files with 526 additions and 510 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "standard",
"parser": "babel-eslint",
"env": {
"node": true,
"browser": true
},
"rules": {
"yoda": 0,
"semi": [2, "always"],
"no-extra-semi": 2,
"semi-spacing": [2, { "before": false, "after": true }]
}
}
99 changes: 55 additions & 44 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
const gulp = require("gulp");
const mocha = require("gulp-mocha");
const istanbul = require("gulp-istanbul");
const file = require("gulp-file");
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const webpack = require('webpack-stream');
const child = require("child_process");
const help = require("gulp-task-listing");
const child = require('child_process');
const help = require('gulp-task-listing');
const del = require('del');
const eslint = require('gulp-eslint');

gulp.task("help", help);
gulp.task('help', help);

////////////////////////////////////////
// //////////////////////////////////////
// BUILDING
////////////////////////////////////////
// //////////////////////////////////////

const BUILD_TARGET_FILENAME = "engine.io.js";
const BUILD_TARGET_DIR = "./";
const BUILD_TARGET_DIR = './';

gulp.task("default", ["build"]);
gulp.task('default', ['build']);

gulp.task("build", function() {
return gulp.src(["lib/*.js", "lib/transports/*.js"], {
base: 'lib'
})
.pipe(webpack(require("./support/webpack.config.js")))
gulp.task('build', function () {
return gulp.src(['lib/*.js', 'lib/transports/*.js'], {
base: 'lib'
})
.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";
const REPORTER = 'dot';
const TEST_FILE = './test/index.js';
const TEST_SUPPORT_SERVER_FILE = './test/support/server.js';
const FILES_TO_CLEAN = [
'test/support/public/engine.io.js'
'test/support/public/engine.io.js'
];

gulp.task("test", function() {
if (process.env.hasOwnProperty("BROWSER_NAME")) {
gulp.task('test', ['lint'], function () {
if (process.env.hasOwnProperty('BROWSER_NAME')) {
return testZuul();
} else {
return testNode();
}
});

gulp.task("test-node", testNode);
gulp.task("test-zuul", testZuul);
gulp.task('lint', function () {
return gulp.src([
'**/*.js',
'!node_modules/**',
'!coverage/**',
'!engine.io.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('test-node', testNode);
gulp.task('test-zuul', testZuul);

function testNode() {
function testNode () {
const MOCHA_OPTS = {
reporter: REPORTER,
require: [TEST_SUPPORT_SERVER_FILE],
Expand All @@ -57,61 +68,61 @@ 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);
cleanFiles(FILES_TO_CLEAN);
process.exit(1);
})
.once("end", function() {
.once('end', function () {
cleanFiles(FILES_TO_CLEAN);
process.exit();
});
}

// 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) {
const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: 'inherit' });
zuulChild.on('exit', function (code) {
cleanFiles(FILES_TO_CLEAN);
process.exit(code);
});
}

function cleanFiles(globArray) {
function cleanFiles (globArray) {
return del.sync(globArray);
}

gulp.task('istanbul-pre-test', 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.task('test-cov', ['istanbul-pre-test'], function () {
return 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.stack);
process.exit(1);
})
.once('end', function() {
.once('end', function () {
process.exit();
});
});
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

module.exports = require('./lib/');
module.exports = require('./lib/');
Loading

0 comments on commit 6045ccf

Please sign in to comment.